-
-
Notifications
You must be signed in to change notification settings - Fork 17
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 #131 from seanmorley15/development
Development
- Loading branch information
Showing
14 changed files
with
407 additions
and
7 deletions.
There are no files selected for viewing
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,91 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
export let activities: string[] | undefined | null; | ||
let allActivities: string[] = []; | ||
let inputVal: string = ''; | ||
if (activities == null || activities == undefined) { | ||
activities = []; | ||
} | ||
onMount(async () => { | ||
let res = await fetch('/api/activity-types/types/'); | ||
let data = await res.json(); | ||
if (data) { | ||
allActivities = data; | ||
} | ||
}); | ||
function addActivity() { | ||
if (inputVal && activities) { | ||
const trimmedInput = inputVal.trim(); | ||
if (trimmedInput && !activities.includes(trimmedInput)) { | ||
activities = [...activities, trimmedInput]; | ||
inputVal = ''; | ||
} | ||
} | ||
} | ||
function removeActivity(item: string) { | ||
if (activities) { | ||
activities = activities.filter((activity) => activity !== item); | ||
} | ||
} | ||
$: filteredItems = allActivities.filter(function (activity) { | ||
return ( | ||
activity.toLowerCase().includes(inputVal.toLowerCase()) && | ||
(!activities || !activities.includes(activity)) | ||
); | ||
}); | ||
</script> | ||
|
||
<div class="relative"> | ||
<input | ||
type="text" | ||
class="input input-bordered w-full" | ||
placeholder="Add an activity" | ||
bind:value={inputVal} | ||
on:keydown={(e) => { | ||
if (e.key === 'Enter') { | ||
e.preventDefault(); | ||
addActivity(); | ||
} | ||
}} | ||
/> | ||
{#if inputVal && filteredItems.length > 0} | ||
<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} | ||
<!-- svelte-ignore a11y-click-events-have-key-events --> | ||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions --> | ||
<li | ||
class="p-2 hover:bg-base-200 cursor-pointer" | ||
on:click={() => { | ||
inputVal = item; | ||
addActivity(); | ||
}} | ||
> | ||
{item} | ||
</li> | ||
{/each} | ||
</ul> | ||
{/if} | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<ul class="space-y-2"> | ||
{#if activities} | ||
{#each activities as activity} | ||
<li class="flex items-center justify-between bg-base-200 p-2 rounded"> | ||
{activity} | ||
<button class="btn btn-sm btn-error" on:click={() => removeActivity(activity)}> | ||
Remove | ||
</button> | ||
</li> | ||
{/each} | ||
{/if} | ||
</ul> | ||
</div> |
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
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,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; |
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,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> --> |
Oops, something went wrong.