-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathuseApp.ts
More file actions
63 lines (54 loc) · 1.84 KB
/
useApp.ts
File metadata and controls
63 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { LibraryFilter } from './types'
import { useCssVar } from '@vueuse/core'
const { store } = window.electron
const selectedLibrary = ref<
(typeof LibraryFilter)[keyof typeof LibraryFilter] | undefined
>(
store.app.get(
'selectedLibrary',
) as (typeof LibraryFilter)[keyof typeof LibraryFilter],
)
const selectedFolderId = ref(store.app.get('selectedFolderId'))
const selectedSnippetId = ref(store.app.get('selectedSnippetId'))
const selectedSnippetIdBeforeSearch = ref(store.app.get('selectedSnippetId'))
const selectedSnippetContentIndex = ref(0)
const highlightedFolderId = ref<number>()
const highlightedSnippetId = ref<number>()
const sidebarWidth = useCssVar('--sidebar-width')
const snippetListWidth = useCssVar('--snippet-list-width')
sidebarWidth.value = `${store.app.get('sidebarWidth')}px`
snippetListWidth.value = `${store.app.get('snippetListWidth')}px`
// TODO: вынести в useFolder
function selectFolder(folderId: number) {
selectedFolderId.value = folderId
selectedLibrary.value = undefined
selectedSnippetContentIndex.value = 0
selectedSnippetIdBeforeSearch.value = undefined
store.app.set('selectedFolderId', folderId)
store.app.delete('selectedLibrary')
}
watch(
[highlightedFolderId, highlightedSnippetId],
([newFolderId, newSnippetId], [oldFolderId, oldSnippetId]) => {
if (newFolderId !== oldFolderId && newFolderId !== undefined) {
highlightedSnippetId.value = undefined
}
if (newSnippetId !== oldSnippetId && newSnippetId !== undefined) {
highlightedFolderId.value = undefined
}
},
)
export function useApp() {
return {
highlightedFolderId,
highlightedSnippetId,
selectedFolderId,
selectedLibrary,
selectedSnippetContentIndex,
selectedSnippetId,
selectedSnippetIdBeforeSearch,
selectFolder,
sidebarWidth,
snippetListWidth,
}
}