Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/routes/$lang.$codeLanguage.play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,39 @@ type GameState = {
usedProblemIds: string[]; // IDs of problems that have been used
};

/**
* Get proper display name for code language
*/
function getCodeLanguageDisplay(codeLanguage: string): string {
const languageMap: Record<string, string> = {
javascript: 'JavaScript',
python: 'Python',
php: 'PHP',
ruby: 'Ruby',
java: 'Java',
dart: 'Dart',
};
return languageMap[codeLanguage] || codeLanguage;
}

/**
* Meta function to set page title
*/
export function meta({ data }: Route.MetaArgs) {
if (!data) {
return [{ title: 'Bug Sniper' }];
}

const { codeLanguage } = data;
const codeLangDisplay = getCodeLanguageDisplay(codeLanguage);

return [
{
title: `${codeLangDisplay} | Bug Sniper`,
},
];
}

/**
* Validate route parameters and redirect if invalid
*/
Expand Down Expand Up @@ -145,6 +178,14 @@ export default function Play({ loaderData }: Route.ComponentProps) {
} | null>(null);
const [error, setError] = useState<string | null>(null);

// Update page title with remaining seconds
useEffect(() => {
if (typeof document !== 'undefined' && !gameEnded) {
const codeLangDisplay = getCodeLanguageDisplay(codeLanguage);
document.title = `(${gameState.remainingSeconds}s) ${codeLangDisplay} | Bug Sniper`;
}
}, [gameState.remainingSeconds, codeLanguage, gameEnded]);

// Timer countdown
useEffect(() => {
if (gameEnded) return;
Expand Down
33 changes: 33 additions & 0 deletions app/routes/result.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,39 @@ type ScoreRecord = {
llm_feedback: string | null;
};

/**
* Get proper display name for code language
*/
function getCodeLanguageDisplay(codeLanguage: string): string {
const languageMap: Record<string, string> = {
javascript: 'JavaScript',
python: 'Python',
php: 'PHP',
ruby: 'Ruby',
java: 'Java',
dart: 'Dart',
};
return languageMap[codeLanguage] || codeLanguage;
}

/**
* Meta function to set page title
*/
export function meta({ data }: Route.MetaArgs) {
if (!data || !data.score) {
return [{ title: 'Result Not Found | Bug Sniper' }];
}

const { score } = data;
const codeLangDisplay = getCodeLanguageDisplay(score.code_language);

return [
{
title: `${codeLangDisplay} ${score.score}pt | Bug Sniper`,
},
];
}

/**
* Loader to fetch score data from D1
*/
Expand Down