feat: dynamic routing for patches (#54)

* feat: dynamic routing for patches

* add all packages button on desktop

Co-authored-by: afn <hey@afn.lol>
This commit is contained in:
Ax333l 2023-01-02 13:39:33 +01:00 committed by GitHub
parent d0d2e3f412
commit e1b8445b59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 24 deletions

View File

@ -1,4 +0,0 @@
import { patches } from '$data/api';
import type { PageLoad } from './$types';
export const load: PageLoad = patches.page_load_impl();

View File

@ -1,14 +1,16 @@
<script lang="ts"> <script lang="ts">
export let selectedPkg: string | boolean; import { goto } from '$app/navigation';
export let selectedPkg: string | undefined;
export let name: string; export let name: string;
function handleClick() { function handleClick() {
// Assign the selected package, if already selected, make it false // Assign the selected package. If it's already selected, deselect it.
if (selectedPkg === name || name === 'All packages') { let path = '/patches';
selectedPkg = false; if (selectedPkg !== name && name !== 'All packages') {
} else { path += `/${name}`;
selectedPkg = name;
} }
goto(path);
window.scrollTo({ top: 0, behavior: 'smooth' }); window.scrollTo({ top: 0, behavior: 'smooth' });
} }
</script> </script>

View File

@ -2,13 +2,14 @@
import { fly } from 'svelte/transition'; import { fly } from 'svelte/transition';
import { quintOut } from 'svelte/easing'; import { quintOut } from 'svelte/easing';
import type { PageData } from './$types';
import type { Patch } from '$lib/types'; import type { Patch } from '$lib/types';
import { patches as api_patches } from '$data/api'; import { patches as api_patches } from '$data/api';
import Meta from '$lib/components/Meta.svelte'; import Meta from '$lib/components/Meta.svelte';
import PackageMenu from './PackageMenu.svelte'; import PackageMenu from '../PackageMenu.svelte';
import Package from './Package.svelte'; import Package from '../Package.svelte';
import PatchItem from './PatchItem.svelte'; import PatchItem from '../PatchItem.svelte';
import Footer from '$layout/Footer.svelte'; import Footer from '$layout/Footer.svelte';
import Search from '$lib/components/Search.svelte'; import Search from '$lib/components/Search.svelte';
import FilterChip from '$lib/components/FilterChip.svelte'; import FilterChip from '$lib/components/FilterChip.svelte';
@ -16,25 +17,27 @@
$: ({ patches, packages } = $api_patches); $: ({ patches, packages } = $api_patches);
let selectedPkg: boolean = false; export let data: PageData;
$: ({ selectedPkg } = data);
let searchTerm: string; let searchTerm: string;
let searchTermFiltered: string; let searchTermFiltered: string;
let timeout: any = null; let timeout: any = null;
let mobilePackages = false; let mobilePackages = false;
function filterByPackage(selectedPkg: string | boolean, packageList: any) { function filterByPackage(pkg: string | undefined, packageList: any) {
for (let i = 0; i < packageList.length; i++) { for (let i = 0; i < packageList.length; i++) {
if (packageList[i].name === selectedPkg) { if (packageList[i].name === pkg) {
return true; return true;
} }
} }
} }
function search(patch: Patch) { function search(patch: Patch) {
function checkPkgName(selectedPkg: string | boolean, packageList: any) { function checkPkgName(pkg: string | undefined, packageList: any) {
// Basically the same function as before lol // Basically the same function as before lol
for (let i = 0; i < packageList.length; i++) { for (let i = 0; i < packageList.length; i++) {
if (packageList[i].name.replace(/\./g, '').includes(selectedPkg)) { if (packageList[i].name.replace(/\./g, '').includes(pkg)) {
return true; return true;
} }
} }
@ -77,8 +80,12 @@
</div> </div>
<main> <main>
<div class="filter-chips" in:fly={{ y: 10, easing: quintOut, duration: 750 }}> <div class="filter-chips" in:fly={{ y: 10, easing: quintOut, duration: 750 }}>
<FilterChip selected={selectedPkg} dropdown on:click={() => (mobilePackages = !mobilePackages)}> <FilterChip
{selectedPkg ? selectedPkg : 'Packages'} selected={!!selectedPkg}
dropdown
on:click={() => (mobilePackages = !mobilePackages)}
>
{selectedPkg || 'Packages'}
</FilterChip> </FilterChip>
<!-- <FilterChip check>Universal</FilterChip> <!-- <FilterChip check>Universal</FilterChip>
<FilterChip>Patch options</FilterChip> --> <FilterChip>Patch options</FilterChip> -->
@ -92,14 +99,14 @@
on:click={() => (mobilePackages = !mobilePackages)} on:click={() => (mobilePackages = !mobilePackages)}
on:keypress={() => (mobilePackages = !mobilePackages)} on:keypress={() => (mobilePackages = !mobilePackages)}
> >
<Package bind:selectedPkg name="All packages" /> <Package {selectedPkg} name="All packages" />
</span> </span>
{#each packages as pkg} {#each packages as pkg}
<span <span
on:click={() => (mobilePackages = !mobilePackages)} on:click={() => (mobilePackages = !mobilePackages)}
on:keypress={() => (mobilePackages = !mobilePackages)} on:keypress={() => (mobilePackages = !mobilePackages)}
> >
<Package bind:selectedPkg name={pkg} /> <Package {selectedPkg} name={pkg} />
</span> </span>
{/each} {/each}
</div> </div>
@ -109,8 +116,9 @@
<aside in:fly={{ y: 10, easing: quintOut, duration: 750 }}> <aside in:fly={{ y: 10, easing: quintOut, duration: 750 }}>
<PackageMenu> <PackageMenu>
<span class="packages"> <span class="packages">
<Package {selectedPkg} name="All packages" />
{#each packages as pkg} {#each packages as pkg}
<Package bind:selectedPkg name={pkg} /> <Package {selectedPkg} name={pkg} />
{/each} {/each}
</span> </span>
</PackageMenu> </PackageMenu>
@ -152,7 +160,7 @@
.search-contain { .search-contain {
width: min(90%, 80rem); width: min(90%, 80rem);
margin-inline: auto;; margin-inline: auto;
} }
.patches-container { .patches-container {

View File

@ -0,0 +1,10 @@
import { patches } from '$data/api';
import type { PageLoad } from './$types';
const api = patches.page_load_impl();
export const load: PageLoad = async ({ params, fetch }) => {
const selectedPkg = params.package || undefined;
await api({ fetch });
return { selectedPkg };
};

1
static/_redirects Normal file
View File

@ -0,0 +1 @@
/patches/* /404.html 200