|
12 | 12 | import { page } from '$app/stores';
|
13 | 13 | import { goto, invalidateAll } from '$app/navigation';
|
14 | 14 | import FeedsSelect from './FeedsSelect.svelte';
|
| 15 | + import { Input } from './ui/input'; |
15 | 16 |
|
16 | 17 | export let data: { feeds: Feed[]; items: { total: number; data: Item[] } };
|
17 | 18 | let filter = parseURLtoFilter($page.url.searchParams);
|
|
73 | 74 | toast.error((e as Error).message);
|
74 | 75 | }
|
75 | 76 | }
|
| 77 | + function debounce(func: Function, wait: number): EventListener { |
| 78 | + let timeout: ReturnType<typeof setTimeout>; |
| 79 | +
|
| 80 | + return function (this: HTMLElement, event: Event) { |
| 81 | + const context = this; |
| 82 | +
|
| 83 | + const later = () => { |
| 84 | + func.apply(context, event); |
| 85 | + }; |
| 86 | +
|
| 87 | + clearTimeout(timeout); |
| 88 | + timeout = setTimeout(later, wait); |
| 89 | + }; |
| 90 | + } |
| 91 | +
|
| 92 | + const handleSearchInput = debounce(function (e: Event) { |
| 93 | + if (e.target instanceof HTMLInputElement) { |
| 94 | + filter.keyword = e.target.value; |
| 95 | + } |
| 96 | + }, 1000); |
76 | 97 |
|
77 | 98 | function fromNow(d: Date) {
|
78 | 99 | d = new Date(d);
|
|
91 | 112 | ];
|
92 | 113 | </script>
|
93 | 114 |
|
94 |
| -<div class="flex justify-between items-center w-full"> |
95 |
| - <FeedsSelect data={data.feeds} bind:selected={selectedFeed} /> |
| 115 | +<div class="flex flex-col md:flex-row md:justify-between md:items-center w-full gap-2"> |
| 116 | + <div class="flex flex-col md:flex-row gap-2"> |
| 117 | + <FeedsSelect data={data.feeds} bind:selected={selectedFeed} className="w-full md:w-[200px]" /> |
| 118 | + <Input |
| 119 | + type="text" |
| 120 | + placeholder="Search in title and content..." |
| 121 | + class="w-full md:w-[400px]" |
| 122 | + on:input={handleSearchInput} |
| 123 | + /> |
| 124 | + </div> |
96 | 125 |
|
97 | 126 | {#if data.items.data.length > 0}
|
98 | 127 | <div>
|
99 | 128 | {#each actions as action}
|
100 | 129 | <Tooltip.Root>
|
101 | 130 | <Tooltip.Trigger asChild let:builder>
|
102 |
| - <Button builders={[builder]} on:click={action.handler} variant="outline" size="icon"> |
| 131 | + <Button |
| 132 | + builders={[builder]} |
| 133 | + on:click={action.handler} |
| 134 | + variant="outline" |
| 135 | + size="icon" |
| 136 | + class="w-full md:w-[40px]" |
| 137 | + > |
103 | 138 | <svelte:component this={action.icon} size="20" />
|
| 139 | + <span class="ml-1 md:hidden">{action.tooltip}</span> |
104 | 140 | </Button>
|
105 | 141 | </Tooltip.Trigger>
|
106 | 142 | <Tooltip.Content>
|
|
0 commit comments