diff --git a/frontend/src/lib/components/CategoryFilterDropdown.svelte b/frontend/src/lib/components/CategoryFilterDropdown.svelte new file mode 100644 index 0000000..1d7c40b --- /dev/null +++ b/frontend/src/lib/components/CategoryFilterDropdown.svelte @@ -0,0 +1,50 @@ + + +
+ +
Category Filter
+
+ + {#each ADVENTURE_TYPES as type} + +
  • + +
  • + {/each} +
    +
    diff --git a/frontend/src/routes/adventures/+page.server.ts b/frontend/src/routes/adventures/+page.server.ts index a8b097f..25be557 100644 --- a/frontend/src/routes/adventures/+page.server.ts +++ b/frontend/src/routes/adventures/+page.server.ts @@ -16,12 +16,12 @@ export const load = (async (event) => { let count = 0; let adventures: Adventure[] = []; - // const visited = event.url.searchParams.get('visited'); - // const planned = event.url.searchParams.get('planned'); + let typeString = event.url.searchParams.get('types'); - let typeString: string = 'all'; - - // *** FOR NOW TYPESTRING IS ALWAYS 'ALL' BECAUSE WE DON'T HAVE A WAY TO FILTER BY VISITED/PLANNED YET *** + // If no type is specified, default to 'all' + if (!typeString) { + typeString = 'all'; + } const include_collections = event.url.searchParams.get('include_collections') || 'false'; const order_by = event.url.searchParams.get('order_by') || 'updated_at'; diff --git a/frontend/src/routes/adventures/+page.svelte b/frontend/src/routes/adventures/+page.svelte index 100db4e..2e6c270 100644 --- a/frontend/src/routes/adventures/+page.svelte +++ b/frontend/src/routes/adventures/+page.svelte @@ -4,6 +4,7 @@ import { page } from '$app/stores'; import AdventureCard from '$lib/components/AdventureCard.svelte'; import AdventureModal from '$lib/components/AdventureModal.svelte'; + import CategoryFilterDropdown from '$lib/components/CategoryFilterDropdown.svelte'; import NotFound from '$lib/components/NotFound.svelte'; import type { Adventure } from '$lib/types'; @@ -28,6 +29,28 @@ let totalPages = Math.ceil(count / resultsPerPage); let currentPage: number = 1; + let typeString: string = ''; + + $: { + if (typeof window !== 'undefined') { + let url = new URL(window.location.href); + url.searchParams.set('types', typeString); + goto(url.toString(), { invalidateAll: true, replaceState: true }); + } + } + + // sets typeString if present in the URL + $: { + // check to make sure its running on the client side + if (typeof window !== 'undefined') { + let url = new URL(window.location.href); + let types = url.searchParams.get('types'); + if (types) { + typeString = types; + } + } + } + function handleChangePage(pageNumber: number) { // let query = new URLSearchParams($page.url.searchParams.toString()); @@ -218,27 +241,8 @@
    - - + +

    Sort

    Order Direction