|
23 | 23 | import * as Alert from '$lib/components/ui/alert'; |
24 | 24 | import {pt} from '$lib/views/view-text'; |
25 | 25 | import {useViewService} from '$lib/views/view-service.svelte'; |
| 26 | + import {useProjectStorage} from '$lib/storage/project-storage.svelte'; |
| 27 | +
|
| 28 | + type DictionaryPreviewMode = 'show' | 'hide' | 'sticky'; |
26 | 29 |
|
27 | 30 | const writingSystemService = useWritingSystemService(); |
28 | 31 | const eventBus = useProjectEventBus(); |
29 | 32 | const miniLcmApi = useMiniLcmApi(); |
30 | 33 | const features = useFeatures(); |
31 | 34 | const viewService = useViewService(); |
| 35 | + const dictionaryPreviewStorage = useProjectStorage().dictionaryPreview; |
32 | 36 | const { |
33 | 37 | entryId, |
34 | 38 | onClose, |
|
88 | 92 | let entry = $derived(entryResource.current ?? undefined); |
89 | 93 | const headword = $derived((entry && writingSystemService.headword(entry)) || $t`Untitled`); |
90 | 94 | const loadingDebounced = new Debounced(() => entryResource.loading, 50); |
91 | | - let dictionaryPreview: 'show' | 'hide' | 'sticky' = $state('show'); |
92 | | - const sticky = $derived.by(() => dictionaryPreview === 'sticky'); |
| 95 | + const dictionaryPreview: DictionaryPreviewMode = $derived( |
| 96 | + isDictionaryPreviewMode(dictionaryPreviewStorage.current) ? dictionaryPreviewStorage.current : 'show' |
| 97 | + ); |
| 98 | + function isDictionaryPreviewMode(value: string): value is DictionaryPreviewMode { |
| 99 | + return value === 'show' || value === 'hide' || value === 'sticky'; |
| 100 | + } |
| 101 | + const sticky = $derived(dictionaryPreview === 'sticky'); |
93 | 102 |
|
94 | 103 | let readonly = $state(false); |
95 | 104 | let deleted = $state(false); |
|
107 | 116 | <div class="md:pb-4"> |
108 | 117 | <DictionaryEntry {entry} showLinks class={cn('rounded bg-muted/80 dark:bg-muted/50 p-4')}> |
109 | 118 | {#snippet actions()} |
110 | | - <Toggle bind:pressed={() => sticky, (value) => dictionaryPreview = value ? 'sticky' : 'show'} |
| 119 | + <Toggle bind:pressed={() => sticky, (value) => void dictionaryPreviewStorage.set(value ? 'sticky' : 'show')} |
111 | 120 | aria-label={$t`Toggle pinned`} class="aspect-square" size="sm"> |
112 | 121 | <Icon icon="i-mdi-pin-outline" class="size-5" /> |
113 | 122 | </Toggle> |
|
125 | 134 | {/if} |
126 | 135 | <h2 class="ml-4 text-2xl font-semibold mb-2 inline">{headword}</h2> |
127 | 136 | <div class="flex"> |
128 | | - <ViewPicker bind:dictionaryPreview bind:readonly /> |
| 137 | + <ViewPicker bind:dictionaryPreview={() => dictionaryPreview, (v) => void dictionaryPreviewStorage.set(v)} bind:readonly /> |
129 | 138 | <EntryMenu {entry} /> |
130 | 139 | </div> |
131 | 140 | </div> |
|
0 commit comments