From 6991e5bf32a3ca7fcc77c8e3cccf63a8c736d8cb Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 29 Feb 2024 20:46:22 -0800 Subject: [PATCH] fix(messaging): localize the topics columns When it was global, the state (show values) would persist when switching between different projects rather than resetting back to the default. --- .../messaging/topics/+page.svelte | 23 +++++++++++++++++-- .../messaging/topics/store.ts | 11 --------- .../messaging/topics/table.svelte | 9 ++++---- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/routes/console/project-[project]/messaging/topics/+page.svelte b/src/routes/console/project-[project]/messaging/topics/+page.svelte index 4cd0959c8..118d31a46 100644 --- a/src/routes/console/project-[project]/messaging/topics/+page.svelte +++ b/src/routes/console/project-[project]/messaging/topics/+page.svelte @@ -16,14 +16,33 @@ import { base } from '$app/paths'; import type { Models } from '@appwrite.io/console'; import type { PageData } from './$types'; - import { columns, showCreate } from './store'; + import { showCreate } from './store'; import { View } from '$lib/helpers/load'; import { Filters, hasPageQueries } from '$lib/components/filters'; import Table from './table.svelte'; + import type { Column } from '$lib/helpers/types'; + import { writable } from 'svelte/store'; export let data: PageData; const project = $page.params.project; + 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: 'emailTotal', title: 'Email Subscribers', type: 'integer', show: false, width: 140 }, + { id: 'smsTotal', title: 'SMS Subscribers', type: 'integer', show: false, width: 140 }, + { id: 'pushTotal', title: 'Push Subscribers', type: 'integer', show: false, width: 140 }, + { + id: 'total', + title: 'Subscribers', + type: 'integer', + show: true, + filter: false, + width: 140 + }, + { id: '$createdAt', title: 'Created', type: 'datetime', show: true, width: 140 } + ]); + const topicCreated = async (event: CustomEvent>>) => { await goto(`${base}/console/project-${project}/messaging/topics/topic-${event.detail.$id}`); }; @@ -73,7 +92,7 @@ {#if data.topics.total} - +
([ - { id: '$id', title: 'Topic ID', type: 'string', show: true, width: 140 }, - { id: 'name', title: 'Name', type: 'string', show: true, width: 140 }, - { id: 'emailTotal', title: 'Email Subscribers', type: 'integer', show: false, width: 140 }, - { id: 'smsTotal', title: 'SMS Subscribers', type: 'integer', show: false, width: 140 }, - { id: 'pushTotal', title: 'Push Subscribers', type: 'integer', show: false, width: 140 }, - { id: 'total', title: 'Subscribers', type: 'integer', show: true, filter: false, width: 140 }, - { id: '$createdAt', title: 'Created', type: 'datetime', show: true, width: 140 } -]); diff --git a/src/routes/console/project-[project]/messaging/topics/table.svelte b/src/routes/console/project-[project]/messaging/topics/table.svelte index 8e611a83b..9ffc0b2eb 100644 --- a/src/routes/console/project-[project]/messaging/topics/table.svelte +++ b/src/routes/console/project-[project]/messaging/topics/table.svelte @@ -16,13 +16,14 @@ } from '$lib/elements/table'; import { addNotification } from '$lib/stores/notifications'; import type { PageData } from './$types'; - import { columns } from './store'; import { project } from '$routes/console/project-[project]/store'; import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import { sdk } from '$lib/stores/sdk'; import { toLocaleDateTime } from '$lib/helpers/date'; + import type { Column } from '$lib/helpers/types'; + export let columns: Column[]; export let data: PageData; let selectedIds: string[] = []; @@ -62,7 +63,7 @@ d.$id)} /> - {#each $columns as column} + {#each columns as column} {#if column.show} {column.title} {/if} @@ -74,10 +75,10 @@ href={`${base}/console/project-${$project.$id}/messaging/topics/topic-${topic.$id}`}> - {#each $columns as column (column.id)} + {#each columns as column (column.id)} {#if column.show} {#if column.id === '$id'} - {#key $columns} + {#key column.id} {topic.$id}