Skip to content

Commit

Permalink
fix(snippets): check for undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Apr 1, 2022
1 parent c8b1c6a commit f2b6a2f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export const useSnippetStore = defineStore('snippets', {
snippetsDeleted: state =>
state.snippets.filter(i => !i.isDeleted) as SnippetWithFolder[],
selectedId: state => state.snippet?.id,
currentContent: state => state.snippet?.content[state.fragment]?.value,
currentContent: state =>
state.snippet?.content?.[state.fragment]?.value || undefined,
currentLanguage: state =>
state.snippet?.content[state.fragment]?.language,
fragmentLabels: state => state.snippet?.content.map(i => i.label),
fragmentCount: state => state.snippet?.content.length,
state.snippet?.content?.[state.fragment]?.language,
fragmentLabels: state => state.snippet?.content?.map(i => i.label),
fragmentCount: state => state.snippet?.content?.length,
isFragmentsShow () {
return this.fragmentLabels?.length > 1
}
Expand All @@ -49,9 +50,13 @@ export const useSnippetStore = defineStore('snippets', {
)
},
async getSnippetsById (id: string) {
const { data } = await useApi<Snippet>(`/snippets/${id}`).get().json()
this.snippet = data.value
store.app.set('selectedSnippetId', id)
if (id) {
const { data } = await useApi<Snippet>(`/snippets/${id}`).get().json()
this.snippet = data.value
store.app.set('selectedSnippetId', id)
} else {
this.snippet = undefined
}
},
async patchSnippetsById (id: string, body: Partial<Snippet>) {
const { data } = await useApi(`/snippets/${id}`).patch(body).json()
Expand Down

0 comments on commit f2b6a2f

Please sign in to comment.