|
1 | 1 | <script lang="ts"> |
2 | | - import { getPreferences, getWikiOrder } from "$ctx"; |
| 2 | + import { getPreferences } from "$ctx"; |
3 | 3 | import { SettingsTab } from "$lib/components/header/types"; |
4 | | - import { sections } from "$lib/sections/constants"; |
5 | 4 | import { cn, flyAndScale } from "$lib/shared/utils"; |
6 | | - import { Feedback } from "@dnd-kit/dom"; |
7 | | - import { OptimisticSortingPlugin, SortableKeyboardPlugin } from "@dnd-kit/dom/sortable"; |
8 | | - import { move } from "@dnd-kit/helpers"; |
9 | | - import type { DragDropEventHandlers } from "@dnd-kit/svelte"; |
10 | | - import { DragDropProvider } from "@dnd-kit/svelte"; |
11 | | - import { createSortable } from "@dnd-kit/svelte/sortable"; |
12 | | - import BookOpenText from "@lucide/svelte/icons/book-open-text"; |
13 | 5 | import CircleQuestionMark from "@lucide/svelte/icons/circle-question-mark"; |
14 | 6 | import Fan from "@lucide/svelte/icons/fan"; |
15 | | - import GripVertical from "@lucide/svelte/icons/grip-vertical"; |
16 | 7 | import Keyboard from "@lucide/svelte/icons/keyboard"; |
17 | 8 | import Pickaxe from "@lucide/svelte/icons/pickaxe"; |
18 | 9 | import Rainbow from "@lucide/svelte/icons/rainbow"; |
19 | 10 | import Settings2 from "@lucide/svelte/icons/settings-2"; |
20 | 11 | import Sparkle from "@lucide/svelte/icons/sparkle"; |
21 | | - import { Button, Separator, Tabs, Tooltip } from "bits-ui"; |
| 12 | + import { Button, Tabs, Tooltip } from "bits-ui"; |
22 | 13 | import SettingToggleRow from "./SettingToggleRow.svelte"; |
23 | 14 |
|
24 | 15 | const preferences = getPreferences(); |
25 | | - const wikiOrderContext = getWikiOrder(); |
26 | | - type WikiSource = (typeof wikiOrderContext.current)[number]; |
27 | | - type SortableItem = ReturnType<typeof createSortable>; |
28 | 16 |
|
29 | 17 | let isListening = $state(false); |
30 | | - let wikiOrder = $state([...wikiOrderContext.current]); |
31 | | - let providerKey = $state(0); |
32 | | -
|
33 | | - const defaultSectionOrder = sections; |
34 | | - const differsFromDefault = $derived(JSON.stringify(preferences.sectionOrder) !== JSON.stringify(defaultSectionOrder)); |
35 | 18 |
|
36 | 19 | function handleKeybindKeydown(e: KeyboardEvent) { |
37 | 20 | if (isListening) { |
|
56 | 39 | } |
57 | 40 | }, 5000); |
58 | 41 | } |
59 | | -
|
60 | | - function onDragEnd(event: Parameters<NonNullable<DragDropEventHandlers["onDragEnd"]>>[0]) { |
61 | | - wikiOrder = move(wikiOrder, event); |
62 | | - wikiOrderContext.current = [...wikiOrder]; |
63 | | - providerKey += 1; |
64 | | - } |
65 | 42 | </script> |
66 | 43 |
|
67 | 44 | <Tabs.Content value={SettingsTab.Misc} class="space-y-6"> |
|
143 | 120 | </Button.Root> |
144 | 121 | </div> |
145 | 122 | </div> |
146 | | - <Separator.Root class="shrink-0 bg-icon/30 data-[orientation=horizontal]:h-0.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-0.5" /> |
147 | | - <div class="space-y-4 rounded-lg bg-text/5 p-4"> |
148 | | - <div class="flex items-start gap-2 rounded-lg p-2 font-semibold"> |
149 | | - <BookOpenText class="size-5 h-lh shrink-0" /> |
150 | | - <div class=""> |
151 | | - <h4>Wiki Order</h4> |
152 | | - <div class="space-y-2"> |
153 | | - <p class="text-text/60">Drag and drop the wiki sources to reorder them as you like.</p> |
154 | | - <p class="text-text/60">If the wiki source isn't available, the next one in the list will be used.</p> |
155 | | - </div> |
156 | | - </div> |
157 | | - </div> |
158 | | - |
159 | | - {#key providerKey} |
160 | | - <DragDropProvider {onDragEnd}> |
161 | | - {#each wikiOrder as wiki, index (wiki.id)} |
162 | | - {@const sortable = createSortable({ |
163 | | - id: wiki.id, |
164 | | - get index() { |
165 | | - return index; |
166 | | - }, |
167 | | - plugins: [SortableKeyboardPlugin, OptimisticSortingPlugin, Feedback.configure({ feedback: "clone" })] |
168 | | - })} |
169 | | - {@render wikiRowContent(wiki, sortable, true)} |
170 | | - {/each} |
171 | | - </DragDropProvider> |
172 | | - {/key} |
173 | | - {#if differsFromDefault} |
174 | | - <Button.Root |
175 | | - class="mt-4 w-full rounded-lg bg-text/65 p-1.5 text-sm font-semibold text-background/80 uppercase transition-colors ease-out hover:bg-text/80" |
176 | | - onclick={() => { |
177 | | - preferences.sectionOrder = defaultSectionOrder; |
178 | | - }}> |
179 | | - Reset to default |
180 | | - </Button.Root> |
181 | | - {/if} |
182 | | - </div> |
183 | 123 | </div> |
184 | 124 | </Tabs.Content> |
185 | | - |
186 | | -{#snippet wikiRowContent(wiki: WikiSource, sortable: SortableItem | null = null, flipEnabled = false)} |
187 | | - <div {@attach sortable?.attach} class="relative flex items-center gap-2 rounded-lg bg-text/5 p-2 font-semibold data-[dragging=true]:animate-pulse data-[dragging=true]:opacity-30 data-[flip=true]:will-change-transform" data-dragging={sortable?.isDropTarget} data-flip={flipEnabled}> |
188 | | - <GripVertical class="size-5 shrink-0 text-text/60" /> |
189 | | - <div class="flex flex-col"> |
190 | | - {wiki.name.replaceAll("_", " ")} |
191 | | - <Button.Root href={wiki.link} target="_blank" class="text-link/60 underline">{new URL(wiki.link).hostname}</Button.Root> |
192 | | - </div> |
193 | | - </div> |
194 | | -{/snippet} |
0 commit comments