From fee8e9cbed0aee769355aff386bc4da6480bd9a4 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 15 Dec 2023 11:51:39 -0800 Subject: [PATCH] Add topic activity page --- .../topic-[topic]/activity/+page.svelte | 8 +++++ .../topics/topic-[topic]/activity/+page.ts | 34 +++++++++++++++++++ .../topics/topic-[topic]/header.svelte | 16 +++------ 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.svelte create mode 100644 src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.ts diff --git a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.svelte b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.svelte new file mode 100644 index 0000000000..f805a79f04 --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.svelte @@ -0,0 +1,8 @@ + + + diff --git a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.ts b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.ts new file mode 100644 index 0000000000..97f3d29aeb --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/activity/+page.ts @@ -0,0 +1,34 @@ +import { Query, type Models } from '@appwrite.io/console'; +import { sdk } from '$lib/stores/sdk'; +import { getLimit, getPage, pageToOffset } from '$lib/helpers/load'; +import { PAGE_LIMIT } from '$lib/constants'; +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ params, url, route }) => { + const page = getPage(url); + const limit = getLimit(url, route, PAGE_LIMIT); + const offset = pageToOffset(page, limit); + + const payload = { + queries: [Query.limit(limit), Query.offset(offset)] + }; + + // TODO: remove when the API is ready with data + // This allows us to mock w/ data and when search returns 0 results + const logs: Models.LogList = await sdk.forProject.client.call( + 'GET', + new URL(`${sdk.forProject.client.config.endpoint}/messaging/topics/${params.topic}/logs`), + { + 'X-Appwrite-Project': sdk.forProject.client.config.project, + 'content-type': 'application/json', + 'X-Appwrite-Mode': 'admin' + }, + payload + ); + + return { + offset, + limit, + logs + }; +}; diff --git a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte index 660b177e71..0848e48db2 100644 --- a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte +++ b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte @@ -18,18 +18,12 @@ href: `${path}/subscribers`, title: 'Subscribers', event: 'subscribers' + }, + { + href: `${path}/activity`, + title: 'Activity', + event: 'activity' } - // { - // href: `${path}/sessions`, - // title: 'Sessions', - // event: 'sessions' - // }, - // { - // href: `${path}/activity`, - // title: 'Activity', - // event: 'activity', - // hasChildren: true - // } ];