Compare commits
2 Commits
fc4ed188d7
...
0ad747b69f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ad747b69f | ||
|
|
c5236b2587 |
@@ -5,7 +5,7 @@ import { data, generateId } from "@/data/data"
|
|||||||
import { DataType } from "@/data/DataType.enum"
|
import { DataType } from "@/data/DataType.enum"
|
||||||
import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache"
|
import { prepareNoteCache } from "@/modules/note/cache/prepareNoteCache"
|
||||||
import { Note } from "@/modules/note/models/Note"
|
import { Note } from "@/modules/note/models/Note"
|
||||||
import { queryFileContent } from "@/modules/repo/services/repo"
|
import { getMainReadme, queryFileContent } from "@/modules/repo/services/repo"
|
||||||
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
|
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
|
||||||
|
|
||||||
export const useOfflineNotes = () => {
|
export const useOfflineNotes = () => {
|
||||||
@@ -13,6 +13,7 @@ export const useOfflineNotes = () => {
|
|||||||
const totalOfNotes = computed(() => store.files.length)
|
const totalOfNotes = computed(() => store.files.length)
|
||||||
|
|
||||||
const noteCompleted = ref(0)
|
const noteCompleted = ref(0)
|
||||||
|
const failedNotes = ref(0)
|
||||||
|
|
||||||
const cacheAllNotes = async () => {
|
const cacheAllNotes = async () => {
|
||||||
const isInitialized = store.user && store.repo && totalOfNotes.value > 0
|
const isInitialized = store.user && store.repo && totalOfNotes.value > 0
|
||||||
@@ -30,6 +31,7 @@ export const useOfflineNotes = () => {
|
|||||||
const cachedNotesSet = new Set(cachedNotesFromSha.map((note) => note._id))
|
const cachedNotesSet = new Set(cachedNotesFromSha.map((note) => note._id))
|
||||||
|
|
||||||
noteCompleted.value = 0
|
noteCompleted.value = 0
|
||||||
|
failedNotes.value = 0
|
||||||
|
|
||||||
for (const file of store.files) {
|
for (const file of store.files) {
|
||||||
noteCompleted.value++
|
noteCompleted.value++
|
||||||
@@ -50,11 +52,18 @@ export const useOfflineNotes = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!contentFile) {
|
if (!contentFile) {
|
||||||
return null
|
failedNotes.value++
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCacheNote(contentFile)
|
saveCacheNote(contentFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await getMainReadme(store.user, store.repo)
|
||||||
|
} catch {
|
||||||
|
failedNotes.value++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const { execute, isLoading } = useAsyncState(cacheAllNotes, null, {
|
const { execute, isLoading } = useAsyncState(cacheAllNotes, null, {
|
||||||
immediate: false
|
immediate: false
|
||||||
@@ -64,6 +73,7 @@ export const useOfflineNotes = () => {
|
|||||||
cacheAllNotes: execute,
|
cacheAllNotes: execute,
|
||||||
isLoading,
|
isLoading,
|
||||||
totalOfNotes,
|
totalOfNotes,
|
||||||
noteCompleted
|
noteCompleted,
|
||||||
|
failedNotes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useOfflineNotes } from "@/hooks/useOfflineNotes.hook"
|
import { useOfflineNotes } from "@/hooks/useOfflineNotes.hook"
|
||||||
import { confirmMessage } from "@/utils/notif"
|
import { confirmMessage, errorMessage } from "@/utils/notif"
|
||||||
|
|
||||||
const { cacheAllNotes, isLoading, totalOfNotes, noteCompleted } =
|
const { cacheAllNotes, isLoading, totalOfNotes, noteCompleted, failedNotes } =
|
||||||
useOfflineNotes()
|
useOfflineNotes()
|
||||||
|
|
||||||
const confirmBeforeCachingAllNotes = async () => {
|
const confirmBeforeCachingAllNotes = async () => {
|
||||||
confirm("Do you want to cache all notes?")
|
confirm("Do you want to cache all notes?")
|
||||||
await cacheAllNotes()
|
await cacheAllNotes()
|
||||||
|
if (failedNotes.value > 0) {
|
||||||
|
errorMessage(
|
||||||
|
`${failedNotes.value} of ${totalOfNotes.value} note(s) could not be cached — try again`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
confirmMessage("✅ All notes have been locally saved")
|
confirmMessage("✅ All notes have been locally saved")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user