Skip to content

Commit

Permalink
refactor(store): encapsulate current file retrieval logic for improve…
Browse files Browse the repository at this point in the history
…d clarity
  • Loading branch information
purocean committed Jan 8, 2025
1 parent 2d66acb commit 0e5d1e3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/renderer/support/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import type { Components, Doc, FileSort, IndexStatus, Repo } from '@fe/types'
import { computed, reactive, watch, watchEffect } from 'vue'
import { isNormalRepoName } from '@share/misc'

function getCurrentFile () {
const data = storage.get<Doc>('currentFile')

if (data && data.type) {
return data
}

return null
}

export const initState = {
tree: null as Components.Tree.Node[] | null,
treeSort: storage.get<FileSort>('treeSort', { by: 'serial', order: 'asc' }),
Expand All @@ -25,7 +35,7 @@ export const initState = {
inComposition: false,
currentRepo: storage.get<Repo>('currentRepo'),
currentRepoIndexStatus: null as { repo: string, status: IndexStatus} | null,
currentFile: storage.get<Repo>('currentFile') as Doc | null | undefined,
currentFile: getCurrentFile() as Doc | null | undefined,
recentOpenTime: storage.get<Record<string, number>>('recentOpenTime', {}),
tabs: storage.get<Components.FileTabs.Item[]>('tabs', []),
previewer: 'default',
Expand Down

0 comments on commit 0e5d1e3

Please sign in to comment.