Skip to content

Commit 61114bd

Browse files
committed
Update rough filtering logic
1 parent 78d0758 commit 61114bd

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

src/ambient.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type RestrictionFilters = {
2+
areas: string[];
3+
};

src/lib/state.svelte.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const restrictionFilters: RestrictionFilters = $state({
2+
areas: []
3+
});

src/routes/api/restrictions/+server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { restriction } from '$lib/server/db/schema';
33
import { json } from '@sveltejs/kit';
44

55
export async function GET() {
6-
const restrictions = await db.select().from(restriction);
6+
const restrictions = await db.select().from(restriction).orderBy(restriction.airport, 'asc');
77

88
return json(restrictions);
99
}

src/routes/restrictions/+page.svelte

+41-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
2-
import RestrictionRow from '$lib/RestrictionRow.svelte';
2+
import RestrictionRow from './RestrictionRow.svelte';
3+
import { restrictionFilters } from '$lib/state.svelte';
34
45
const { data } = $props();
56
@@ -12,21 +13,57 @@
1213
map.set(airport, []);
1314
}
1415
15-
map.get(airport).push(restriction);
16+
if (restrictionFilters.areas.length === 0
17+
|| (restrictionFilters.areas.includes(restriction.to)
18+
|| restrictionFilters.areas.includes(restriction.from))) {
19+
map.get(airport).push(restriction);
20+
}
21+
});
22+
23+
// Filter out any airports with no restrictions
24+
map.forEach((restrictions, airport) => {
25+
if (restrictions.length === 0) {
26+
map.delete(airport);
27+
}
1628
});
1729
1830
return map;
1931
});
32+
33+
const areas = [
34+
'Area 1',
35+
'Area 2',
36+
'Area 3',
37+
'Area 4',
38+
'Area 5',
39+
'Area 6',
40+
'Area 7'
41+
];
42+
43+
function toggleAreaFilter(area: string) {
44+
if (restrictionFilters.areas.includes(area)) {
45+
restrictionFilters.areas = restrictionFilters.areas.filter(a => a !== area);
46+
} else {
47+
restrictionFilters.areas.push(area);
48+
}
49+
}
2050
</script>
2151

2252
<svelte:head>
2353
<title>ICCT - Restrictions</title>
2454
</svelte:head>
25-
55+
<h2>Filters</h2>
56+
<div class="flex gap-2">
57+
{#each areas.filter((a) => a && a.includes('Area')) as area}
58+
<button class="px-2 py-1 rounded-md border border-b-zinc-200"
59+
class:bg-zinc-200={restrictionFilters.areas.includes(area)}
60+
onclick="{() => toggleAreaFilter(area)}">{area}</button>
61+
{/each}
62+
</div>
2663
<div class="w-full">
2764
{#each restrictions as [airport, r]}
2865
<div class="w-full flex mb-2 p-2">
29-
<div class="text-left mr-4 font-medium border rounded-md p-2 bg-gray-700 text-white">{airport}</div>
66+
<div class="w-32 text-left mr-4 font-medium border rounded-md p-2 bg-gray-700 text-white">{airport}</div>
3067
<div class="flex-grow flex flex-col">
3168
<div class="flex border-b border-b-zinc-400 font-medium">
3269
<div class="w-5/12">Route</div>

src/lib/RestrictionRow.svelte src/routes/restrictions/RestrictionRow.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { restriction }: { restriction: any} = $props()
33
</script>
44

5-
<div class="flex border-b border-b-zinc-200 last:border-0">
5+
<div class="flex border-b border-b-zinc-200 last:border-0 text-sm">
66
<div class="w-5/12">{restriction.route}</div>
77
<div class="w-1/12">{restriction.from}</div>
88
<div class="w-1/12">{restriction.to}</div>

0 commit comments

Comments
 (0)