refacto: prepare for a relevant useNote hook

This commit is contained in:
Julien Calixte
2024-11-02 18:58:51 +01:00
parent c2168c4927
commit a1c5cb666a
3 changed files with 30 additions and 27 deletions

View File

@@ -13,7 +13,7 @@ import LiteLoading from '@/components/LiteLoading.vue'
import StackedNote from '@/components/StackedNote.vue'
import { useLinks } from '@/hooks/useLinks.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 { useVisitRepo } from '@/modules/history/hooks/useVisitRepo.hook'
import CacheAllNotes from '@/modules/note/components/CacheAllNote.vue'
@@ -52,7 +52,7 @@ const { toHTML } = useMarkdown(repo)
const { listenToClick } = useLinks('note-display')
const { stackedNotes, scrollToTop } = useRouteQueryStackedNotes()
const { titles } = useNote('note-container')
const { titles } = useNoteView('note-container')
const renderedContent = computed(() =>
props.content !== null

View File

@@ -88,15 +88,19 @@ watch([content, mode], () => {
})
watch(mode, async (newMode) => {
if (newMode === 'read' && rawContent.value !== initialRawContent.value) {
const editedSha = (await getEditedSha()) ?? sha.value
const hasUserFinishedToEdit =
newMode === 'read' && rawContent.value !== initialRawContent.value
if (!hasUserFinishedToEdit) {
return
}
if (!path.value) {
console.warn('no path found for this file')
return
}
const editedSha = (await getEditedSha()) ?? sha.value
const newSha = await updateFile({
content: rawContent.value,
path: path.value,
@@ -113,7 +117,6 @@ watch(mode, async (newMode) => {
editedSha: newSha
})
initialRawContent.value = rawContent.value
}
})
</script>

View File

@@ -8,7 +8,7 @@ import { resolvePath } from '@/modules/repo/services/resolvePath'
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
import { pathToNotePathTitle } from '@/utils/noteTitle'
export const useNote = (containerClass: string) => {
export const useNoteView = (containerClass: string) => {
const store = useUserRepoStore()
const { isMobile } = useOverlay(false)
const { stackedNotes, addStackedNote } = useRouteQueryStackedNotes()