|
| 1 | +<script lang="ts"> |
| 2 | + import { goto } from '$app/navigation'; |
| 3 | + import { base } from '$app/paths'; |
| 4 | + import { page } from '$app/stores'; |
| 5 | + import { |
| 6 | + Empty, |
| 7 | + EmptySearch, |
| 8 | + FloatingActionBar, |
| 9 | + Heading, |
| 10 | + Id, |
| 11 | + PaginationWithLimit, |
| 12 | + SearchQuery, |
| 13 | + ViewSelector |
| 14 | + } from '$lib/components'; |
| 15 | + import { Button } from '$lib/elements/forms'; |
| 16 | + import { Container } from '$lib/layout'; |
| 17 | + import type { Models } from '@appwrite.io/console'; |
| 18 | + import type { PageData } from './$types'; |
| 19 | + import Create from './create.svelte'; |
| 20 | + import { |
| 21 | + TableHeader, |
| 22 | + TableCellHead, |
| 23 | + TableBody, |
| 24 | + TableCell, |
| 25 | + TableCellText, |
| 26 | + TableRowLink, |
| 27 | + TableCellHeadCheck, |
| 28 | + TableCellCheck |
| 29 | + } from '$lib/elements/table'; |
| 30 | + import { toLocaleDateTime } from '$lib/helpers/date'; |
| 31 | + import Filters from '../databases/database-[database]/collection-[collection]/(filters)/filters.svelte'; |
| 32 | + import { columns, showCreate } from './store'; |
| 33 | + import TableScroll from '$lib/elements/table/tableScroll.svelte'; |
| 34 | +
|
| 35 | + export let data: PageData; |
| 36 | + let selected: string[] = []; |
| 37 | + let showDelete = false; |
| 38 | +
|
| 39 | + const project = $page.params.project; |
| 40 | +
|
| 41 | + async function messageCreated(event: CustomEvent<Models.Bucket>) { |
| 42 | + $showCreate = false; |
| 43 | + await goto(`${base}/console/project-${project}/messaging/message-${event.detail.$id}`); |
| 44 | + } |
| 45 | +</script> |
| 46 | + |
| 47 | +<Container> |
| 48 | + <div class="u-flex u-flex-vertical"> |
| 49 | + <div class="u-flex u-main-space-between"> |
| 50 | + <Heading tag="h2" size="5">Messages</Heading> |
| 51 | + <div class="is-only-mobile"> |
| 52 | + <Button on:click={() => ($showCreate = true)} event="create_message"> |
| 53 | + <span class="icon-plus" aria-hidden="true" /> |
| 54 | + <span class="text">Create message</span> |
| 55 | + </Button> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + <!-- TODO: fix width of search input in mobile --> |
| 59 | + <SearchQuery search={data.search} placeholder="Search by channel, topic, provider, or ID"> |
| 60 | + <div class="u-flex u-gap-16 is-not-mobile"> |
| 61 | + <!-- TODO: make this not database-specific --> |
| 62 | + <Filters /> |
| 63 | + <ViewSelector |
| 64 | + view={data.view} |
| 65 | + {columns} |
| 66 | + hideView |
| 67 | + allowNoColumns |
| 68 | + showColsTextMobile /> |
| 69 | + <Button on:click={() => ($showCreate = true)} event="create_message"> |
| 70 | + <span class="icon-plus" aria-hidden="true" /> |
| 71 | + <span class="text">Create message</span> |
| 72 | + </Button> |
| 73 | + </div> |
| 74 | + </SearchQuery> |
| 75 | + <div class="u-flex u-gap-16 is-only-mobile u-margin-block-start-16"> |
| 76 | + <div class="u-flex-basis-50-percent"> |
| 77 | + <!-- TODO: fix width --> |
| 78 | + <ViewSelector |
| 79 | + view={data.view} |
| 80 | + {columns} |
| 81 | + hideView |
| 82 | + allowNoColumns |
| 83 | + showColsTextMobile /> |
| 84 | + </div> |
| 85 | + <div class="u-flex-basis-50-percent"> |
| 86 | + <!-- TODO: fix width --> |
| 87 | + <Filters /> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + |
| 92 | + {#if data.messages.total} |
| 93 | + <TableScroll> |
| 94 | + <TableHeader> |
| 95 | + <TableCellHeadCheck |
| 96 | + bind:selected |
| 97 | + pageItemsIds={data.messages.messages.map((d) => d.$id)} /> |
| 98 | + {#each $columns as column} |
| 99 | + {#if column.show} |
| 100 | + <TableCellHead width={column.width}>{column.title}</TableCellHead> |
| 101 | + {/if} |
| 102 | + {/each} |
| 103 | + </TableHeader> |
| 104 | + <TableBody> |
| 105 | + {#each data.messages.messages as message} |
| 106 | + <TableRowLink |
| 107 | + href={`${base}/console/project-${project}/messaging/message-${message.$id}`}> |
| 108 | + <TableCellCheck bind:selectedIds={selected} id={message.$id} /> |
| 109 | + |
| 110 | + {#each $columns as column} |
| 111 | + {#if column.show} |
| 112 | + {#if column.id === '$id'} |
| 113 | + {#key $columns} |
| 114 | + <TableCell title={column.title} width={column.width}> |
| 115 | + <Id value={message.$id}>{message.$id}</Id> |
| 116 | + </TableCell> |
| 117 | + {/key} |
| 118 | + {:else if column.id === 'deliveryTime'} |
| 119 | + <TableCellText title={column.title} width={column.width}> |
| 120 | + {toLocaleDateTime(message[column.id])} |
| 121 | + </TableCellText> |
| 122 | + {:else} |
| 123 | + <TableCellText title={column.title} width={column.width}> |
| 124 | + {message[column.id]} |
| 125 | + </TableCellText> |
| 126 | + {/if} |
| 127 | + {/if} |
| 128 | + {/each} |
| 129 | + </TableRowLink> |
| 130 | + {/each} |
| 131 | + </TableBody> |
| 132 | + </TableScroll> |
| 133 | + |
| 134 | + <FloatingActionBar show={selected.length > 0}> |
| 135 | + <div class="u-flex u-cross-center u-main-space-between actions"> |
| 136 | + <div class="u-flex u-cross-center u-gap-8"> |
| 137 | + <span class="indicator body-text-2 u-bold">{selected.length}</span> |
| 138 | + <p> |
| 139 | + <span class="is-only-desktop"> |
| 140 | + {selected.length > 1 ? 'messages' : 'message'} |
| 141 | + </span> |
| 142 | + selected |
| 143 | + </p> |
| 144 | + </div> |
| 145 | + |
| 146 | + <div class="u-flex u-cross-center u-gap-8"> |
| 147 | + <Button text on:click={() => (selected = [])}>Cancel</Button> |
| 148 | + <!-- TODO: handle delete --> |
| 149 | + <Button secondary on:click={() => (showDelete = true)}> |
| 150 | + <p>Delete</p> |
| 151 | + </Button> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + </FloatingActionBar> |
| 155 | + |
| 156 | + <PaginationWithLimit |
| 157 | + name="Messages" |
| 158 | + limit={data.limit} |
| 159 | + offset={data.offset} |
| 160 | + total={data.messages.total} /> |
| 161 | + <!-- TODO: remove data.search != 'empty' when the API is ready with data --> |
| 162 | + {:else if data.search && data.search != 'empty'} |
| 163 | + <EmptySearch> |
| 164 | + <div class="u-text-center"> |
| 165 | + <b>Sorry, we couldn't find '{data.search}'</b> |
| 166 | + <p>There are no messages that match your search.</p> |
| 167 | + </div> |
| 168 | + <div class="u-flex u-gap-16"> |
| 169 | + <!-- TODO: update docs link --> |
| 170 | + <Button |
| 171 | + external |
| 172 | + href="https://appwrite.io/docs/products/storage/upload-download" |
| 173 | + text> |
| 174 | + Documentation |
| 175 | + </Button> |
| 176 | + <Button |
| 177 | + secondary |
| 178 | + href={`/console/project-${$page.params.project}/storage/bucket-${$page.params.bucket}`}> |
| 179 | + Clear Search |
| 180 | + </Button> |
| 181 | + </div> |
| 182 | + </EmptySearch> |
| 183 | + {:else} |
| 184 | + <!-- TODO: update docs link --> |
| 185 | + <Empty |
| 186 | + single |
| 187 | + href="https://appwrite.io/docs" |
| 188 | + target="message" |
| 189 | + on:click={() => ($showCreate = true)} /> |
| 190 | + {/if} |
| 191 | +</Container> |
| 192 | + |
| 193 | +<!-- TODO: handle create --> |
| 194 | +<Create bind:showCreate={$showCreate} on:created={messageCreated} /> |
0 commit comments