Bug fixes and correct answer count in results

This commit is contained in:
Mawoka
2025-10-25 22:49:02 +02:00
parent 932f8dfbcf
commit caa2a6002f
37 changed files with 164 additions and 157 deletions
@@ -95,6 +95,7 @@ SPDX-License-Identifier: MPL-2.0
<PlayerOverview
custom_field={data.results.custom_field_data}
scores={data.results.player_scores}
answers={data.results.answers}
/>
</div>
{/if}
@@ -10,30 +10,23 @@ SPDX-License-Identifier: MPL-2.0
const { t } = getLocalization();
interface Props {
questions: Question[];
answers: {
username: string;
answer: string;
right: boolean;
tike_taken: number;
score: number;
}[][];
username: string;
answer: string;
right: boolean;
tike_taken: number;
score: number;
}[][];
scores: {
[key: string]: string;
};
[key: string]: string;
};
title: string;
timestamp: string;
}
let {
questions,
answers,
scores,
title,
timestamp
}: Props = $props();
let { questions, answers, scores, title, timestamp }: Props = $props();
const usernames = Object.keys(scores);
@@ -49,7 +42,7 @@ SPDX-License-Identifier: MPL-2.0
<div class="w-full">
<div class="flex justify-center w-full">
<p class="text-3xl w-5/6 text-center">
{$t('results_page.general_overview.sentence', {
{@html $t('results_page.general_overview.sentence', {
title,
date: new Date(timestamp).toLocaleString(),
player_count: usernames.length,
@@ -10,16 +10,29 @@ SPDX-License-Identifier: MPL-2.0
const { t } = getLocalization();
interface Props {
scores: {
[key: string]: string;
};
[key: string]: string;
};
custom_field: {
[key: string]: string;
};
[key: string]: string;
};
answers: { [key: string]: any }[];
}
let { scores, custom_field }: Props = $props();
let { scores, custom_field, answers }: Props = $props();
let usernames = Object.keys(scores);
const correctCounts = {};
answers.forEach((questionAnswers) => {
questionAnswers.forEach((answer) => {
const user = answer.username;
if (!correctCounts[user]) {
correctCounts[user] = 0;
}
if (answer.right) {
correctCounts[user] += 1;
}
});
});
console.log(custom_field);
</script>
@@ -31,6 +44,9 @@ SPDX-License-Identifier: MPL-2.0
<th class="border-r dark:border-gray-500 p-1 mx-auto border-gray-300"
>{$t('result_page.player_name')}
</th>
<th class="border-r dark:border-gray-500 p-1 mx-auto border-gray-300"
>{$t('result_page.player_correct_questions')}
</th>
<th class="p-1 mx-auto">{$t('result_page.player_score')}</th>
{#if Object.keys(custom_field).length !== 0}
<th class="border-l dark:border-gray-500 p-1 mx-auto border-gray-300"
@@ -43,6 +59,9 @@ SPDX-License-Identifier: MPL-2.0
{#each usernames as uname}
<tr class="text-left">
<td class="border-r dark:border-gray-500 p-1 border-gray-300">{uname}</td>
<td class="border-r dark:border-gray-500 p-1 border-gray-300"
>{correctCounts[uname]}</td
>
<td class="p-1">{scores[uname]}</td>
{#if custom_field[uname]}
<td class="border-l dark:border-gray-500 p-1 border-gray-300"