✨ (stacked note) cache visited note
This commit is contained in:
31
src/modules/note/hooks/useNoteCache.ts
Normal file
31
src/modules/note/hooks/useNoteCache.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { data } from '@/data/data'
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { Note } from '@/modules/note/models/Note'
|
||||
import { useAsyncState } from '@vueuse/core'
|
||||
import { computed } from 'vue'
|
||||
|
||||
export const useNoteCache = (sha: string) => {
|
||||
const noteId = computed(() => data.generateId(DataType.Note, sha))
|
||||
const getCachedNote = async () => data.get<DataType.Note, Note>(noteId.value)
|
||||
|
||||
const cachedNote = useAsyncState(getCachedNote, null)
|
||||
|
||||
const saveCacheNote = async (content: string) => {
|
||||
const newNote: Note = {
|
||||
_id: noteId.value,
|
||||
$type: DataType.Note,
|
||||
content
|
||||
}
|
||||
|
||||
await data.update(newNote)
|
||||
|
||||
await cachedNote.execute()
|
||||
}
|
||||
|
||||
return {
|
||||
cachedNote: cachedNote.state,
|
||||
isReady: cachedNote.isReady,
|
||||
getCachedNote,
|
||||
saveCacheNote
|
||||
}
|
||||
}
|
||||
6
src/modules/note/models/Note.ts
Normal file
6
src/modules/note/models/Note.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { Model } from '@/data/models/Model'
|
||||
|
||||
export interface Note extends Model<DataType.Note> {
|
||||
content: string
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { FavoriteRepo } from '@/modules/models/FavoriteRepo'
|
||||
import { RepoBase } from '@/modules/interfaces/RepoBase'
|
||||
import { FavoriteRepo } from '@/modules/repo/models/FavoriteRepo'
|
||||
import { RepoBase } from '@/modules/repo/interfaces/RepoBase'
|
||||
import { data } from '@/data/data'
|
||||
import { useRepos } from '@/hooks/useRepos.hook'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { RepoBase } from '@/modules/interfaces/RepoBase'
|
||||
import { RepoBase } from '@/modules/repo/interfaces/RepoBase'
|
||||
import { computed } from 'vue'
|
||||
import { useFavoriteRepos } from '@/modules/repo/hooks/useFavoriteRepos.hook'
|
||||
import { useRepos } from '@/hooks/useRepos.hook'
|
||||
Reference in New Issue
Block a user