🔧 (eslint)

This commit is contained in:
Julien Calixte
2021-05-09 00:50:41 +02:00
parent a9fba33760
commit 9afe9ef289
6 changed files with 125 additions and 125 deletions

View File

@@ -1,31 +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
}
}
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
}
}

View File

@@ -1,32 +1,32 @@
const sanitizePath = (path: string) => {
if (path.startsWith('./')) {
return decodeURIComponent(path.replace('./', ''))
}
return decodeURIComponent(path)
}
const removeNoteFilename = (pathNote: string) => {
const path = pathNote.split('/')
path.pop()
return sanitizePath(path.join('/'))
}
export const resolvePath = (
currentAbsolutePathNote: string,
pathToResolve: string
) => {
let currentAbsolutePath = removeNoteFilename(currentAbsolutePathNote)
pathToResolve = sanitizePath(pathToResolve)
while (pathToResolve.startsWith('../')) {
const adjustedAbsolutePath = currentAbsolutePath.split('/')
adjustedAbsolutePath.pop()
currentAbsolutePath = adjustedAbsolutePath.join('/')
pathToResolve = pathToResolve.replace('../', '')
}
return currentAbsolutePath
? `${currentAbsolutePath}/${pathToResolve}`
: pathToResolve
}
const sanitizePath = (path: string) => {
if (path.startsWith('./')) {
return decodeURIComponent(path.replace('./', ''))
}
return decodeURIComponent(path)
}
const removeNoteFilename = (pathNote: string) => {
const path = pathNote.split('/')
path.pop()
return sanitizePath(path.join('/'))
}
export const resolvePath = (
currentAbsolutePathNote: string,
pathToResolve: string
) => {
let currentAbsolutePath = removeNoteFilename(currentAbsolutePathNote)
pathToResolve = sanitizePath(pathToResolve)
while (pathToResolve.startsWith('../')) {
const adjustedAbsolutePath = currentAbsolutePath.split('/')
adjustedAbsolutePath.pop()
currentAbsolutePath = adjustedAbsolutePath.join('/')
pathToResolve = pathToResolve.replace('../', '')
}
return currentAbsolutePath
? `${currentAbsolutePath}/${pathToResolve}`
: pathToResolve
}