mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Update the create message wizard to support topics
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy } from 'svelte';
|
||||
import { Wizard } from '$lib/layout';
|
||||
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
|
||||
import Step1 from './wizard/step1.svelte';
|
||||
@@ -97,10 +96,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
console.log('destroy');
|
||||
});
|
||||
|
||||
const stepsComponents: WizardStepsType = new Map();
|
||||
stepsComponents.set(1, {
|
||||
label: 'Message',
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import Create from './create.svelte';
|
||||
import { messageParams, providerType, targetsById } from './wizard/store';
|
||||
import { ProviderTypes } from './providerType.svelte';
|
||||
import { topicsById } from './store';
|
||||
|
||||
export let showCreateDropdown = false;
|
||||
</script>
|
||||
@@ -29,6 +30,7 @@
|
||||
)
|
||||
return;
|
||||
$providerType = type;
|
||||
$topicsById = {};
|
||||
$targetsById = {};
|
||||
const common = {
|
||||
topics: [],
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Card } from '$lib/components';
|
||||
import UserTargetsModal, { type Target } from '../userTargetsModal.svelte';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import {
|
||||
Table,
|
||||
@@ -12,11 +11,26 @@
|
||||
} from '$lib/elements/table';
|
||||
import { WizardStep } from '$lib/layout';
|
||||
import { messageParams, providerType, targetsById } from './store';
|
||||
import Actions from '../actions.svelte';
|
||||
import { topicsById, type Target, type Topic } from '../store';
|
||||
|
||||
let showDropdown = false;
|
||||
let showTopics = false;
|
||||
let showUserTargets = false;
|
||||
let targetIdsLength = 0;
|
||||
let topicIdsLength = 0;
|
||||
|
||||
function update(event: CustomEvent<Record<string, Target>>) {
|
||||
function addTopics(event: CustomEvent<Record<string, Topic>>) {
|
||||
$topicsById = event.detail;
|
||||
showDropdown = false;
|
||||
}
|
||||
|
||||
function removeTopic(topicId: string) {
|
||||
const { [topicId]: _, ...rest } = $topicsById;
|
||||
$topicsById = rest;
|
||||
}
|
||||
|
||||
function addTargets(event: CustomEvent<Record<string, Target>>) {
|
||||
$targetsById = event.detail;
|
||||
showDropdown = false;
|
||||
}
|
||||
@@ -28,11 +42,12 @@
|
||||
|
||||
async function beforeSubmit() {
|
||||
$messageParams[$providerType].targets = Object.keys($targetsById);
|
||||
$messageParams[$providerType].topics = Object.keys($topicsById);
|
||||
console.log($messageParams[$providerType]);
|
||||
}
|
||||
|
||||
$: topicIdsLength = Object.keys($topicsById).length;
|
||||
$: targetIdsLength = Object.keys($targetsById).length;
|
||||
$: console.log(targetIdsLength);
|
||||
</script>
|
||||
|
||||
<WizardStep {beforeSubmit}>
|
||||
@@ -40,12 +55,20 @@
|
||||
<!-- TODO: add support for topics -->
|
||||
<svelte:fragment slot="subtitle"
|
||||
>Select users to whom this message should be directed.</svelte:fragment>
|
||||
{#if targetIdsLength == 0}
|
||||
{#if targetIdsLength === 0 && topicIdsLength === 0}
|
||||
<Card>
|
||||
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
|
||||
<Button secondary round on:click={() => (showDropdown = !showDropdown)}>
|
||||
<i class="icon-plus" />
|
||||
</Button>
|
||||
<Actions
|
||||
providerType={$providerType}
|
||||
bind:showDropdown
|
||||
bind:showUserTargets
|
||||
bind:showTopics
|
||||
on:addTargets={addTargets}
|
||||
on:addTopics={addTopics}>
|
||||
<Button secondary round on:click={() => (showDropdown = !showDropdown)}>
|
||||
<i class="icon-plus" />
|
||||
</Button>
|
||||
</Actions>
|
||||
<div class="common-section">
|
||||
<span class="text"> Select recipients to get started</span>
|
||||
</div>
|
||||
@@ -59,6 +82,32 @@
|
||||
<TableCellHead width={32} />
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each Object.entries($topicsById) as [topicId, topic] (topicId)}
|
||||
<TableRow>
|
||||
<TableCell title="Target">
|
||||
<div class="u-flex u-cross-center">
|
||||
<span class="title"
|
||||
><span class="u-line-height-1-5">
|
||||
<span class="body-text-2 u-bold" data-private>
|
||||
{topic.name}
|
||||
</span><span class="collapsible-button-optional"
|
||||
>({topic.total} subscribers)</span>
|
||||
</span></span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell title="Remove" width={40}>
|
||||
<div class="u-flex u-main-end">
|
||||
<button
|
||||
class="button is-text is-only-icon"
|
||||
type="button"
|
||||
aria-label="delete"
|
||||
on:click={() => removeTopic(topicId)}>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
{#each Object.entries($targetsById) as [targetId, target] (targetId)}
|
||||
<TableRow>
|
||||
<TableCell title="Target">
|
||||
@@ -84,15 +133,17 @@
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
<Button text noMargin on:click={() => (showDropdown = !showDropdown)}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<span class="text">Add target</span>
|
||||
</Button>
|
||||
<Actions
|
||||
providerType={$providerType}
|
||||
bind:showDropdown
|
||||
bind:showUserTargets
|
||||
bind:showTopics
|
||||
on:addTargets={addTargets}
|
||||
on:addTopics={addTopics}>
|
||||
<Button text noMargin on:click={() => (showDropdown = !showDropdown)}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<span class="text">Add</span>
|
||||
</Button>
|
||||
</Actions>
|
||||
{/if}
|
||||
</WizardStep>
|
||||
|
||||
<UserTargetsModal
|
||||
providerType={$providerType}
|
||||
bind:show={showDropdown}
|
||||
bind:targetsById={$targetsById}
|
||||
on:update={update} />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ProviderTypes } from '../providerType.svelte';
|
||||
import type { Target } from '../userTargetsModal.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Target } from '../store';
|
||||
|
||||
export enum MessageStatuses {
|
||||
DRAFT = 'draft',
|
||||
|
||||
Reference in New Issue
Block a user