Fix words per display setting and limit max to 3

This commit is contained in:
Roni Laukkarinen
2026-02-01 21:38:05 +02:00
parent 909d3d905a
commit ed4132b650
2 changed files with 17 additions and 13 deletions
+1
View File
@@ -1,6 +1,7 @@
### 2026-02-01: 1.0.4 ### 2026-02-01: 1.0.4
* Improve mobile responsiveness and book metadata layout * Improve mobile responsiveness and book metadata layout
* Fix words per display setting and limit max to 3
### 2026-02-01: 1.0.3 ### 2026-02-01: 1.0.3
+16 -13
View File
@@ -396,11 +396,11 @@ function App() {
timeoutRef.current = setTimeout(() => { timeoutRef.current = setTimeout(() => {
setCurrentIndex((prev) => { setCurrentIndex((prev) => {
if (prev + 1 >= words.length) { if (prev + wordAmount >= words.length) {
setIsPlaying(false); setIsPlaying(false);
return prev; return prev;
} }
return prev + 1; return prev + wordAmount;
}); });
}, delay); }, delay);
} }
@@ -410,7 +410,7 @@ function App() {
clearTimeout(timeoutRef.current); clearTimeout(timeoutRef.current);
} }
}; };
}, [isPlaying, currentIndex, words, getBaseDelay]); }, [isPlaying, currentIndex, words, getBaseDelay, wordAmount]);
useEffect(() => { useEffect(() => {
const handleKeyDown = (e) => { const handleKeyDown = (e) => {
@@ -465,9 +465,10 @@ function App() {
return () => window.removeEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown);
}, [isPlaying, words.length]); }, [isPlaying, words.length]);
const getCurrentWord = () => { const getCurrentWords = () => {
if (words.length === 0) return ""; if (words.length === 0) return "";
return words[currentIndex] || ""; const endIndex = Math.min(currentIndex + wordAmount, words.length);
return words.slice(currentIndex, endIndex).join(" ");
}; };
const togglePlay = () => { const togglePlay = () => {
@@ -502,12 +503,14 @@ function App() {
const progress = const progress =
words.length > 0 ? ((currentIndex + 1) / words.length) * 100 : 0; words.length > 0 ? ((currentIndex + 1) / words.length) * 100 : 0;
const currentWord = getCurrentWord(); const currentText = getCurrentWords();
const orpIndex = getORPIndex(currentWord.length); // For ORP, use the first word when displaying multiple words
const firstWord = words[currentIndex] || "";
const orpIndex = getORPIndex(firstWord.length);
const beforeORP = currentWord.slice(0, orpIndex); const beforeORP = currentText.slice(0, orpIndex);
const orpChar = currentWord[orpIndex] || ""; const orpChar = currentText[orpIndex] || "";
const afterORP = currentWord.slice(orpIndex + 1); const afterORP = currentText.slice(orpIndex + 1);
return ( return (
<div style={styles.container}> <div style={styles.container}>
@@ -622,7 +625,7 @@ function App() {
</div> </div>
<div style={styles.wordContainer} className="word-container"> <div style={styles.wordContainer} className="word-container">
{currentWord ? ( {currentText ? (
<div <div
style={{ style={{
...styles.wordDisplay, ...styles.wordDisplay,
@@ -952,9 +955,9 @@ function App() {
</button> </button>
<span style={styles.settingValue}>{wordAmount}</span> <span style={styles.settingValue}>{wordAmount}</span>
<button <button
onClick={() => setWordAmount(Math.min(5, wordAmount + 1))} onClick={() => setWordAmount(Math.min(3, wordAmount + 1))}
style={styles.settingBtn} style={styles.settingBtn}
disabled={wordAmount >= 5} disabled={wordAmount >= 3}
> >
<Plus size={14} /> <Plus size={14} />
</button> </button>