|
1 | 1 | <script lang="ts">
|
2 |
| - import RestrictionRow from '$lib/RestrictionRow.svelte'; |
| 2 | + import RestrictionRow from './RestrictionRow.svelte'; |
| 3 | + import { restrictionFilters } from '$lib/state.svelte'; |
3 | 4 |
|
4 | 5 | const { data } = $props();
|
5 | 6 |
|
|
12 | 13 | map.set(airport, []);
|
13 | 14 | }
|
14 | 15 |
|
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 | + } |
16 | 28 | });
|
17 | 29 |
|
18 | 30 | return map;
|
19 | 31 | });
|
| 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 | + } |
20 | 50 | </script>
|
21 | 51 |
|
22 | 52 | <svelte:head>
|
23 | 53 | <title>ICCT - Restrictions</title>
|
24 | 54 | </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> |
26 | 63 | <div class="w-full">
|
27 | 64 | {#each restrictions as [airport, r]}
|
28 | 65 | <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> |
30 | 67 | <div class="flex-grow flex flex-col">
|
31 | 68 | <div class="flex border-b border-b-zinc-400 font-medium">
|
32 | 69 | <div class="w-5/12">Route</div>
|
|
0 commit comments