✨ (card) add repetition card in database
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
import { data } from '@/data/data'
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { useFile } from '@/hooks/useFile.hook'
|
||||
import { useLinks } from '@/hooks/useLinks.hook'
|
||||
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
||||
import { Card } from '@/modules/card/models/Card'
|
||||
import { RepetitionCard } from '@/modules/card/models/RepetitionCard'
|
||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||
import { asyncComputed } from '@vueuse/core'
|
||||
import { isAfter, isBefore } from 'date-fns'
|
||||
import { computed, nextTick, watch } from 'vue'
|
||||
|
||||
interface Repetition {
|
||||
repetition: RepetitionCard
|
||||
card: Card
|
||||
}
|
||||
|
||||
export const useSpacedRepetitionCards = () => {
|
||||
const { renderString } = useMarkdown()
|
||||
const store = useUserRepoStore()
|
||||
@@ -18,13 +27,39 @@ export const useSpacedRepetitionCards = () => {
|
||||
)
|
||||
|
||||
const cards = asyncComputed(async () => {
|
||||
const cards: Card[] = []
|
||||
const cards: Repetition[] = []
|
||||
|
||||
for (const cardFile of cardFiles.value) {
|
||||
if (!cardFile.sha) {
|
||||
continue
|
||||
}
|
||||
|
||||
const repetitionId = data.generateId(
|
||||
DataType.RepetitionCard,
|
||||
cardFile.sha
|
||||
)
|
||||
|
||||
let repetition = await data.get<DataType.RepetitionCard, RepetitionCard>(
|
||||
repetitionId
|
||||
)
|
||||
|
||||
if (!repetition) {
|
||||
const newRepetition: RepetitionCard = {
|
||||
_id: repetitionId,
|
||||
$type: DataType.RepetitionCard,
|
||||
level: 1,
|
||||
repeatDate: new Date()
|
||||
}
|
||||
await data.add<DataType.RepetitionCard>(newRepetition)
|
||||
repetition = (await data.get<DataType.RepetitionCard, RepetitionCard>(
|
||||
repetitionId
|
||||
)) as RepetitionCard
|
||||
}
|
||||
|
||||
if (isAfter(new Date(repetition.repeatDate), new Date())) {
|
||||
continue
|
||||
}
|
||||
|
||||
const { getRawContent } = useFile(cardFile.sha, false)
|
||||
const content = await getRawContent()
|
||||
|
||||
@@ -32,9 +67,12 @@ export const useSpacedRepetitionCards = () => {
|
||||
decodeURIComponent(escape(atob(content ?? '')))?.split('___') ?? []
|
||||
|
||||
cards.push({
|
||||
front: renderString(front),
|
||||
back: renderString(back),
|
||||
references: renderString(references)
|
||||
repetition,
|
||||
card: {
|
||||
front: renderString(front),
|
||||
back: renderString(back),
|
||||
references: renderString(references)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user