Skip to content

Commit

Permalink
Add expand all & collapse all buttons (#358)
Browse files Browse the repository at this point in the history
* add expand all & collapse all buttons

* i forgor 💀

* accidentally removed this👎

* show total weight in profile selector

* remembered to format this time 🙏

* pov me when i forget git checkout

* Change key name as the required space was confusing

---------

Co-authored-by: Kaeso <[email protected]>
  • Loading branch information
Not-a-cowfr and ptlthg authored Jan 16, 2025
1 parent 8c4a907 commit eef4ec3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/routes/@[id=id]/[[profile]]/contests/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@
import type { PageData } from './$types';
import * as Accordion from '$ui/accordion';
import { Switch } from '$ui/switch';
import { Button } from '$ui/button';
let timeType = $state(false);
let accordionValues = $state<string[]>([]);
function expandAll() {
accordionValues = Object.keys(data.years ?? {}).map((year) => `year-${year}`);
}
function collapseAll() {
accordionValues = [];
}
interface Props {
data: PageData;
Expand Down Expand Up @@ -41,9 +51,14 @@
</div>
</div>

<Accordion.Root type="multiple" class="mx-4 w-full max-w-6xl items-center">
<div class="mb-4 flex gap-4">
<Button onclick={expandAll}>Expand All</Button>
<Button onclick={collapseAll}>Collapse All</Button>
</div>

<Accordion.Root type="multiple" class="mx-4 w-full max-w-6xl items-center" value={accordionValues}>
{#each Object.entries(data.years ?? {}).sort((a, b) => +b[0] - +a[0]) as [year, conts] (year)}
<Accordion.Item value="{year} ">
<Accordion.Item value="year-{year}">
<Accordion.Trigger class="flex justify-center hover:no-underline">
<div class="mr-4 flex flex-col items-center justify-center gap-2">
<div class="flex w-full flex-row items-center justify-between">
Expand All @@ -70,7 +85,7 @@

<Accordion.Content>
<div class="flex flex-wrap justify-center gap-4">
{#each conts ?? [] as contest (`${contest.timestamp ?? 0}${contest?.crop ?? 0}`)}
{#each conts ?? [] as contest}
<div class="basis-64">
<Contest {contest} irlTime={timeType} />
</div>
Expand Down

0 comments on commit eef4ec3

Please sign in to comment.