mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: bucketList store with caching
This commit is contained in:
1 parent
21680aee8b
commit
5582dbc75d
2 files changed
+109
-73
No files matched your search
@@ -10,6 +10,7 @@
|
||||
import { Container } from '$lib/layout';
|
||||
import { base } from '$app/paths';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { bucketList } from './store';
|
||||
|
||||
let showCreate = false;
|
||||
let search = '';
|
||||
@@ -22,7 +23,7 @@
|
||||
await goto(`${base}/console/${project}/storage/bucket/${event.detail.$id}`);
|
||||
};
|
||||
|
||||
$: request = sdkForProject.storage.listBuckets(search, limit, offset);
|
||||
$: bucketList.load(search, limit, offset ?? 0);
|
||||
$: if (search) offset = 0;
|
||||
|
||||
const copy = async (value: string) => {
|
||||
@@ -49,83 +50,78 @@
|
||||
<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}
|
||||
<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>
|
||||
<div class="u-flex u-main-space-between">
|
||||
<Pill button on:click={() => copy(bucket.$id)}
|
||||
><i class="icon-duplicate" />Bucket ID
|
||||
</Pill>
|
||||
<div class="">
|
||||
<Tooltip icon="lock-closed" aria="encryption">
|
||||
<span
|
||||
>{bucket.encryption
|
||||
? 'Encryption enabled'
|
||||
: 'Encryption disabled'}</span>
|
||||
</Tooltip>
|
||||
<Tooltip icon="shield-check" aria="antivirus">
|
||||
<span
|
||||
>{bucket.antivirus
|
||||
? 'Antivirus enabled'
|
||||
: 'Antivirus disabled'}</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{/each}
|
||||
</Tiles>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
{#if $bucketList.response.total}
|
||||
<Tiles>
|
||||
{#each $bucketList.response.buckets as bucket}
|
||||
<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>
|
||||
<div class="common-section">
|
||||
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
|
||||
<h3 class="tiles-title">{bucket.name}</h3>
|
||||
<div class="u-flex u-main-space-between">
|
||||
<Pill button on:click={() => copy(bucket.$id)}
|
||||
><i class="icon-duplicate" />Bucket ID
|
||||
</Pill>
|
||||
<div class="">
|
||||
<Tooltip icon="lock-closed" aria="encryption">
|
||||
<span
|
||||
>{bucket.encryption
|
||||
? 'Encryption enabled'
|
||||
: 'Encryption disabled'}</span>
|
||||
</Tooltip>
|
||||
<Tooltip icon="shield-check" aria="antivirus">
|
||||
<span
|
||||
>{bucket.antivirus
|
||||
? 'Antivirus enabled'
|
||||
: 'Antivirus disabled'}</span>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{/each}
|
||||
</Tiles>
|
||||
|
||||
<div class="u-flex common-section u-main-space-between">
|
||||
<p class="text">Total results: {$bucketList.response.total}</p>
|
||||
<Pagination {limit} bind:offset sum={$bucketList.response.total} />
|
||||
</div>
|
||||
{:else if search}
|
||||
<Empty>
|
||||
<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>
|
||||
</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 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 class="common-section">
|
||||
<Button secondary on:click={() => (search = '')}>Clear Search</Button>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
</Empty>
|
||||
<div class="u-flex common-section u-main-space-between">
|
||||
<p class="text">Total results: {$bucketList.response.total}</p>
|
||||
<Pagination {limit} bind:offset sum={$bucketList.response.total} />
|
||||
</div>
|
||||
{:else}
|
||||
<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}
|
||||
</Container>
|
||||
|
||||
<Create bind:showCreate on:created={bucketCreated} />
|
||||
@@ -0,0 +1,40 @@
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from 'src/sdk';
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/env';
|
||||
|
||||
export type BucketList = {
|
||||
loading: boolean;
|
||||
response?: Models.BucketList;
|
||||
};
|
||||
|
||||
function createBucketListStore() {
|
||||
const { subscribe, set } = writable<BucketList>({
|
||||
loading: true,
|
||||
response: browser ? JSON.parse(sessionStorage.getItem('bucketList')) : null
|
||||
});
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (search: string, limit: number, offset: number) => {
|
||||
try {
|
||||
const response = await sdkForProject.storage.listBuckets(search, limit, offset);
|
||||
set({
|
||||
loading: false,
|
||||
response
|
||||
});
|
||||
} catch (error) {
|
||||
//TODO: take care what happens here
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const bucketList = createBucketListStore();
|
||||
|
||||
if (browser) {
|
||||
bucketList.subscribe((n) =>
|
||||
sessionStorage?.setItem('bucketList', JSON.stringify(n.response ?? ''))
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user