Skip to content

Commit

Permalink
chore(project): bw base data access
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 24, 2021
1 parent 65a823a commit c8572ee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ProjectState } from '@/types/project'
import { useFormat } from '@/use/format'
import { useText } from '../use/text'
import { Entity } from '../types/context'
import isElectron from 'is-electron'
import { useEnv } from '@/use/env'

export const useProjectStore = defineStore('project', {
state: (): ProjectState => {
Expand All @@ -19,6 +21,10 @@ export const useProjectStore = defineStore('project', {
summary: {},
pages: [] as Array<ContextState>,
pageLoaded: 0,
bw: {
version: '0.1.0',
platform: 'web',
},
}
},
actions: {
Expand All @@ -35,6 +41,8 @@ export const useProjectStore = defineStore('project', {
this.main = payload.main
this.summary = payload.summary
this.pages = payload.pages
this.bw.platform = payload.bw.platform
this.bw.version = payload.bw.version
},
create(payload: Record<any, any>) {
this.$reset()
Expand All @@ -49,6 +57,8 @@ export const useProjectStore = defineStore('project', {
this.main = {}
this.summary = {}
this.pages = []
this.bw.platform = isElectron() ? 'desktop' : 'web'
this.bw.version = useEnv().packageVersion() as string

const init: ContextState = {
id: this.totalPagesCreated,
Expand Down Expand Up @@ -84,6 +94,8 @@ export const useProjectStore = defineStore('project', {
this.main = {}
this.summary = {}
this.pages = []
this.bw.platform = isElectron() ? 'desktop' : 'web'
this.bw.version = useEnv().packageVersion() as string

const context: ContextState = {
id: this.totalPagesCreated,
Expand Down
6 changes: 6 additions & 0 deletions src/types/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ProjectState {
summary: Record<any, any>
pages: Array<ContextState>
pageLoaded: number
bw: ProjectStateBetterWrite
}

export interface ProjectObject {
Expand All @@ -23,3 +24,8 @@ export interface ProjectObject {
logger: LoggerState
pdf: PDFState
}

export interface ProjectStateBetterWrite {
platform: 'web' | 'desktop' | 'app'
version: string
}
11 changes: 10 additions & 1 deletion src/use/storage/dropbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useContextStore } from '@/store/context'
import i18n from '@/lang'
import { useAuthStore } from '@/store/auth'
import useEmitter from '@/use/emitter'
import isElectron from 'is-electron'

export const useDropbox = () => {
const CONTEXT = useContextStore()
Expand All @@ -21,6 +22,7 @@ export const useDropbox = () => {

const toast = useToast()
const emitter = useEmitter()
const env = useEnv()
const { t } = i18n.global

const loadContext = async (context: any) => {
Expand Down Expand Up @@ -126,10 +128,17 @@ export const useDropbox = () => {
})
}

// <= 0.4.0
if (!context.project.bw) {
context.project.bw = {
platform: isElectron() ? 'desktop' : 'web',
version: env.packageVersion(),
}
}

loadContext(context)
})
.catch((err: DropboxResponseError<any>) => {
console.log(err)
toast.error(t('toast.project.error'))
})
},
Expand Down
9 changes: 9 additions & 0 deletions src/use/storage/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useLoggerStore } from '@/store/logger'
import { usePDFStore } from '@/store/pdf'
import { useContextStore } from '@/store/context'
import useEmitter from '@/use/emitter'
import isElectron from 'is-electron'

export const useLocalStorage = () => {
const CONTEXT = useContextStore()
Expand Down Expand Up @@ -45,6 +46,14 @@ export const useLocalStorage = () => {
})
}

// <= 0.4.0
if (!_.project.bw) {
_.project.bw = {
platform: isElectron() ? 'desktop' : 'web',
version: env.packageVersion(),
}
}

return _
}

Expand Down

0 comments on commit c8572ee

Please sign in to comment.