Skip to content

Commit

Permalink
feat(snippets): add new snippet method
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Mar 29, 2022
1 parent dea7dc2 commit 412b3a1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ export const useSnippetStore = defineStore('snippets', {

await useApi(`/snippets/${this.selectedId}`).patch(body)
}
},
async addNewSnippet () {
const folderStore = useFolderStore()
const body: Partial<Snippet> = {}

body.name = 'Untitled snippet'
body.folderId = folderStore.selectedId
body.content = [
{
label: 'Fragment 1',
language: folderStore.selected?.defaultLanguage || 'plain_text',
value: ''
}
]

const { data } = await useApi('/snippets').post(body).json()

this.snippet = data.value
store.app.set('selectedSnippetId', this.snippet!.id)
}
}
})

0 comments on commit 412b3a1

Please sign in to comment.