feat: add daily fruit feature and related components
Build Docker Image / build (push) Successful in 2m8s
Build Docker Image / build (push) Successful in 2m8s
- Introduced a new daily fruit selection mechanism with associated database schema. - Created routes and components for displaying and interacting with daily fruit. - Implemented logic for tracking wins related to daily fruit and character guesses. - Added localization support for new daily fruit titles in English and French. - Enhanced the user experience with history tracking for guesses and wins. - Refactored existing character-related logic to accommodate new fruit functionality.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { getAllDevilFruitsFromCharacters, getOrCreateTodayFruit, getYesterdayFruit, getTodayFruitWinsCount } from '$lib/server/daily-fruit';
|
||||
import { getAllCharacters } from '$lib/server/daily-character';
|
||||
|
||||
export async function load(event) {
|
||||
const fruits = await getAllDevilFruitsFromCharacters();
|
||||
const dailyFruit = await getOrCreateTodayFruit();
|
||||
|
||||
if (!dailyFruit) {
|
||||
throw error(404, 'No daily fruit available. Please check if devil fruits are configured from characters.');
|
||||
}
|
||||
|
||||
const yesterdayFruit = await getYesterdayFruit(new Date());
|
||||
|
||||
// Load all characters for searching and filter only those with a devil fruit
|
||||
const allCharacters = await getAllCharacters();
|
||||
const characters = allCharacters.filter((c) => c.devilFruitId);
|
||||
|
||||
// Find the character tied to the chosen fruit among characters that have a devil fruit
|
||||
const dailyCharacter = characters.find((c) => c.devilFruitId === dailyFruit.id) ?? null;
|
||||
|
||||
const winCount = await getTodayFruitWinsCount(dailyFruit.id);
|
||||
|
||||
return {
|
||||
fruits,
|
||||
dailyFruit,
|
||||
dailyCharacter,
|
||||
yesterdayFruit,
|
||||
winCount,
|
||||
characters
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user