diff --git a/src/lib/components/ChapterGuess.svelte b/src/lib/components/ChapterGuess.svelte new file mode 100644 index 0000000..aa15a9d --- /dev/null +++ b/src/lib/components/ChapterGuess.svelte @@ -0,0 +1,216 @@ + + + +
+

Bonus Challenge

+

+ Guess the chapter for an even higher grade +

+ +
+ {#each chapterOptions as chapter} + + {/each} +
+ + {#if hasAnswered} +

+ {isCorrect ? "✓ Correct!" : "✗ Incorrect"} +

+

+ The verse is from chapter {correctChapter} +

+ {#if isCorrect} +

Grade: S++

+ {/if} + {/if} +
+
diff --git a/src/lib/components/SearchInput.svelte b/src/lib/components/SearchInput.svelte index 2eb9cad..753d589 100644 --- a/src/lib/components/SearchInput.svelte +++ b/src/lib/components/SearchInput.svelte @@ -16,16 +16,55 @@ } -
- +
+
+ + + + + {#if searchQuery} + + {/if} +
{#if searchQuery && filteredBooks.length > 0}
-

- {getNextGradeMessage(guessCount)} -

+ {#if guessCount !== 1} +

+ {getNextGradeMessage(guessCount)} +

+ {/if} + + {#if guessCount === 1} + + {/if} + diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 1305e5b..61aacc5 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -30,6 +30,8 @@ let copied = $state(false); let isDev = $state(false); + let chapterGuessCompleted = $state(false); + let chapterCorrect = $state(false); let anonymousId = $state(""); let statsSubmitted = $state(false); @@ -54,9 +56,14 @@ let isWon = $derived(guesses.some((g) => g.book.id === correctBookId)); let grade = $derived( isWon - ? getGrade(guesses.length, getBookById(correctBookId)?.popularity ?? 0) + ? guesses.length === 1 && chapterCorrect + ? "S++" + : getGrade(guesses.length, getBookById(correctBookId)?.popularity ?? 0) : "" ); + let blurChapter = $derived( + isWon && guesses.length === 1 && !chapterGuessCompleted + ); function getBookById(id: string): BibleBook | undefined { return bibleBooks.find((b) => b.id === id); @@ -79,7 +86,7 @@ const testamentMatch = book.testament === correctBook.testament; const sectionMatch = book.section === correctBook.section; - const adjacent = isAdjacent(book.id, correctBookId); + const adjacent = isAdjacent(bookId, correctBookId); console.log( `Guess: ${book.name} (order ${book.order}), Correct: ${correctBook.name} (order ${correctBook.order}), Adjacent: ${adjacent}` @@ -141,6 +148,17 @@ anonymousId = getOrCreateAnonymousId(); const statsKey = `bibdle-stats-submitted-${dailyVerse.date}`; statsSubmitted = localStorage.getItem(statsKey) === "true"; + const chapterGuessKey = `bibdle-chapter-guess-${dailyVerse.reference}`; + chapterGuessCompleted = localStorage.getItem(chapterGuessKey) !== null; + if (chapterGuessCompleted) { + const saved = localStorage.getItem(chapterGuessKey); + if (saved) { + const data = JSON.parse(saved); + const match = dailyVerse.reference.match(/\s(\d+):/); + const correctChapter = match ? parseInt(match[1], 10) : 1; + chapterCorrect = data.selectedChapter === correctChapter; + } + } }); $effect(() => { @@ -307,8 +325,8 @@ const siteUrl = window.location.origin; return [ `📖 Bibdle | ${formattedDate} 📖`, - `${grade} (${guesses.length} ${guesses.length == 1 ? "guess" : "guesses"})`, - `${emojis}`, + `${grade} (${guesses.length} ${guesses.length === 1 ? "guess" : "guesses"})`, + `${emojis}${guesses.length === 1 && chapterCorrect ? " ⭐" : ""}`, siteUrl, ].join("\n"); } @@ -408,7 +426,7 @@
- + {#if !isWon} @@ -422,6 +440,18 @@ bind:copied {statsSubmitted} guessCount={guesses.length} + reference={dailyVerse.reference} + onChapterGuessCompleted={() => { + chapterGuessCompleted = true; + const key = `bibdle-chapter-guess-${dailyVerse.reference}`; + const saved = localStorage.getItem(key); + if (saved) { + const data = JSON.parse(saved); + const match = dailyVerse.reference.match(/\s(\d+):/); + const correctChapter = match ? parseInt(match[1], 10) : 1; + chapterCorrect = data.selectedChapter === correctChapter; + } + }} /> {/if}