Skip to content

Commit

Permalink
feat(snippets): add patch method
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Mar 29, 2022
1 parent 412b3a1 commit 41ba0c8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useApi } from '@/composable'
import { store } from '@/electron'
import type { Snippet, SnippetContent } from '@@/types/db'
import { defineStore } from 'pinia'
import { useFolderStore } from './folders'
import type { SnippetWithFolder, State } from './types/snippets'

export const useSnippetStore = defineStore('snippets', {
Expand Down Expand Up @@ -47,7 +48,14 @@ export const useSnippetStore = defineStore('snippets', {
store.app.set('selectedSnippetId', id)
},
async patchSnippetsById (id: string, body: Partial<Snippet>) {
body.updatedAt = new Date().valueOf()
const { data } = await useApi(`/snippets/${id}`).patch(body).json()
const snippet = this.snippets.find(i => i.id === id)

if (!snippet) return

if (snippet.name !== data.value.name) {
snippet.name = data.value.name
}
},
async patchCurrentSnippetContentByKey (
key: keyof SnippetContent,
Expand Down

0 comments on commit 41ba0c8

Please sign in to comment.