diff --git a/src/routes/console/project-[project]/messaging/topics/+page.svelte b/src/routes/console/project-[project]/messaging/topics/+page.svelte new file mode 100644 index 000000000..1a990e8b8 --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/+page.svelte @@ -0,0 +1,160 @@ + + + +
+
+ Topics +
+ +
+
+ + +
+ + + +
+
+
+
+ + +
+
+ + +
+
+
+ {#if data.topics.total} + + + d.$id)} /> + {#each $columns as column} + {#if column.show} + {column.title} + {/if} + {/each} + + + {#each data.topics.topics as topic (topic.$id)} + + + + {#each $columns as column (column.id)} + {#if column.show} + {#if column.id === '$id'} + {#key $columns} + + {topic.$id} + + {/key} + {:else if column.type === 'datetime'} + + {#if !topic[column.id]} + - + {:else} + {toLocaleDateTime(topic[column.id])} + {/if} + + {:else} + + {topic[column.id]} + + {/if} + {/if} + {/each} + + {/each} + + + + + + {:else if data.search && data.search != 'empty'} + +
+ Sorry, we couldn't find '{data.search}' +

There are no topics that match your search.

+
+ +
+ {:else} + + ($showCreate = true)} + href="https://appwrite.io/docs/references/cloud/client-web/teams" + target="topic" /> + {/if} +
+ + + diff --git a/src/routes/console/project-[project]/messaging/topics/+page.ts b/src/routes/console/project-[project]/messaging/topics/+page.ts new file mode 100644 index 000000000..ead3791df --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/+page.ts @@ -0,0 +1,62 @@ +import { Query } from '@appwrite.io/console'; +import { sdk } from '$lib/stores/sdk'; +import { getLimit, getPage, getQuery, getSearch, pageToOffset } from '$lib/helpers/load'; +import { PAGE_LIMIT } from '$lib/constants'; +import { queryParamToMap, queries } from '$lib/components/filters/store'; + +// TODO: remove when sdk has the model +export type Topic = { + $id: string; + $createdAt: string; + $updatedAt: string; + providerId: string; + name: string; + total: number; + description: string; +}; + +export const load = async ({ url, route }) => { + const page = getPage(url); + const search = getSearch(url); + const limit = getLimit(url, route, PAGE_LIMIT); + const offset = pageToOffset(page, limit); + const query = getQuery(url); + + const parsedQueries = queryParamToMap(query || '[]'); + queries.set(parsedQueries); + + const payload = { + queries: [ + Query.limit(limit), + Query.offset(offset), + Query.orderDesc(''), + ...parsedQueries.values() + ] + }; + + if (search) { + payload['search'] = search; + } + + // TODO: remove when the API is ready with data + // This allows us to mock w/ data and when search returns 0 results + const topics: { topics: Topic[]; total: number } = await sdk.forProject.client.call( + 'GET', + new URL(sdk.forProject.client.config.endpoint + '/messaging/topics'), + { + 'X-Appwrite-Project': sdk.forProject.client.config.project, + 'content-type': 'application/json', + 'X-Appwrite-Mode': 'admin' + }, + payload + ); + + return { + offset, + limit, + search, + query, + page, + topics + }; +}; diff --git a/src/routes/console/project-[project]/messaging/topics/create.svelte b/src/routes/console/project-[project]/messaging/topics/create.svelte new file mode 100644 index 000000000..65528f2c0 --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/create.svelte @@ -0,0 +1,68 @@ + + + + + + {#if !showCustomId} +
+ (showCustomId = !showCustomId)} + > +
+ {:else} + + {/if} +
+ + + + +
diff --git a/src/routes/console/project-[project]/messaging/topics/store.ts b/src/routes/console/project-[project]/messaging/topics/store.ts new file mode 100644 index 000000000..f8bd1df06 --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/store.ts @@ -0,0 +1,11 @@ +import type { Column } from '$lib/helpers/types'; +import { writable } from 'svelte/store'; + +export let showCreate = writable(false); + +export const columns = writable([ + { id: '$id', title: 'Topic ID', type: 'string', show: true, width: 140 }, + { id: 'name', title: 'Name', type: 'string', show: true, width: 140 }, + { id: 'total', title: 'Subscribers', type: 'integer', show: true, width: 140 }, + { id: '$createdAt', title: 'Created', type: 'datetime', show: true, width: 140 } +]);