-
Notifications
You must be signed in to change notification settings - Fork 12
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 #173 from seanmorley15/development
Collection Archive Update
- Loading branch information
Showing
10 changed files
with
232 additions
and
34 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
backend/server/adventures/migrations/0021_collection_is_archived.py
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,18 @@ | ||
# Generated by Django 5.0.7 on 2024-08-07 16:20 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('adventures', '0020_checklist_checklistitem'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='collection', | ||
name='is_archived', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher } from 'svelte'; | ||
const dispatch = createEventDispatcher(); | ||
import { onMount } from 'svelte'; | ||
let modal: HTMLDialogElement; | ||
export let title: string; | ||
export let button_text: string; | ||
export let description: string; | ||
export let is_warning: boolean; | ||
onMount(() => { | ||
modal = document.getElementById('my_modal_1') as HTMLDialogElement; | ||
if (modal) { | ||
modal.showModal(); | ||
} | ||
}); | ||
function close() { | ||
dispatch('close'); | ||
} | ||
function confirm() { | ||
dispatch('close'); | ||
dispatch('confirm'); | ||
} | ||
function handleKeydown(event: KeyboardEvent) { | ||
if (event.key === 'Escape') { | ||
dispatch('close'); | ||
} | ||
} | ||
</script> | ||
|
||
<dialog id="my_modal_1" class="modal {is_warning ? 'bg-primary' : ''}"> | ||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions --> | ||
<!-- svelte-ignore a11y-no-noninteractive-tabindex --> | ||
<div class="modal-box" role="dialog" on:keydown={handleKeydown} tabindex="0"> | ||
<h3 class="font-bold text-lg">{title}</h3> | ||
<p class="py-1 mb-4">{description}</p> | ||
<button class="btn btn-warning mr-2" on:click={confirm}>{button_text}</button> | ||
<button class="btn btn-neutral" on:click={close}>Cancel</button> | ||
</div> | ||
</dialog> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
import type { PageServerLoad } from './$types'; | ||
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; | ||
import type { Adventure } from '$lib/types'; | ||
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; | ||
|
||
export const load = (async (event) => { | ||
if (!event.locals.user) { | ||
return redirect(302, '/login'); | ||
} else { | ||
let next = null; | ||
let previous = null; | ||
let count = 0; | ||
let adventures: Adventure[] = []; | ||
let initialFetch = await fetch(`${serverEndpoint}/api/collections/archived/`, { | ||
headers: { | ||
Cookie: `${event.cookies.get('auth')}` | ||
} | ||
}); | ||
if (!initialFetch.ok) { | ||
console.error('Failed to fetch visited adventures'); | ||
return redirect(302, '/login'); | ||
} else { | ||
let res = await initialFetch.json(); | ||
let visited = res as Adventure[]; | ||
adventures = [...adventures, ...visited]; | ||
} | ||
|
||
return { | ||
props: { | ||
adventures | ||
} | ||
}; | ||
} | ||
}) satisfies PageServerLoad; |
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 { enhance, deserialize } from '$app/forms'; | ||
import AdventureCard from '$lib/components/AdventureCard.svelte'; | ||
import CollectionCard from '$lib/components/CollectionCard.svelte'; | ||
import EditAdventure from '$lib/components/EditAdventure.svelte'; | ||
import EditCollection from '$lib/components/EditCollection.svelte'; | ||
import NewAdventure from '$lib/components/NewAdventure.svelte'; | ||
import NewCollection from '$lib/components/NewCollection.svelte'; | ||
import NotFound from '$lib/components/NotFound.svelte'; | ||
import type { Adventure, Collection } from '$lib/types'; | ||
import Plus from '~icons/mdi/plus'; | ||
export let data: any; | ||
console.log(data); | ||
let collections: Collection[] = data.props.adventures || []; | ||
function deleteCollection(event: CustomEvent<number>) { | ||
collections = collections.filter((collection) => collection.id !== event.detail); | ||
} | ||
</script> | ||
|
||
<div class="drawer lg:drawer-open"> | ||
<div class="drawer-content"> | ||
<!-- Page content --> | ||
<h1 class="text-center font-bold text-4xl mb-6">Archived Collections</h1> | ||
{#if collections.length === 0} | ||
<NotFound error={undefined} /> | ||
{/if} | ||
<div class="p-4"> | ||
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center"> | ||
{#each collections as collection} | ||
<CollectionCard type="" {collection} on:delete={deleteCollection} /> | ||
{/each} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<svelte:head> | ||
<title>Collections</title> | ||
<meta name="description" content="View your adventure collections." /> | ||
</svelte:head> |