mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-20 21:39:37 +02:00
Archive Collections
This commit is contained in:
parent
493c25018c
commit
1858790308
9 changed files with 173 additions and 33 deletions
|
@ -5,12 +5,15 @@
|
|||
import TrashCanOutline from '~icons/mdi/trash-can-outline';
|
||||
|
||||
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
||||
import ArchiveArrowDown from '~icons/mdi/archive-arrow-down';
|
||||
import ArchiveArrowUp from '~icons/mdi/archive-arrow-up';
|
||||
|
||||
import { goto } from '$app/navigation';
|
||||
import type { Collection } from '$lib/types';
|
||||
import { addToast } from '$lib/toasts';
|
||||
|
||||
import Plus from '~icons/mdi/plus';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
|
@ -22,6 +25,24 @@
|
|||
dispatch('edit', collection);
|
||||
}
|
||||
|
||||
async function archiveCollection(is_archived: boolean) {
|
||||
console.log(JSON.stringify({ is_archived: is_archived }));
|
||||
let res = await fetch(`/api/collections/${collection.id}/`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ is_archived: is_archived })
|
||||
});
|
||||
if (res.ok) {
|
||||
console.log(`Collection ${is_archived ? 'archived' : 'unarchived'}`);
|
||||
addToast('info', `Adventure ${is_archived ? 'archived' : 'unarchived'} successfully!`);
|
||||
dispatch('delete', collection.id);
|
||||
} else {
|
||||
console.log('Error archiving adventure');
|
||||
}
|
||||
}
|
||||
|
||||
export let collection: Collection;
|
||||
|
||||
async function deleteCollection() {
|
||||
|
@ -61,15 +82,22 @@
|
|||
) + 1}{' '}
|
||||
days
|
||||
</p>{/if}
|
||||
<div class="badge badge-neutral">{collection.is_public ? 'Public' : 'Private'}</div>
|
||||
<div class="inline-flex gap-2 mb-2">
|
||||
<div class="badge badge-neutral">{collection.is_public ? 'Public' : 'Private'}</div>
|
||||
{#if collection.is_archived}
|
||||
<div class="badge badge-warning">Archived</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="card-actions justify-end">
|
||||
{#if type != 'link'}
|
||||
<button on:click={deleteCollection} class="btn btn-secondary"
|
||||
><TrashCanOutline class="w-5 h-5 mr-1" /></button
|
||||
>
|
||||
<button class="btn btn-primary" on:click={editAdventure}>
|
||||
<FileDocumentEdit class="w-6 h-6" />
|
||||
</button>
|
||||
{#if !collection.is_archived}
|
||||
<button class="btn btn-primary" on:click={editAdventure}>
|
||||
<FileDocumentEdit class="w-6 h-6" />
|
||||
</button>
|
||||
{/if}
|
||||
<button class="btn btn-primary" on:click={() => goto(`/collections/${collection.id}`)}
|
||||
><Launch class="w-5 h-5 mr-1" /></button
|
||||
>
|
||||
|
@ -79,6 +107,15 @@
|
|||
<Plus class="w-5 h-5 mr-1" />
|
||||
</button>
|
||||
{/if}
|
||||
{#if collection.is_archived}
|
||||
<button class="btn btn-primary" on:click={() => archiveCollection(false)}>
|
||||
<ArchiveArrowUp class="w-5 h-5 mr-1" />
|
||||
</button>
|
||||
{:else}
|
||||
<button class="btn btn-primary" on:click={() => archiveCollection(true)}>
|
||||
<ArchiveArrowDown class="w-5 h-5 mr" />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue