refacto: prepare for a relevant useNote hook
This commit is contained in:
@@ -13,7 +13,7 @@ import LiteLoading from '@/components/LiteLoading.vue'
|
|||||||
import StackedNote from '@/components/StackedNote.vue'
|
import StackedNote from '@/components/StackedNote.vue'
|
||||||
import { useLinks } from '@/hooks/useLinks.hook'
|
import { useLinks } from '@/hooks/useLinks.hook'
|
||||||
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
||||||
import { useNote } from '@/hooks/useNote.hook'
|
import { useNoteView } from '@/hooks/useNoteView.hook'
|
||||||
import { useRouteQueryStackedNotes } from '@/hooks/useRouteQueryStackedNotes.hook'
|
import { useRouteQueryStackedNotes } from '@/hooks/useRouteQueryStackedNotes.hook'
|
||||||
import { useVisitRepo } from '@/modules/history/hooks/useVisitRepo.hook'
|
import { useVisitRepo } from '@/modules/history/hooks/useVisitRepo.hook'
|
||||||
import CacheAllNotes from '@/modules/note/components/CacheAllNote.vue'
|
import CacheAllNotes from '@/modules/note/components/CacheAllNote.vue'
|
||||||
@@ -52,7 +52,7 @@ const { toHTML } = useMarkdown(repo)
|
|||||||
const { listenToClick } = useLinks('note-display')
|
const { listenToClick } = useLinks('note-display')
|
||||||
const { stackedNotes, scrollToTop } = useRouteQueryStackedNotes()
|
const { stackedNotes, scrollToTop } = useRouteQueryStackedNotes()
|
||||||
|
|
||||||
const { titles } = useNote('note-container')
|
const { titles } = useNoteView('note-container')
|
||||||
|
|
||||||
const renderedContent = computed(() =>
|
const renderedContent = computed(() =>
|
||||||
props.content !== null
|
props.content !== null
|
||||||
|
|||||||
@@ -88,15 +88,19 @@ watch([content, mode], () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
watch(mode, async (newMode) => {
|
watch(mode, async (newMode) => {
|
||||||
if (newMode === 'read' && rawContent.value !== initialRawContent.value) {
|
const hasUserFinishedToEdit =
|
||||||
const editedSha = (await getEditedSha()) ?? sha.value
|
newMode === 'read' && rawContent.value !== initialRawContent.value
|
||||||
|
|
||||||
|
if (!hasUserFinishedToEdit) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!path.value) {
|
if (!path.value) {
|
||||||
console.warn('no path found for this file')
|
console.warn('no path found for this file')
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editedSha = (await getEditedSha()) ?? sha.value
|
||||||
const newSha = await updateFile({
|
const newSha = await updateFile({
|
||||||
content: rawContent.value,
|
content: rawContent.value,
|
||||||
path: path.value,
|
path: path.value,
|
||||||
@@ -113,7 +117,6 @@ watch(mode, async (newMode) => {
|
|||||||
editedSha: newSha
|
editedSha: newSha
|
||||||
})
|
})
|
||||||
initialRawContent.value = rawContent.value
|
initialRawContent.value = rawContent.value
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { resolvePath } from '@/modules/repo/services/resolvePath'
|
|||||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
import { pathToNotePathTitle } from '@/utils/noteTitle'
|
import { pathToNotePathTitle } from '@/utils/noteTitle'
|
||||||
|
|
||||||
export const useNote = (containerClass: string) => {
|
export const useNoteView = (containerClass: string) => {
|
||||||
const store = useUserRepoStore()
|
const store = useUserRepoStore()
|
||||||
const { isMobile } = useOverlay(false)
|
const { isMobile } = useOverlay(false)
|
||||||
const { stackedNotes, addStackedNote } = useRouteQueryStackedNotes()
|
const { stackedNotes, addStackedNote } = useRouteQueryStackedNotes()
|
||||||
Reference in New Issue
Block a user