5.11.2: Случайная сторона карточки при каждом показе слова
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m3s

This commit is contained in:
poignatov
2026-03-04 18:28:08 +03:00
parent 6caed05c9f
commit 20773a29b7
3 changed files with 9 additions and 9 deletions

View File

@@ -1 +1 @@
5.11.1 5.11.2

View File

@@ -1,6 +1,6 @@
{ {
"name": "play-life-web", "name": "play-life-web",
"version": "5.11.1", "version": "5.11.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -34,6 +34,7 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
const cardsShownRef = useRef(0) // Синхронный счётчик для избежания race condition const cardsShownRef = useRef(0) // Синхронный счётчик для избежания race condition
const saveProgressPromiseRef = useRef(null) // Промис сохранения прогресса (null = ещё не запущено) const saveProgressPromiseRef = useRef(null) // Промис сохранения прогресса (null = ещё не запущено)
const savePayloadRef = useRef(null) // Данные для сохранения при нажатии «Закончить» (если сохранение ещё не запускали) const savePayloadRef = useRef(null) // Данные для сохранения при нажатии «Закончить» (если сохранение ещё не запускали)
const [currentSide, setCurrentSide] = useState(null) // Текущая случайная сторона карточки ('word' или 'translation')
// Функция равномерного распределения слов в пуле с гарантией максимального расстояния между одинаковыми словами // Функция равномерного распределения слов в пуле с гарантией максимального расстояния между одинаковыми словами
// excludeFirstWordId - ID слова, которое не должно быть первым в пуле (только что показанная карточка) // excludeFirstWordId - ID слова, которое не должно быть первым в пуле (только что показанная карточка)
@@ -213,6 +214,7 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
setWords([]) setWords([])
setTestWords([]) setTestWords([])
setCurrentWord(null) setCurrentWord(null)
setCurrentSide(null)
setFlippedCards(new Set()) setFlippedCards(new Set())
setWordStats({}) setWordStats({})
wordStatsRef.current = {} wordStatsRef.current = {}
@@ -437,6 +439,7 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
cardsShownRef.current = nextCardsShown cardsShownRef.current = nextCardsShown
setCurrentWord(validWord) setCurrentWord(validWord)
setCurrentSide(Math.random() < 0.5 ? 'word' : 'translation')
setCardsShown(nextCardsShown) setCardsShown(nextCardsShown)
setFlippedCards(new Set()) setFlippedCards(new Set())
@@ -450,6 +453,7 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
// showCard: показываем карточку // showCard: показываем карточку
setCurrentWord(nextWord) setCurrentWord(nextWord)
setCurrentSide(Math.random() < 0.5 ? 'word' : 'translation')
setCardsShown(nextCardsShown) setCardsShown(nextCardsShown)
setFlippedCards(new Set()) setFlippedCards(new Set())
@@ -604,9 +608,6 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
} }
} }
const getRandomSide = (word) => {
return word.id % 2 === 0 ? 'word' : 'translation'
}
return ( return (
<div className="test-container test-container-fullscreen"> <div className="test-container test-container-fullscreen">
@@ -741,10 +742,9 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
loadWords() loadWords()
}} /> }} />
)} )}
{!loading && !error && !isFinishingRef.current && currentWord && (() => { {!loading && !error && !isFinishingRef.current && currentWord && currentSide && (() => {
const word = currentWord const word = currentWord
const isFlipped = flippedCards.has(word.id) const isFlipped = flippedCards.has(word.id)
const showSide = getRandomSide(word)
return ( return (
<div className="test-card-container" key={word.id}> <div className="test-card-container" key={word.id}>
@@ -754,7 +754,7 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
> >
<div className="test-card-front"> <div className="test-card-front">
<div className="test-card-content"> <div className="test-card-content">
{showSide === 'word' ? ( {currentSide === 'word' ? (
<div className="test-word">{word.name}</div> <div className="test-word">{word.name}</div>
) : ( ) : (
<div className="test-translation">{word.translation}</div> <div className="test-translation">{word.translation}</div>
@@ -763,7 +763,7 @@ function TestWords({ onNavigate, wordCount: initialWordCount, configId: initialC
</div> </div>
<div className="test-card-back"> <div className="test-card-back">
<div className="test-card-content"> <div className="test-card-content">
{showSide === 'word' ? ( {currentSide === 'word' ? (
<div className="test-translation">{word.translation}</div> <div className="test-translation">{word.translation}</div>
) : ( ) : (
<div className="test-word">{word.name}</div> <div className="test-word">{word.name}</div>