mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Merge branch 'main' of github.com:appwrite/appwrite-console-poc into databases
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { browser } from '$app/env';
|
||||
import { writable, type Writable } from 'svelte/store';
|
||||
|
||||
export function cachedStore<TModel, TMethods = Record<string, unknown>>(
|
||||
id: string,
|
||||
callback: (store: Writable<TModel>) => TMethods
|
||||
): TMethods & Writable<TModel> {
|
||||
const store = writable<TModel>(browser ? JSON.parse(sessionStorage.getItem(id)) : null);
|
||||
|
||||
if (browser) {
|
||||
store.subscribe((n) => sessionStorage?.setItem(id, JSON.stringify(n ?? '')));
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe: store.subscribe,
|
||||
set: store.set,
|
||||
update: store.update,
|
||||
...callback(store)
|
||||
};
|
||||
}
|
||||
@@ -1,52 +1,50 @@
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/env';
|
||||
import { get } from 'svelte/store';
|
||||
import { base } from '$app/paths';
|
||||
import { goto } from '$app/navigation';
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
function createOrganizationList() {
|
||||
const { subscribe, set } = writable<Models.TeamList>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('organizationList')) : null
|
||||
);
|
||||
export const newOrgModal = writable<boolean>(false);
|
||||
export const newMemberModal = writable<boolean>(false);
|
||||
|
||||
export const organizationList = cachedStore<
|
||||
Models.TeamList,
|
||||
{
|
||||
load: () => Promise<void>;
|
||||
}
|
||||
>('organizationList', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async () => {
|
||||
const response = await sdkForConsole.teams.list();
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
function createOrganization() {
|
||||
const { subscribe, set } = writable<Models.Team>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('organization')) : null
|
||||
);
|
||||
});
|
||||
|
||||
export const organization = cachedStore<
|
||||
Models.Team,
|
||||
{
|
||||
load: (teamId: string) => Promise<void>;
|
||||
}
|
||||
>('organization', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (teamId: string) => {
|
||||
load: async (teamId) => {
|
||||
const response = await sdkForConsole.teams.get(teamId);
|
||||
set(response);
|
||||
},
|
||||
deleteCache: () => {
|
||||
sessionStorage.removeItem('organization');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createProjectList() {
|
||||
const { subscribe, set } = writable<Models.ProjectList>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('projectList')) : null
|
||||
);
|
||||
});
|
||||
|
||||
export const projectList = cachedStore<
|
||||
Models.ProjectList,
|
||||
{
|
||||
load: (search: string, limit: number, offset: number) => Promise<void>;
|
||||
}
|
||||
>('projectList', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (search: string, limit: number, offset: number) => {
|
||||
load: async (search, limit, offset) => {
|
||||
const response = await sdkForConsole.projects.list(
|
||||
search,
|
||||
limit,
|
||||
@@ -58,17 +56,16 @@ function createProjectList() {
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createMemberList() {
|
||||
const { subscribe, set } = writable<Models.MembershipList>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('memberList')) : null
|
||||
);
|
||||
});
|
||||
|
||||
export const memberList = cachedStore<
|
||||
Models.MembershipList,
|
||||
{
|
||||
load: (teamId: string, search: string, limit: number, offset: number) => Promise<void>;
|
||||
}
|
||||
>('memberList', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (teamId: string, search: string, limit: number, offset: number) => {
|
||||
load: async (teamId, search, limit, offset) => {
|
||||
const response = await sdkForConsole.teams.getMemberships(
|
||||
teamId,
|
||||
search,
|
||||
@@ -78,23 +75,7 @@ function createMemberList() {
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const organizationList = createOrganizationList();
|
||||
export const organization = createOrganization();
|
||||
export const projectList = createProjectList();
|
||||
export const memberList = createMemberList();
|
||||
export const newOrgModal = writable<boolean>(false);
|
||||
export const newMemberModal = writable<boolean>(false);
|
||||
|
||||
if (browser) {
|
||||
organizationList.subscribe((n) =>
|
||||
sessionStorage?.setItem('organizationList', JSON.stringify(n ?? ''))
|
||||
);
|
||||
organization.subscribe((n) => sessionStorage?.setItem('organization', JSON.stringify(n ?? '')));
|
||||
projectList.subscribe((n) => sessionStorage?.setItem('projectList', JSON.stringify(n ?? '')));
|
||||
memberList.subscribe((n) => sessionStorage?.setItem('memberList', JSON.stringify(n ?? '')));
|
||||
}
|
||||
});
|
||||
|
||||
export const redirectTo = async () => {
|
||||
let org = get(organization);
|
||||
|
||||
@@ -14,10 +14,16 @@
|
||||
import { toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { pageLimit } from '$lib/stores/layout';
|
||||
import { onMount } from 'svelte';
|
||||
import { accountActivity } from './store';
|
||||
|
||||
let offset = 0;
|
||||
|
||||
$: request = sdkForConsole.account.getLogs($pageLimit, offset);
|
||||
onMount(async () => {
|
||||
await accountActivity.load($pageLimit, offset);
|
||||
});
|
||||
|
||||
$: accountActivity.load($pageLimit, offset);
|
||||
|
||||
const getBrowser = (clientCode: string) => {
|
||||
return sdkForConsole.avatars.getBrowser(clientCode, 40, 40);
|
||||
@@ -25,82 +31,78 @@
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
{#await request}
|
||||
<div aria-busy="true" />
|
||||
{:then response}
|
||||
{#if response.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Date</TableCellHead>
|
||||
<TableCellHead>Event</TableCellHead>
|
||||
<TableCellHead>Client</TableCellHead>
|
||||
<TableCellHead>Location</TableCellHead>
|
||||
<TableCellHead>IP</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each response.logs as log}
|
||||
<TableRow>
|
||||
<TableCellText title="Date">{toLocaleDateTime(log.time)}</TableCellText>
|
||||
<TableCellText title="Event">{log.event}</TableCellText>
|
||||
{#if $accountActivity?.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Date</TableCellHead>
|
||||
<TableCellHead>Event</TableCellHead>
|
||||
<TableCellHead>Client</TableCellHead>
|
||||
<TableCellHead>Location</TableCellHead>
|
||||
<TableCellHead>IP</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each $accountActivity.logs as log}
|
||||
<TableRow>
|
||||
<TableCellText title="Date">{toLocaleDateTime(log.time)}</TableCellText>
|
||||
<TableCellText title="Event">{log.event}</TableCellText>
|
||||
|
||||
<TableCell title="Client">
|
||||
{#if log.clientName}
|
||||
<div class="u-flex u-cross-center u-gap-12">
|
||||
<div class="avatar is-small">
|
||||
<img
|
||||
height="20"
|
||||
width="20"
|
||||
src={getBrowser(log.clientCode).toString()}
|
||||
alt={log.clientName} />
|
||||
</div>
|
||||
<p
|
||||
class="text u-trim"
|
||||
title={`${log.clientName} ${log.clientVersion} on ${log.osName} ${log.osVersion}`}>
|
||||
{log.clientName}
|
||||
{log.clientVersion}
|
||||
on {log.osName}
|
||||
{log.osVersion}
|
||||
</p>
|
||||
<TableCell title="Client">
|
||||
{#if log.clientName}
|
||||
<div class="u-flex u-cross-center u-gap-12">
|
||||
<div class="avatar is-small">
|
||||
<img
|
||||
height="20"
|
||||
width="20"
|
||||
src={getBrowser(log.clientCode).toString()}
|
||||
alt={log.clientName} />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="u-flex u-cross-center u-gap-12">
|
||||
<span class="avatar is-color-empty" />
|
||||
<p class="text u-trim">Unknown</p>
|
||||
</div>
|
||||
{/if}
|
||||
</TableCell>
|
||||
<p
|
||||
class="text u-trim"
|
||||
title={`${log.clientName} ${log.clientVersion} on ${log.osName} ${log.osVersion}`}>
|
||||
{log.clientName}
|
||||
{log.clientVersion}
|
||||
on {log.osName}
|
||||
{log.osVersion}
|
||||
</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="u-flex u-cross-center u-gap-12">
|
||||
<span class="avatar is-color-empty" />
|
||||
<p class="text u-trim">Unknown</p>
|
||||
</div>
|
||||
{/if}
|
||||
</TableCell>
|
||||
|
||||
<TableCellText title="Location">
|
||||
{#if log.countryCode !== '--'}
|
||||
{log.countryName}
|
||||
{:else}
|
||||
Unknown
|
||||
{/if}
|
||||
</TableCellText>
|
||||
<TableCellText title="IP">{log.ip}</TableCellText>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{:else}
|
||||
<Empty centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<p>No logs available</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button
|
||||
external
|
||||
secondary
|
||||
href="https://appwrite.io/docs/server/authentication?sdk=nodejs-default#usersGetLogs"
|
||||
>Documentation</Button>
|
||||
</div>
|
||||
<TableCellText title="Location">
|
||||
{#if log.countryCode !== '--'}
|
||||
{log.countryName}
|
||||
{:else}
|
||||
Unknown
|
||||
{/if}
|
||||
</TableCellText>
|
||||
<TableCellText title="IP">{log.ip}</TableCellText>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{:else}
|
||||
<Empty centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<p>No logs available</p>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {response.total}</p>
|
||||
<Pagination limit={$pageLimit} bind:offset sum={response.total} />
|
||||
</div>
|
||||
{/await}
|
||||
<div class="common-section">
|
||||
<Button
|
||||
external
|
||||
secondary
|
||||
href="https://appwrite.io/docs/server/authentication?sdk=nodejs-default#usersGetLogs"
|
||||
>Documentation</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {$accountActivity?.total}</p>
|
||||
<Pagination limit={$pageLimit} bind:offset sum={$accountActivity?.total} />
|
||||
</div>
|
||||
</Container>
|
||||
|
||||
@@ -15,23 +15,27 @@
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { pageLimit } from '$lib/stores/layout';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { accountSession } from './store';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let offset = 0;
|
||||
|
||||
onMount(async () => {
|
||||
await accountSession.load();
|
||||
});
|
||||
|
||||
const getBrowser = (clientCode: string) => {
|
||||
return sdkForConsole.avatars.getBrowser(clientCode, 40, 40);
|
||||
};
|
||||
|
||||
const logout = (session: Models.Session) => {
|
||||
sdkForConsole.account.deleteSession(session.$id);
|
||||
request = sdkForConsole.account.getSessions();
|
||||
const logout = async (session: Models.Session) => {
|
||||
await sdkForConsole.account.deleteSession(session.$id);
|
||||
await accountSession.load();
|
||||
};
|
||||
const logoutAll = () => {
|
||||
sdkForConsole.account.deleteSessions();
|
||||
request = sdkForConsole.account.getSessions();
|
||||
const logoutAll = async () => {
|
||||
await sdkForConsole.account.deleteSessions();
|
||||
await accountSession.load();
|
||||
};
|
||||
|
||||
$: request = sdkForConsole.account.getSessions();
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
@@ -42,83 +46,80 @@
|
||||
<span class="text">Logout all sessions</span>
|
||||
</Button>
|
||||
</div>
|
||||
{#await request}
|
||||
<div aria-busy="true" />
|
||||
{:then response}
|
||||
{#if response.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Client</TableCellHead>
|
||||
<TableCellHead width={100}>Location</TableCellHead>
|
||||
<TableCellHead width={150}>IP</TableCellHead>
|
||||
<TableCellHead width={100} />
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each response.sessions as session}
|
||||
<TableRow>
|
||||
<TableCell title="Client">
|
||||
<div class="u-flex u-gap-12">
|
||||
<div class="u-flex u-cross-center u-gap-12">
|
||||
{#if session.clientName}
|
||||
<div class="avatar is-small">
|
||||
<img
|
||||
height="20"
|
||||
width="20"
|
||||
src={getBrowser(session.clientCode).toString()}
|
||||
alt={session.clientName} />
|
||||
</div>
|
||||
<p class="text u-trim">
|
||||
{session.clientName}
|
||||
{session.clientVersion}
|
||||
on {session.osName}
|
||||
{session.osVersion}
|
||||
</p>
|
||||
{:else}
|
||||
<span class="avatar is-color-empty" />
|
||||
<p class="text u-trim">Unknown</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<Pill>{session.provider}</Pill>
|
||||
{#if session.current}
|
||||
<Pill success>current session</Pill>
|
||||
{#if $accountSession?.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Client</TableCellHead>
|
||||
<TableCellHead width={100}>Location</TableCellHead>
|
||||
<TableCellHead width={150}>IP</TableCellHead>
|
||||
<TableCellHead width={100} />
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each $accountSession.sessions as session}
|
||||
<TableRow>
|
||||
<TableCell title="Client">
|
||||
<div class="u-flex u-gap-12">
|
||||
<div class="u-flex u-cross-center u-gap-12">
|
||||
{#if session.clientName}
|
||||
<div class="avatar is-small">
|
||||
<img
|
||||
height="20"
|
||||
width="20"
|
||||
src={getBrowser(session.clientCode).toString()}
|
||||
alt={session.clientName} />
|
||||
</div>
|
||||
<p class="text u-trim">
|
||||
{session.clientName}
|
||||
{session.clientVersion}
|
||||
on {session.osName}
|
||||
{session.osVersion}
|
||||
</p>
|
||||
{:else}
|
||||
<span class="avatar is-color-empty" />
|
||||
<p class="text u-trim">Unknown</p>
|
||||
{/if}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCellText title="Location">
|
||||
{#if session.countryCode !== '--'}
|
||||
{session.countryName}
|
||||
{:else}
|
||||
Unknown
|
||||
|
||||
<Pill>{session.provider}</Pill>
|
||||
{#if session.current}
|
||||
<Pill success>current session</Pill>
|
||||
{/if}
|
||||
</TableCellText>
|
||||
<TableCellText title="IP">{session.ip}</TableCellText>
|
||||
<TableCell title="Client">
|
||||
<Button secondary on:click={() => logout(session)}>Logout</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{:else}
|
||||
<Empty centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<p>No sessions available</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button
|
||||
external
|
||||
secondary
|
||||
href="https://appwrite.io/docs/server/authentication?sdk=nodejs-default#usersGetsessions"
|
||||
>Documentation</Button>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCellText title="Location">
|
||||
{#if session.countryCode !== '--'}
|
||||
{session.countryName}
|
||||
{:else}
|
||||
Unknown
|
||||
{/if}
|
||||
</TableCellText>
|
||||
<TableCellText title="IP">{session.ip}</TableCellText>
|
||||
<TableCell title="Client">
|
||||
<Button secondary on:click={() => logout(session)}>Logout</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{:else}
|
||||
<Empty centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<p>No sessions available</p>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {response.total}</p>
|
||||
<Pagination limit={$pageLimit} bind:offset sum={response.total} />
|
||||
</div>
|
||||
{/await}
|
||||
<div class="common-section">
|
||||
<Button
|
||||
external
|
||||
secondary
|
||||
href="https://appwrite.io/docs/server/authentication?sdk=nodejs-default#usersGetsessions"
|
||||
>Documentation</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {$accountSession?.total}</p>
|
||||
<Pagination limit={$pageLimit} bind:offset sum={$accountSession?.total} />
|
||||
</div>
|
||||
</Container>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
|
||||
export const accountSession = cachedStore<
|
||||
Models.SessionList,
|
||||
{
|
||||
load: () => Promise<void>;
|
||||
}
|
||||
>('accountSession', function ({ set }) {
|
||||
return {
|
||||
load: async () => {
|
||||
const response = await sdkForConsole.account.getSessions();
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
});
|
||||
export const accountActivity = cachedStore<
|
||||
Models.LogList,
|
||||
{
|
||||
load: (limit: number, offset: number) => Promise<void>;
|
||||
}
|
||||
>('accountActivity', function ({ set }) {
|
||||
return {
|
||||
load: async (limit, offset) => {
|
||||
const response = await sdkForConsole.account.getLogs(limit, offset);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -1,17 +1,15 @@
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { browser } from '$app/env';
|
||||
|
||||
function createUsersListStore() {
|
||||
const { subscribe, set } = writable<Models.UserList<Record<string, unknown>>>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('users')) : null
|
||||
);
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const usersList = cachedStore<
|
||||
Models.UserList<Record<string, unknown>>,
|
||||
{
|
||||
load: (search: string, limit: number, offset: number) => Promise<void>;
|
||||
}
|
||||
>('users', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (search: string, limit: number, offset: number) => {
|
||||
load: async (search, limit, offset) => {
|
||||
const response = await sdkForProject.users.list(
|
||||
search,
|
||||
limit,
|
||||
@@ -23,17 +21,16 @@ function createUsersListStore() {
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function createTeamsListStore() {
|
||||
const { subscribe, set } = writable<Models.TeamList>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('teams')) : null
|
||||
);
|
||||
});
|
||||
|
||||
export const teamsList = cachedStore<
|
||||
Models.TeamList,
|
||||
{
|
||||
load: (search: string, limit: number, offset: number) => Promise<void>;
|
||||
}
|
||||
>('teams', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (search: string, limit: number, offset: number) => {
|
||||
load: async (search, limit, offset) => {
|
||||
const response = await sdkForProject.teams.list(
|
||||
search,
|
||||
limit,
|
||||
@@ -45,28 +42,18 @@ function createTeamsListStore() {
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
function createUsersUsageStore() {
|
||||
const { subscribe, set } = writable(
|
||||
browser ? JSON.parse(sessionStorage.getItem('usersUsage')) : null
|
||||
);
|
||||
});
|
||||
|
||||
export const usersUsage = cachedStore<
|
||||
Models.UsageUsers,
|
||||
{
|
||||
load: (range: string) => Promise<void>;
|
||||
}
|
||||
>('usersUsage', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (range: string) => {
|
||||
load: async (range) => {
|
||||
const response = await sdkForProject.users.getUsage(range);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const usersList = createUsersListStore();
|
||||
export const teamsList = createTeamsListStore();
|
||||
export const usersUsage = createUsersUsageStore();
|
||||
|
||||
if (browser) {
|
||||
usersList.subscribe((n) => sessionStorage?.setItem('users', JSON.stringify(n ?? '')));
|
||||
teamsList.subscribe((n) => sessionStorage?.setItem('teams', JSON.stringify(n ?? '')));
|
||||
usersUsage.subscribe((n) => sessionStorage?.setItem('usersUsage', JSON.stringify(n ?? '')));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/env';
|
||||
|
||||
function createTeamStore() {
|
||||
const { subscribe, set } = writable<Models.Team>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('team')) : null
|
||||
);
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const team = cachedStore<
|
||||
Models.Team,
|
||||
{
|
||||
load: (teamId: string) => Promise<void>;
|
||||
}
|
||||
>('team', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (teamId: string) => {
|
||||
const response = await sdkForProject.teams.get(teamId);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
function createMembershipStore() {
|
||||
const { subscribe, set } = writable<Models.MembershipList>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('memberships')) : null
|
||||
);
|
||||
|
||||
});
|
||||
export const memberships = cachedStore<
|
||||
Models.MembershipList,
|
||||
{
|
||||
load: (teamId: string, search: string, limit: number, offset: number) => Promise<void>;
|
||||
}
|
||||
>('memberships', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (teamId: string, search: string, limit: number, offset: number) => {
|
||||
load: async (teamId, search, limit, offset) => {
|
||||
const response = await sdkForProject.teams.getMemberships(
|
||||
teamId,
|
||||
search,
|
||||
@@ -38,12 +35,4 @@ function createMembershipStore() {
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const memberships = createMembershipStore();
|
||||
export const team = createTeamStore();
|
||||
|
||||
if (browser) {
|
||||
team.subscribe((n) => sessionStorage?.setItem('team', JSON.stringify(n ?? '')));
|
||||
memberships.subscribe((n) => sessionStorage?.setItem('memberships', JSON.stringify(n ?? '')));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/env';
|
||||
|
||||
function createUserStore() {
|
||||
const { subscribe, set } = writable<Models.User<Record<string, unknown>>>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('selectedUser')) : null
|
||||
);
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const user = cachedStore<
|
||||
Models.User<Record<string, unknown>>,
|
||||
{
|
||||
load: (userId: string) => Promise<void>;
|
||||
}
|
||||
>('selectedUser', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (userId: string) => {
|
||||
const response = await sdkForProject.users.get(userId);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const user = createUserStore();
|
||||
|
||||
if (browser) {
|
||||
user.subscribe((n) => sessionStorage?.setItem('selectedUser', JSON.stringify(n ?? '')));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/env';
|
||||
|
||||
function createFileStore() {
|
||||
const { subscribe, set } = writable<Models.File>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('file')) : null
|
||||
);
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const file = cachedStore<
|
||||
Models.File,
|
||||
{
|
||||
load: (bucketId: string, fileId: string) => Promise<void>;
|
||||
}
|
||||
>('file', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (bucketId: string, fileId: string) => {
|
||||
load: async (bucketId, fileId) => {
|
||||
const response = await sdkForProject.storage.getFile(bucketId, fileId);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const file = createFileStore();
|
||||
|
||||
if (browser) {
|
||||
file.subscribe((n) => sessionStorage?.setItem('file', JSON.stringify(n ?? '')));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/env';
|
||||
|
||||
function createBucketListStore() {
|
||||
const { subscribe, set } = writable<Models.BucketList>(
|
||||
browser ? JSON.parse(sessionStorage.getItem('bucketList')) : null
|
||||
);
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const bucketList = cachedStore<
|
||||
Models.BucketList,
|
||||
{
|
||||
load: (search: string, limit: number, offset: number) => Promise<void>;
|
||||
}
|
||||
>('bucketList', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (search: string, limit: number, offset: number) => {
|
||||
load: async (search, limit, offset) => {
|
||||
const response = await sdkForProject.storage.listBuckets(search, limit, offset);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const bucketList = createBucketListStore();
|
||||
|
||||
if (browser) {
|
||||
bucketList.subscribe((n) => sessionStorage?.setItem('bucketList', JSON.stringify(n ?? '')));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
function createProject() {
|
||||
const { subscribe, set } = writable<Models.Project>();
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const project = cachedStore<
|
||||
Models.Project,
|
||||
{
|
||||
load: (projectId: string) => Promise<void>;
|
||||
}
|
||||
>('project', function ({ set }) {
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (projectId: string) => {
|
||||
const project = await sdkForConsole.projects.get(projectId);
|
||||
set(project);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const project = createProject();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user