-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from appwrite/feat-messaging-topics
Add messaging topics route
- Loading branch information
Showing
32 changed files
with
1,589 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/routes/console/project-[project]/messaging/actions.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script lang="ts"> | ||
import { DropList, DropListItem } from '$lib/components'; | ||
import { createEventDispatcher } from 'svelte'; | ||
import { targetsById } from './wizard/store'; | ||
import UserTargetsModal from './userTargetsModal.svelte'; | ||
import type { ProviderTypes } from './providerType.svelte'; | ||
import TopicsModal from './topicsModal.svelte'; | ||
import { topicsById } from './store'; | ||
export let showDropdown: boolean; | ||
export let showUserTargets: boolean; | ||
export let showTopics: boolean; | ||
export let providerType: ProviderTypes = null; | ||
const dispatch = createEventDispatcher(); | ||
$: if (showUserTargets || showTopics) { | ||
showDropdown = false; | ||
} | ||
</script> | ||
|
||
<DropList bind:show={showDropdown} placement="bottom-end" fixed> | ||
<slot /> | ||
<svelte:fragment slot="list"> | ||
<DropListItem on:click={() => (showTopics = true)}>Select topics</DropListItem> | ||
<DropListItem on:click={() => (showUserTargets = true)}>Select targets</DropListItem> | ||
</svelte:fragment> | ||
</DropList> | ||
|
||
<TopicsModal | ||
bind:show={showTopics} | ||
bind:topicsById={$topicsById} | ||
on:update={(e) => { | ||
showTopics = false; | ||
dispatch('addTopics', e.detail); | ||
}} /> | ||
<UserTargetsModal | ||
{providerType} | ||
bind:show={showUserTargets} | ||
bind:targetsById={$targetsById} | ||
on:update={(e) => { | ||
showUserTargets = false; | ||
dispatch('addTargets', e.detail); | ||
}} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/routes/console/project-[project]/messaging/topics/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<script lang="ts"> | ||
import { page } from '$app/stores'; | ||
import { Button } from '$lib/elements/forms'; | ||
import { | ||
Empty, | ||
EmptySearch, | ||
SearchQuery, | ||
PaginationWithLimit, | ||
Heading, | ||
ViewSelector | ||
} from '$lib/components'; | ||
import Create from './create.svelte'; | ||
import { goto } from '$app/navigation'; | ||
import { Container } from '$lib/layout'; | ||
import { base } from '$app/paths'; | ||
import type { Models } from '@appwrite.io/console'; | ||
import type { PageData } from './$types'; | ||
import { columns, showCreate } from './store'; | ||
import { View } from '$lib/helpers/load'; | ||
import Filters from '$lib/components/filters/filters.svelte'; | ||
import Table from './table.svelte'; | ||
export let data: PageData; | ||
const project = $page.params.project; | ||
const topicCreated = async (event: CustomEvent<Models.Team<Record<string, unknown>>>) => { | ||
await goto(`${base}/console/project-${project}/messaging/topics/topic-${event.detail.$id}`); | ||
}; | ||
</script> | ||
|
||
<Container> | ||
<div class="u-flex u-flex-vertical"> | ||
<div class="u-flex u-main-space-between"> | ||
<Heading tag="h2" size="5">Topics</Heading> | ||
<div class="is-only-mobile"> | ||
<Button on:click={() => ($showCreate = true)} event="create_topic"> | ||
<span class="icon-plus" aria-hidden="true" /> | ||
<span class="text">Create topic</span> | ||
</Button> | ||
</div> | ||
</div> | ||
<!-- TODO: fix width of search input in mobile --> | ||
<SearchQuery search={data.search} placeholder="Search by name or ID"> | ||
<div class="u-flex u-gap-16 is-not-mobile"> | ||
<Filters query={data.query} {columns} /> | ||
<ViewSelector | ||
view={View.Table} | ||
{columns} | ||
hideView | ||
allowNoColumns | ||
showColsTextMobile /> | ||
<Button on:click={() => ($showCreate = true)} event="create_topic"> | ||
<span class="icon-plus" aria-hidden="true" /> | ||
<span class="text">Create topic</span> | ||
</Button> | ||
</div> | ||
</SearchQuery> | ||
<div class="u-flex u-gap-16 is-only-mobile u-margin-block-start-16"> | ||
<div class="u-flex-basis-50-percent"> | ||
<!-- TODO: fix width --> | ||
<ViewSelector | ||
view={View.Table} | ||
{columns} | ||
hideView | ||
allowNoColumns | ||
showColsTextMobile /> | ||
</div> | ||
<div class="u-flex-basis-50-percent"> | ||
<!-- TODO: fix width --> | ||
<Filters query={data.query} {columns} /> | ||
</div> | ||
</div> | ||
</div> | ||
{#if data.topics.total} | ||
<Table {data} /> | ||
|
||
<PaginationWithLimit | ||
name="Topics" | ||
limit={data.limit} | ||
offset={data.offset} | ||
total={data.topics.total} /> | ||
<!-- TODO: remove data.search != 'empty' when the API is ready with data --> | ||
{:else if data.search && data.search != 'empty'} | ||
<EmptySearch> | ||
<div class="u-text-center"> | ||
<b>Sorry, we couldn't find '{data.search}'</b> | ||
<p>There are no topics that match your search.</p> | ||
</div> | ||
<Button secondary href={`/console/project-${$page.params.project}/messaging/topics`}> | ||
Clear Search | ||
</Button> | ||
</EmptySearch> | ||
{:else} | ||
<!-- TODO: update docs link --> | ||
<Empty | ||
single | ||
on:click={() => ($showCreate = true)} | ||
href="https://appwrite.io/docs/references/cloud/client-web/teams" | ||
target="topic" /> | ||
{/if} | ||
</Container> | ||
|
||
<Create bind:showCreate={$showCreate} on:created={topicCreated} /> |
53 changes: 53 additions & 0 deletions
53
src/routes/console/project-[project]/messaging/topics/+page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Query } from '@appwrite.io/console'; | ||
import { sdk } from '$lib/stores/sdk'; | ||
import { getLimit, getPage, getQuery, getSearch, pageToOffset } from '$lib/helpers/load'; | ||
import { Dependencies, PAGE_LIMIT } from '$lib/constants'; | ||
import { queryParamToMap, queries } from '$lib/components/filters/store'; | ||
import type { Topic } from '../store'; | ||
|
||
export const load = async ({ depends, url, route }) => { | ||
depends(Dependencies.MESSAGING_TOPICS); | ||
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 | ||
}; | ||
}; |
88 changes: 88 additions & 0 deletions
88
src/routes/console/project-[project]/messaging/topics/create.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<script lang="ts"> | ||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; | ||
import { Modal, CustomId } from '$lib/components'; | ||
import { Pill } from '$lib/elements'; | ||
import { InputText, Button, FormList } from '$lib/elements/forms'; | ||
import { addNotification } from '$lib/stores/notifications'; | ||
import { sdk } from '$lib/stores/sdk'; | ||
import { ID } from '@appwrite.io/console'; | ||
import { createEventDispatcher } from 'svelte'; | ||
export let showCreate = false; | ||
const dispatch = createEventDispatcher(); | ||
let name: string, description: string, id: string, error: string; | ||
let showCustomId = false; | ||
const create = async () => { | ||
try { | ||
const topic = await sdk.forProject.client.call( | ||
'POST', | ||
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' | ||
}, | ||
{ | ||
name, | ||
description, | ||
topicId: id ?? ID.unique() | ||
} | ||
); | ||
name = ''; | ||
description = ''; | ||
showCreate = false; | ||
showCustomId = false; | ||
addNotification({ | ||
type: 'success', | ||
message: `${topic.name} has been created` | ||
}); | ||
trackEvent(Submit.MessagingTopicCreate, { | ||
customId: !!id | ||
}); | ||
dispatch('created', topic); | ||
} catch (e) { | ||
error = e.message; | ||
trackError(e, Submit.MessagingTopicCreate); | ||
} | ||
}; | ||
$: if (!showCreate) { | ||
showCustomId = false; | ||
error = null; | ||
} | ||
</script> | ||
|
||
<Modal title="Create topic" {error} size="big" bind:show={showCreate} onSubmit={create}> | ||
<FormList> | ||
<InputText | ||
id="name" | ||
label="Name" | ||
placeholder="Enter name" | ||
autofocus={true} | ||
required | ||
bind:value={name} /> | ||
<InputText | ||
id="description" | ||
label="Description" | ||
placeholder="Enter description" | ||
bind:value={description}> | ||
</InputText> | ||
{#if !showCustomId} | ||
<div> | ||
<Pill button on:click={() => (showCustomId = !showCustomId)} | ||
><span class="icon-pencil" aria-hidden="true" /> | ||
<span class="text"> Topic ID </span> | ||
</Pill> | ||
</div> | ||
{:else} | ||
<CustomId bind:show={showCustomId} name="Topic" bind:id /> | ||
{/if} | ||
</FormList> | ||
<svelte:fragment slot="footer"> | ||
<Button secondary on:click={() => (showCreate = false)}>Cancel</Button> | ||
<Button submit>Create</Button> | ||
</svelte:fragment> | ||
</Modal> |
12 changes: 12 additions & 0 deletions
12
src/routes/console/project-[project]/messaging/topics/store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { Column } from '$lib/helpers/types'; | ||
import { writable } from 'svelte/store'; | ||
|
||
export let showCreate = writable(false); | ||
|
||
export const columns = writable<Column[]>([ | ||
{ id: '$id', title: 'Topic ID', type: 'string', show: true, width: 140 }, | ||
{ id: 'name', title: 'Name', type: 'string', show: true, width: 140 }, | ||
{ id: 'description', title: 'Description', 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 } | ||
]); |
Oops, something went wrong.