Added chapter guess challenge

This commit is contained in:
George Powell
2026-01-04 16:36:28 -05:00
parent 0f6870344f
commit 1b1bc7bd3c
5 changed files with 326 additions and 19 deletions

View File

@@ -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 @@
</div>
<div class="flex flex-col gap-6">
<VerseDisplay {data} {isWon} />
<VerseDisplay {data} {isWon} {blurChapter} />
{#if !isWon}
<SearchInput bind:searchQuery {guessedIds} {submitGuess} />
@@ -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}