mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 14:59:36 +02:00
Fetch and display categories in CategoryFilterDropdown; update adventure details to include category information
This commit is contained in:
parent
42f07dc2fb
commit
129c76078e
4 changed files with 33 additions and 12 deletions
|
@ -1,13 +1,17 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ADVENTURE_TYPES } from '$lib';
|
import type { Category } from '$lib/types';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
|
||||||
let types_arr: string[] = [];
|
let types_arr: string[] = [];
|
||||||
export let types: string;
|
export let types: string;
|
||||||
|
let adventure_types: Category[] = [];
|
||||||
|
|
||||||
onMount(() => {
|
onMount(async () => {
|
||||||
console.log(types);
|
let categoryFetch = await fetch('/api/categories/categories');
|
||||||
|
let categoryData = await categoryFetch.json();
|
||||||
|
adventure_types = categoryData;
|
||||||
|
console.log(categoryData);
|
||||||
types_arr = types.split(',');
|
types_arr = types.split(',');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -17,12 +21,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleSelect(type: string) {
|
function toggleSelect(type: string) {
|
||||||
if (types_arr.includes(type)) {
|
if (types_arr.indexOf(type) > -1) {
|
||||||
types_arr = types_arr.filter((t) => t !== type);
|
types_arr = types_arr.filter((item) => item !== type);
|
||||||
} else {
|
} else {
|
||||||
types_arr.push(type);
|
types_arr.push(type);
|
||||||
}
|
}
|
||||||
|
types_arr = types_arr.filter((item) => item !== '');
|
||||||
|
// turn types_arr into a comma seperated list with no spaces
|
||||||
types = types_arr.join(',');
|
types = types_arr.join(',');
|
||||||
|
|
||||||
console.log(types);
|
console.log(types);
|
||||||
console.log(types_arr);
|
console.log(types_arr);
|
||||||
}
|
}
|
||||||
|
@ -37,16 +44,16 @@
|
||||||
<button class="btn btn-wide btn-neutral-300" on:click={clearTypes}
|
<button class="btn btn-wide btn-neutral-300" on:click={clearTypes}
|
||||||
>{$t(`adventures.clear`)}</button
|
>{$t(`adventures.clear`)}</button
|
||||||
>
|
>
|
||||||
{#each ADVENTURE_TYPES as type}
|
{#each adventure_types as type}
|
||||||
<li>
|
<li>
|
||||||
<label class="cursor-pointer">
|
<label class="cursor-pointer">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
value={type.label}
|
value={type.name}
|
||||||
on:change={() => toggleSelect(type.type)}
|
on:change={() => toggleSelect(type.name)}
|
||||||
checked={types.indexOf(type.type) > -1}
|
checked={types.indexOf(type.name) > -1}
|
||||||
/>
|
/>
|
||||||
<span>{$t(`adventures.activities.${type.type}`)}</span>
|
<span>{type.display_name + ' ' + type.icon}</span>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -187,3 +187,11 @@ export type ReverseGeocode = {
|
||||||
is_visited: boolean;
|
is_visited: boolean;
|
||||||
display_name: string;
|
display_name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Category = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
display_name: string;
|
||||||
|
icon: string;
|
||||||
|
user_id: number;
|
||||||
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import AdventureModal from '$lib/components/AdventureModal.svelte';
|
import AdventureModal from '$lib/components/AdventureModal.svelte';
|
||||||
import CategoryFilterDropdown from '$lib/components/CategoryFilterDropdown.svelte';
|
import CategoryFilterDropdown from '$lib/components/CategoryFilterDropdown.svelte';
|
||||||
import NotFound from '$lib/components/NotFound.svelte';
|
import NotFound from '$lib/components/NotFound.svelte';
|
||||||
import type { Adventure } from '$lib/types';
|
import type { Adventure, Category } from '$lib/types';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
|
||||||
import Plus from '~icons/mdi/plus';
|
import Plus from '~icons/mdi/plus';
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
let adventures: Adventure[] = data.props.adventures || [];
|
let adventures: Adventure[] = data.props.adventures || [];
|
||||||
|
let categories: Category[] = data.props.categories || [];
|
||||||
|
|
||||||
let currentSort = {
|
let currentSort = {
|
||||||
order_by: '',
|
order_by: '',
|
||||||
|
@ -35,10 +36,15 @@
|
||||||
let typeString: string = '';
|
let typeString: string = '';
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
|
console.log(typeString);
|
||||||
if (typeof window !== 'undefined' && typeString) {
|
if (typeof window !== 'undefined' && typeString) {
|
||||||
let url = new URL(window.location.href);
|
let url = new URL(window.location.href);
|
||||||
url.searchParams.set('types', typeString);
|
url.searchParams.set('types', typeString);
|
||||||
goto(url.toString(), { invalidateAll: true, replaceState: true });
|
goto(url.toString(), { invalidateAll: true, replaceState: true });
|
||||||
|
} else if (typeof window !== 'undefined' && !typeString) {
|
||||||
|
let url = new URL(window.location.href);
|
||||||
|
url.searchParams.set('types', 'all');
|
||||||
|
goto(url.toString(), { invalidateAll: true, replaceState: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@
|
||||||
<div>
|
<div>
|
||||||
<p class="text-sm text-muted-foreground">{$t('adventures.adventure_type')}</p>
|
<p class="text-sm text-muted-foreground">{$t('adventures.adventure_type')}</p>
|
||||||
<p class="text-base font-medium">
|
<p class="text-base font-medium">
|
||||||
{$t(`adventures.activities.${adventure.type}`)}
|
{`${adventure.category.display_name} ${adventure.category.icon}`}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{#if data.props.collection}
|
{#if data.props.collection}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue