Skip to content

Commit

Permalink
fix: progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yb6b committed Mar 24, 2024
1 parent e352b94 commit ac83b5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion components/train/TrainCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ watch(userKeys, (newKeys) => {
const showConfetti = shallowRef(false)
const cardLength = p.cards.length
let alreadyShowConfetti = false
watch(progress, async (newV, oldV) => {
if (newV === cardLength && newV > oldV) {
if (!alreadyShowConfetti && newV === cardLength && newV > oldV) {
alreadyShowConfetti = true
showConfetti.value = true
await nextTick()
startConfette()
Expand Down
9 changes: 7 additions & 2 deletions components/train/useReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export function useReview<T>(name: string, cards: T[]) {

const emptyRecord = () => Array.from({ length: cards.length }, (_, i) => [-1, i] as Record)
const storageRef = useLocalStorage<Record[]>(`yima_${name}_records`, emptyRecord)
if (storageRef.value.length < cards.length) {
for (let i = storageRef.value.length; i < cards.length; i++) {
storageRef.value.push([-1, i])
}
}

const scanProgress = () => storageRef.value.reduce((p, c) => p + Number(c[0] > 1), 0)
const progress = shallowRef(scanProgress())
Expand All @@ -27,7 +32,7 @@ export function useReview<T>(name: string, cards: T[]) {

const answer = (correct: boolean) => {
if (!correct) {
if (storageRef.value[0][0] > 2)
if (storageRef.value[0][0] > 1)
progress.value -= 1
storageRef.value[0][0] = -1
isFirst.value = true
Expand All @@ -36,7 +41,7 @@ export function useReview<T>(name: string, cards: T[]) {

const firstRecord = storageRef.value[0]
const firstCount = ++firstRecord[0]
if (firstCount > 2) {
if (firstCount === 2) {
progress.value += 1
}

Expand Down

0 comments on commit ac83b5d

Please sign in to comment.