🐛 (card) fix flex and reload at every failed flashcard

This commit is contained in:
Julien Calixte
2023-07-08 18:22:34 +02:00
parent 558d00d703
commit fe2ba2d82d
3 changed files with 8 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import FlipCard from '@/modules/card/components/FlipCard.vue' import FlipCard from '@/modules/card/components/FlipCard.vue'
import { Repetition } from '@/modules/card/hooks/useSpacedRepetitionCards' import { Repetition } from '@/modules/card/hooks/useSpacedRepetitionCards'
import { computed, ref } from 'vue' import { ref } from 'vue'
const props = defineProps<{ cards: Repetition[] }>() const props = defineProps<{ cards: Repetition[] }>()
const emits = defineEmits<{ const emits = defineEmits<{
@@ -17,12 +17,8 @@ const cards = ref(
const currentIndex = ref(0) const currentIndex = ref(0)
const cardsToDisplay = computed(() => {
return cards.value
})
const goToNextCard = (success: boolean) => { const goToNextCard = (success: boolean) => {
const id = cardsToDisplay.value[currentIndex.value].repetition._id ?? '' const id = cards.value[currentIndex.value].repetition._id ?? ''
if (success) { if (success) {
emits('success', id) emits('success', id)
@@ -41,13 +37,13 @@ const goToNextCard = (success: boolean) => {
<template> <template>
<div class="flip-card-list"> <div class="flip-card-list">
<h3 class="subtitle is-3"> <h3 class="subtitle is-3">
Level: {{ cardsToDisplay[currentIndex].repetition.level }} Level: {{ cards[currentIndex].repetition.level }}
</h3> </h3>
<h4>cards left: {{ cardsToDisplay.length - currentIndex }}</h4> <h4>cards left: {{ cards.length - currentIndex }}</h4>
<div v-if="currentIndex < cards.length"> <div v-if="currentIndex < cards.length">
<flip-card <flip-card
v-for="(card, index) in cardsToDisplay" v-for="(card, index) in cards"
:key="card.repetition._id ?? ''" :key="card.repetition._id ?? ''"
class="card" class="card"
:style="{ :style="{
@@ -65,7 +61,7 @@ const goToNextCard = (success: boolean) => {
<style scoped lang="scss"> <style scoped lang="scss">
.flip-card-list { .flip-card-list {
overflow-x: hidden; overflow-x: hidden;
height: 100%; flex: 1;
.card { .card {
position: relative; position: relative;

View File

@@ -99,6 +99,7 @@ export const useSpacedRepetitionCards = () => {
repeatDate: addDays(new Date(), 2 ** repetition.level) repeatDate: addDays(new Date(), 2 ** repetition.level)
}) })
} }
const failRepetition = async (cardId: string) => { const failRepetition = async (cardId: string) => {
const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>( const repetition = await data.get<DataType.RepetitionCard, RepetitionCard>(
cardId cardId
@@ -114,8 +115,6 @@ export const useSpacedRepetitionCards = () => {
level, level,
repeatDate: addDays(new Date(), level) repeatDate: addDays(new Date(), level)
}) })
await execute()
} }
watch( watch(

View File

@@ -46,6 +46,7 @@ const { cards, isLoading, successRepetition, failRepetition } =
.cards { .cards {
flex: 1; flex: 1;
display: flex;
} }
} }
</style> </style>