|
11 | 11 | import { CheckCheckIcon, type Icon } from 'lucide-svelte';
|
12 | 12 | import { page } from '$app/stores';
|
13 | 13 | import { goto, invalidateAll } from '$app/navigation';
|
| 14 | + import FeedsSelect from './FeedsSelect.svelte'; |
14 | 15 |
|
15 | 16 | export let data: { feeds: Feed[]; items: { total: number; data: Item[] } };
|
16 | 17 | let filter = parseURLtoFilter($page.url.searchParams);
|
17 | 18 |
|
18 |
| - type feedOption = { label: string; value: number }; |
19 |
| - const defaultSelectedFeed: feedOption = { value: -1, label: 'All Feeds' }; |
20 |
| - let allFeeds = data.feeds |
21 |
| - .map((f) => { |
22 |
| - return { value: f.id, label: f.name }; |
23 |
| - }) |
24 |
| - .concat(defaultSelectedFeed) |
25 |
| - .sort((a, b) => a.value - b.value); |
26 |
| -
|
27 | 19 | // NOTE: Svelte treats object as dirty, it may cause poorly reactive updates
|
28 | 20 | // when using it in two-way binding.
|
29 | 21 | // Therefore, we create an oldFilter as a control. Update url search params
|
|
33 | 25 |
|
34 | 26 | let oldFilter = Object.assign({}, filter);
|
35 | 27 |
|
36 |
| - let selectedFeed = allFeeds.find((v) => v.value === filter?.feed_id) || defaultSelectedFeed; |
| 28 | + let selectedFeed = filter?.feed_id ?? -1; |
37 | 29 | $: updateSelectedFeed(selectedFeed);
|
38 |
| - function updateSelectedFeed(f: feedOption) { |
39 |
| - if (f.value == filter.feed_id) return; |
40 |
| - filter.feed_id = f.value !== -1 ? f.value : undefined; |
| 30 | + function updateSelectedFeed(id: number) { |
| 31 | + if (id == filter.feed_id) return; |
| 32 | + filter.feed_id = id !== -1 ? id : undefined; |
41 | 33 | filter.page = 1;
|
42 | 34 | console.log(filter);
|
43 | 35 | }
|
|
100 | 92 | </script>
|
101 | 93 |
|
102 | 94 | <div class="flex justify-between items-center w-full">
|
103 |
| - <Select.Root items={allFeeds} bind:selected={selectedFeed}> |
104 |
| - <!-- FIX: auto width --> |
105 |
| - <!-- TODO: show relevant feeds only (api) --> |
106 |
| - <Select.Trigger class="w-[180px]"> |
107 |
| - <Select.Value placeholder="Filter by Feed" /> |
108 |
| - </Select.Trigger> |
109 |
| - <Select.Content class="max-h-[200px] overflow-y-scroll"> |
110 |
| - {#each allFeeds as feed} |
111 |
| - <Select.Item value={feed.value} class="truncate">{feed.label}</Select.Item> |
112 |
| - {/each} |
113 |
| - </Select.Content> |
114 |
| - </Select.Root> |
| 95 | + <FeedsSelect data={data.feeds} bind:selected={selectedFeed} /> |
115 | 96 |
|
116 | 97 | {#if data.items.data.length > 0}
|
117 | 98 | <div>
|
|
0 commit comments