Skip to content

Commit

Permalink
feat: Managing archived status
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie committed Dec 4, 2024
1 parent d161d54 commit a71c943
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/routes/announcements/[slug]/AdminButtons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
export let isEditing: boolean,
isCreating,
isPreviewing: boolean,
archivedAtElement: string | null,
showDeleteConfirm: boolean,
createAnnouncement,
save;
const toggleArchived = () => {
if (archivedAtElement) {
archivedAtElement = null;
} else {
archivedAtElement = new Date().toISOString().split('.')[0].slice(0, -3);
}
};
</script>

<div>
Expand All @@ -16,9 +25,19 @@
icon={isPreviewing ? 'hide' : 'show'}
on:click={() => (isPreviewing = !isPreviewing)}
/>
<Button
type="icon"
icon={archivedAtElement ? 'unarchive' : 'archive'}
on:click={toggleArchived}
/>
<Button type="icon" icon={'close'} on:click={() => (isEditing = false)} />
<Button type="icon" icon={'check'} on:click={save} />
{:else if isCreating}
<Button
type="icon"
icon={archivedAtElement ? 'unarchive' : 'archive'}
on:click={toggleArchived}
/>
<Button
type="icon"
icon={isPreviewing ? 'hide' : 'show'}
Expand Down
6 changes: 5 additions & 1 deletion src/routes/announcements/[slug]/Announcement.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { admin, queries } from '$data/api';
import { admin } from '$data/api';
import Button from '$lib/components/Button.svelte';
import Dialogue from '$lib/components/Dialogue.svelte';
import { admin_login } from '$lib/stores';
Expand All @@ -25,6 +25,7 @@
let authorElement: string = announcementContent?.author ?? '';
let contentElement: string = announcementContent?.content ?? '';
let createdAtElement: string = announcementContent?.created_at ?? '';
let archivedAtElement: string = announcementContent?.archived_at ?? null;
let attachmentsElement: string[] = announcementContent?.attachments ?? [];
const addAttachment = () => {
Expand Down Expand Up @@ -111,6 +112,8 @@
{isEditing}
{isPreviewing}
createdAt={announcementContent.created_at}
archivedAt={announcementContent.archived_at}
bind:archivedAtElement
bind:createdAtElement
/>
·
Expand All @@ -132,6 +135,7 @@
bind:isEditing
bind:isPreviewing
bind:showDeleteConfirm
bind:archivedAtElement
{createAnnouncement}
{save}
/>
Expand Down
50 changes: 47 additions & 3 deletions src/routes/announcements/[slug]/Date.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,67 @@
<script lang="ts">
import moment from 'moment';
export let isEditing, isCreating, isPreviewing, createdAt, createdAtElement: string;
export let isEditing,
isCreating,
isPreviewing,
createdAt,
createdAtElement: string,
archivedAt,
archivedAtElement: string;
// Ensure createdAtElement is properly formatted for the datetime-local input
if (createdAtElement) createdAtElement = createdAtElement.split('.')[0];
if (createdAtElement) {
createdAtElement = createdAtElement.split('.')[0];
} else {
createdAtElement = new Date().toISOString().split('.')[0].slice(0, -3);
}
</script>

{#if (isEditing || isCreating) && !isPreviewing}
<input type="datetime-local" max="9999-12-31T23:59" bind:value={createdAtElement} />
<span>
<input type="datetime-local" max="9999-12-31T23:59" bind:value={createdAtElement} />
{#if archivedAtElement}
<svg
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 -960 960 960"
width="24px"
fill="#ACC1D2"
>
<path d="M647-440H160v-80h487L423-744l57-56 320 320-320 320-57-56 224-224Z" />
</svg>
<input type="datetime-local" max="9999-12-31T23:59" bind:value={archivedAtElement} />
{/if}
</span>
{:else}
<span>
{isPreviewing
? moment(createdAtElement).format('MMMM D, YYYY [at] h:mm A')
: moment(createdAt).format('MMMM D, YYYY [at] h:mm A')}
{#if archivedAt || archivedAtElement}
<svg
xmlns="http://www.w3.org/2000/svg"
height="24px"
viewBox="0 -960 960 960"
width="24px"
fill="#ACC1D2"
>
<path d="M647-440H160v-80h487L423-744l57-56 320 320-320 320-57-56 224-224Z" />
</svg>
{isPreviewing
? moment(archivedAtElement).format('MMMM D, YYYY [at] h:mm A')
: moment(archivedAt).format('MMMM D, YYYY [at] h:mm A')}
{/if}
</span>
{/if}

<style lang="scss">
span {
display: inline-flex;
align-items: center;
gap: 1rem;
}
input {
&,
&:focus {
Expand Down
1 change: 1 addition & 0 deletions static/icons/archive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/icons/unarchive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a71c943

Please sign in to comment.