feat: start work on storage page

This commit is contained in:
Arman committed 2022-06-16 15:41:22 +02:00
1 parent e0651cb191
commit 89d3e51b96
3 files changed
+133 -44

No files matched your search

@@ -22,8 +22,8 @@
backButton.set('');
copyData.set({
text: '',
value: ''
text: $bucket.$id,
value: $bucket.$id
});
tabs.set([
{
@@ -38,35 +38,47 @@
</script>
<Container>
<h1>Files</h1>
<Card>
<InputSearch bind:value={search} />
</Card>
<div class="u-flex u-gap-12 common-section u-main-space-between">
<div class="input-text-wrapper u-stretch" style="max-width: 500px">
<input
type="search"
placeholder="Search by Filename"
class="input-text"
bind:value={search} />
<span class="icon-search" aria-hidden="true" />
</div>
<Button on:click={() => (showCreate = true)}>
<span class="icon-plus" aria-hidden="true" /> <span class="text">Add File</span>
</Button>
</div>
{#await request}
<div aria-busy="true" />
{:then response}
{#if response.total}
<p>{response.total} files found</p>
<Table>
<TableHeader>
<TableCellHead width={30} />
<TableCellHead>Name</TableCellHead>
<TableCellHead>Filename</TableCellHead>
<TableCellHead>Type</TableCellHead>
<TableCellHead>Size</TableCellHead>
<TableCellHead>Date Created</TableCellHead>
<TableCellHead width={30} />
</TableHeader>
<TableBody>
{#each response.files as file}
<TableRow>
<TableCellAvatar
src={getPreview(file.$id)}
alt={file.name}
onlyDesktop />
<TableCellText title="Name">
<span class="link" on:click={() => openFile(file)}>
{file.name}
</span>
<div class="u-flex u-gap-12">
<span class="link" on:click={() => openFile(file)}>
<img
class="avatar"
width="40"
height="40"
src={getPreview(file.$id)}
alt={file.name} />
{file.name}
</span>
</div>
</TableCellText>
<TableCellText title="Type">{file.mimeType}</TableCellText>
<TableCellText title="Size">{file.sizeOriginal}</TableCellText>
@@ -76,22 +88,44 @@
{/each}
</TableBody>
</Table>
<Pagination {limit} bind:offset sum={response.total} />
<div class="u-flex common-section u-main-space-between">
<p class="text">Total results: {response.total}</p>
<Pagination {limit} bind:offset sum={response.total} />
</div>
{:else if search}
<Empty>
<svelte:fragment slot="header"
>No results found for <b>{search}</b></svelte:fragment>
<div class="u-flex u-flex-vertical">
<b>Sorry, we couldn’t find ‘{search}’</b>
<div class="common-section">
<p>There are no files that match your search.</p>
</div>
<div class="common-section">
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
</div>
</div>
</Empty>
<div class="u-flex common-section u-main-space-between">
<p class="text">Total results: {response.total}</p>
<Pagination {limit} bind:offset sum={response.total} />
</div>
{:else}
<Empty>
<svelte:fragment slot="header">No Files Found</svelte:fragment>
Upload your first file to get started.
<Empty dashed centered>
<div class="u-flex u-flex-vertical u-cross-center">
<div class="common-section">
<Button secondary round on:click={() => (showCreate = true)}>
<i class="icon-plus" />
</Button>
</div>
<div class="common-section">
<p>Upload spme files to get started</p>
</div>
<div class="common-section">
<Button secondary href="#">Documentation</Button>
</div>
</div>
</Empty>
{/if}
{/await}
<Button on:click={() => (showCreate = true)}>Upload</Button>
</Container>
<Create bind:showCreate />
@@ -2,18 +2,20 @@
import { page } from '$app/stores';
import { goto } from '$app/navigation';
import { sdkForProject } from '$lib/stores/sdk';
import { Button, InputSearch } from '$lib/elements/forms';
import { Card, Empty, Pagination, Tile, Tiles } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Empty, Pagination, Tiles } from '$lib/components';
import { Pill } from '$lib/elements';
import type { Models } from 'src/sdk';
import Create from './_create.svelte';
import { Container } from '$lib/layout';
import { base } from '$app/paths';
import { addNotification } from '$lib/stores/notifications';
let search = '';
let showCreate = false;
let search = '';
let offset = 0;
const limit = 25;
const limit = 5;
const project = $page.params.project;
const bucketCreated = async (event: CustomEvent<Models.Bucket>) => {
showCreate = false;
@@ -22,41 +24,94 @@
$: request = sdkForProject.storage.listBuckets(search, limit, offset);
$: if (search) offset = 0;
const copy = async (value: string) => {
try {
await navigator.clipboard.writeText(value);
addNotification({
message: 'Copied to clipboard.',
type: 'success'
});
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
}
};
</script>
<Container>
<h1>Buckets</h1>
<Card>
<InputSearch bind:value={search} />
</Card>
<div class="u-flex u-gap-12 common-section u-main-space-between">
<h2 class="heading-level-5">Buckets</h2>
<Button on:click={() => (showCreate = true)}>
<span class="icon-plus" aria-hidden="true" /> <span class="text">Add Bucket</span>
</Button>
</div>
{#await request}
<div aria-busy="true" />
{:then response}
{#if response.total}
<Tiles>
{#each response.buckets as bucket}
<Tile
href={`${base}/console/${project}/storage/bucket/${bucket.$id}`}
title={bucket.name} />
<a
class="card"
href={`${base}/console/${project}/storage/bucket/${bucket.$id}`}>
<div class="u-flex u-main-space-between">
<span class="is-small">XX Files</span>
{#if !bucket.enabled}
<Pill>Disabled</Pill>
{/if}
</div>
<h3 class="tiles-title">{bucket.name}</h3>
<Pill button on:click={() => copy(bucket.$id)}
><i class="icon-duplicate" />User ID
</Pill>
<span class="icon-lock-closed" aria-hidden="true" />
<span class="icon-shield-check" aria-hidden="true" />
</a>
{/each}
</Tiles>
<Pagination {limit} bind:offset sum={response.total} />
<div class="u-flex common-section u-main-space-between">
<p class="text">Total results: {response.total}</p>
<Pagination {limit} bind:offset sum={response.total} />
</div>
{:else if search}
<Empty>
<svelte:fragment slot="header"
>No results found for <b>{search}</b></svelte:fragment>
<div class="u-flex u-flex-vertical">
<b>Sorry, we couldn’t find ‘{search}’</b>
<div class="common-section">
<p>There are no buckets that match your search.</p>
</div>
<div class="common-section">
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
</div>
</div>
</Empty>
<div class="u-flex common-section u-main-space-between">
<p class="text">Total results: {response.total}</p>
<Pagination {limit} bind:offset sum={response.total} />
</div>
{:else}
<Empty>
<svelte:fragment slot="header">No Buckets Found</svelte:fragment>
You haven't created any buckets for your project yet.
<Empty dashed centered>
<div class="u-flex u-flex-vertical u-cross-center">
<div class="common-section">
<Button secondary round on:click={() => (showCreate = true)}>
<i class="icon-plus" />
</Button>
</div>
<div class="common-section">
<p>Add Your First Bucket To Get Started</p>
</div>
<div class="common-section">
<Button secondary href="#">Documentation</Button>
</div>
</div>
</Empty>
{/if}
{/await}
<Button on:click={() => (showCreate = true)}>Create Bucket</Button>
</Container>
<Create bind:showCreate on:created={bucketCreated} />