mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 15:29:36 +02:00
activity type overhaul
This commit is contained in:
parent
f03c338935
commit
f38062e250
6 changed files with 76 additions and 7 deletions
|
@ -20,8 +20,9 @@
|
||||||
|
|
||||||
function addActivity() {
|
function addActivity() {
|
||||||
if (inputVal && activities) {
|
if (inputVal && activities) {
|
||||||
if (!activities.includes(inputVal) && allActivities.includes(inputVal)) {
|
const trimmedInput = inputVal.trim();
|
||||||
activities = [...activities, inputVal];
|
if (trimmedInput && !activities.includes(trimmedInput)) {
|
||||||
|
activities = [...activities, trimmedInput];
|
||||||
inputVal = '';
|
inputVal = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +57,7 @@
|
||||||
/>
|
/>
|
||||||
{#if inputVal && filteredItems.length > 0}
|
{#if inputVal && filteredItems.length > 0}
|
||||||
<ul class="absolute z-10 w-full bg-base-100 shadow-lg max-h-60 overflow-auto">
|
<ul class="absolute z-10 w-full bg-base-100 shadow-lg max-h-60 overflow-auto">
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
{#each filteredItems as item}
|
{#each filteredItems as item}
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
<p class="text-lg ml-4 font-bold">Hi, {user.first_name} {user.last_name}</p>
|
<p class="text-lg ml-4 font-bold">Hi, {user.first_name} {user.last_name}</p>
|
||||||
<li><button on:click={() => goto('/profile')}>Profile</button></li>
|
<li><button on:click={() => goto('/profile')}>Profile</button></li>
|
||||||
<li><button on:click={() => goto('/adventures')}>My Adventures</button></li>
|
<li><button on:click={() => goto('/adventures')}>My Adventures</button></li>
|
||||||
|
<li><button on:click={() => goto('/activities')}>My Activities</button></li>
|
||||||
<li><button on:click={() => goto('/settings')}>User Settings</button></li>
|
<li><button on:click={() => goto('/settings')}>User Settings</button></li>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<li><button formaction="/?/logout">Logout</button></li>
|
<li><button formaction="/?/logout">Logout</button></li>
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
export let type: string = 'visited';
|
export let type: string = 'visited';
|
||||||
|
|
||||||
import Wikipedia from '~icons/mdi/wikipedia';
|
import Wikipedia from '~icons/mdi/wikipedia';
|
||||||
|
import ClipboardList from '~icons/mdi/clipboard-list';
|
||||||
|
import ActivityComplete from './ActivityComplete.svelte';
|
||||||
|
|
||||||
let newAdventure: Adventure = {
|
let newAdventure: Adventure = {
|
||||||
id: NaN,
|
id: NaN,
|
||||||
|
@ -218,17 +220,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label for="activity_types"
|
<label for="activityTypes"
|
||||||
>Activity Types <iconify-icon icon="mdi:clipboard-list" class="text-xl -mb-1"
|
>Activity Types <ClipboardList class="inline-block -mt-1 mb-1 w-6 h-6" /></label
|
||||||
></iconify-icon></label
|
|
||||||
><br />
|
><br />
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="activity_types"
|
|
||||||
id="activity_types"
|
id="activity_types"
|
||||||
|
name="activity_types"
|
||||||
|
hidden
|
||||||
bind:value={newAdventure.activity_types}
|
bind:value={newAdventure.activity_types}
|
||||||
class="input input-bordered w-full max-w-xs mt-1"
|
class="input input-bordered w-full max-w-xs mt-1"
|
||||||
/>
|
/>
|
||||||
|
<ActivityComplete bind:activities={newAdventure.activity_types} />
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label for="rating"
|
<label for="rating"
|
||||||
|
|
26
frontend/src/routes/activities/+page.server.ts
Normal file
26
frontend/src/routes/activities/+page.server.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
import type { PageServerLoad } from './$types';
|
||||||
|
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||||
|
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||||
|
|
||||||
|
export const load = (async (event) => {
|
||||||
|
if (!event.locals.user) {
|
||||||
|
return redirect(302, '/login');
|
||||||
|
}
|
||||||
|
let allActivities: string[] = [];
|
||||||
|
let res = await fetch(`${endpoint}/api/activity-types/types/`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Cookie: `${event.cookies.get('auth')}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let data = await res.json();
|
||||||
|
if (data) {
|
||||||
|
allActivities = data;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
activities: allActivities
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}) satisfies PageServerLoad;
|
33
frontend/src/routes/activities/+page.svelte
Normal file
33
frontend/src/routes/activities/+page.svelte
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import type { PageData } from './$types';
|
||||||
|
|
||||||
|
export let data: PageData;
|
||||||
|
|
||||||
|
let activities: string[] = data.props.activities;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- make a table with pinned rows -->
|
||||||
|
<table class="table table-compact">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Activity</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each activities as activity}
|
||||||
|
<tr>
|
||||||
|
<td>{activity}</td>
|
||||||
|
<td>
|
||||||
|
<!-- <button
|
||||||
|
class="btn btn-sm btn-error"
|
||||||
|
on:click={() => {
|
||||||
|
activities = activities.filter((a) => a !== activity);
|
||||||
|
}}>Remove</button
|
||||||
|
> -->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<!-- </ul> -->
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
|
function deleteAdventure(event: CustomEvent<number>) {
|
||||||
|
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
|
||||||
|
}
|
||||||
|
|
||||||
console.log(data);
|
console.log(data);
|
||||||
let adventures: Adventure[] = [];
|
let adventures: Adventure[] = [];
|
||||||
if (data.props) {
|
if (data.props) {
|
||||||
|
@ -18,7 +22,7 @@
|
||||||
{:else}
|
{:else}
|
||||||
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
||||||
{#each adventures as adventure}
|
{#each adventures as adventure}
|
||||||
<AdventureCard type={adventure.type} {adventure} />
|
<AdventureCard type={adventure.type} {adventure} on:delete={deleteAdventure} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue