diff --git a/src/lib/data.ts b/src/lib/data.ts index bf92eed3b24fb43f0dbdea15f39b15429fc843e7..a4a3336879c9713b35331078a78406601b8d1c44 100644 --- a/src/lib/data.ts +++ b/src/lib/data.ts @@ -24,6 +24,7 @@ async function cacheImages(users: UserId[]): Promise<void> { if (!photo?.url) continue; await fetch(photo.url, { method: 'HEAD' }); } + console.log('cached', users.length, 'images'); } async function fetchPromotion(year: number): Promise<PromoCache> { @@ -54,7 +55,7 @@ export async function* promotionIterator( min: number, max: number ): AsyncGenerator<UserId, void, undefined> { - for (let i = min; i < max; i++) { + for (let i = min; i <= max; i++) { const promotion = await getPromotion(i); yield* promotion; } diff --git a/src/lib/game.ts b/src/lib/game.ts index dcd2697a876147c51d4c9ecdb2d04f56647b8eae..e20f14d9977ea52a95fa9483abcf7e5f7d17309b 100644 --- a/src/lib/game.ts +++ b/src/lib/game.ts @@ -32,6 +32,7 @@ export class Game { constructor(protected cookies: Cookies) { this.cookie = new SecureCookie(cookies, gameStateSchema, this.cookie_name); this.state = this.cookie.read() ?? this.defaultState(); + // console.log('LOAD:', GameStage[this.state.stage], this.state); } protected defaultState(): GameState { @@ -48,6 +49,7 @@ export class Game { } save() { + // console.log('SAVE:', GameStage[this.state.stage], this.state); this.cookie.write(this.state); } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c92a033577a09462f8d171059cc79323ff802668..7a0f532fe4db3700524f1ba14b6a0a2ad7902c7a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,8 +1,5 @@ export function getRandomItems<T>(array: T[], count: number): T[] { - if (count === 0) return []; - if (count > array.length) { - throw new Error('Count is greater than the size of the set'); - } + if (count === 0 || array.length === 0) return []; const index = Math.floor(Math.random() * array.length); const item = array[index]; array.splice(index, 1); diff --git a/src/routes/quiz/+page.server.ts b/src/routes/quiz/+page.server.ts index 943b4f0f61836b71ec6a298dab4b224ad729bfa0..db2214e69bd15b9cb7ca228d35fbe3116ada9a53 100644 --- a/src/routes/quiz/+page.server.ts +++ b/src/routes/quiz/+page.server.ts @@ -37,24 +37,21 @@ export async function load(event) { break; case GameStage.NEXT: await next(game.state); + game.save(); break; } - const details = await client - .query(USER_DETAILS_QUERY, { idList: game.state.options }) - .toPromise(); - + const details = await client.query(USER_DETAILS_QUERY, { idList: game.state.options }); handleGqlError(details); const users = details.data!.page.nodes ?? []; const options: Option[] = users.map((node) => ({ label: node.nickname!, value: node.id })) ?? []; - game.save(); - const photo = users.find((node) => node.id === game.state.solution)?.photo; const form = await superValidate(zod(schema)); + return { form, options, diff --git a/src/routes/quiz/new/+page.server.ts b/src/routes/quiz/new/+page.server.ts index f839073e5defb3d2beca3fd9e544b55ecc736230..8eeb72bd2ebbf4d863b168f5fa43c7652f500bdc 100644 --- a/src/routes/quiz/new/+page.server.ts +++ b/src/routes/quiz/new/+page.server.ts @@ -29,45 +29,45 @@ export async function load(event) { { year: 1, name: '1A', - image: images.baby + image: images.stroller }, { year: 2, name: '2A', - image: images.baby + image: images.running }, { year: 3, name: '3A', - image: images.student + image: images.stickFighting }, { year: 1, maxYear: 3, name: '1-3A', - image: images.student + image: images.conferenceCall }, { year: 4, name: '4A', - image: images.student + image: images.certificate }, { year: 5, name: '5A', - image: images.student + image: images.wallet }, { year: 4, maxYear: VIIEUX_YEAR, name: 'Viieux', - image: images.student + image: images.elderlyPerson }, { year: 1, maxYear: VIIEUX_YEAR, name: 'IIEns', - image: images.student + image: images.crowd } ]; diff --git a/src/routes/quiz/new/+page.svelte b/src/routes/quiz/new/+page.svelte index d7bc2c15f12787e3e40aed0f52befe904b0c31f1..da4628add3d09c66d134acc203ca60dd9f024150 100644 --- a/src/routes/quiz/new/+page.svelte +++ b/src/routes/quiz/new/+page.svelte @@ -11,8 +11,8 @@ const { enhance } = form; </script> -<div class="m-16"> - <div class="flex flex-wrap items-center justify-center gap-8 text-gray-700"> +<div class="my-auto p-8 sm:p-16"> + <div class="flex flex-wrap items-center justify-center gap-4 text-gray-700 sm:gap-8"> {#each data.levels as level} <form method="post" use:enhance> <Field {form} name="year"> @@ -32,12 +32,12 @@ </Field> <button type="submit" - class="col-span-1 flex h-72 w-72 flex-col divide-y divide-gray-200 rounded-2xl border-6 border-solid border-zinc-800 bg-slate-100 text-center shadow transition-[0.45s] hover:translate-y-[-3px] hover:bg-slate-300 focus:border-indigo-500" + class="col-span-1 flex h-36 w-36 flex-col divide-y divide-gray-200 rounded-2xl border-6 border-solid border-zinc-800 bg-slate-100 text-center shadow transition-[0.45s] hover:translate-y-[-3px] hover:bg-slate-300 focus:border-indigo-500 sm:h-72 sm:w-72" > - <div class="flex flex-1 flex-col p-8"> - <img class="mx-auto h-32 w-32 flex-shrink-0" src={level.image} alt="" /> - <h1 class="mt-4 text-6xl font-medium">{level.name}</h1> - <dl class="mt-1 flex flex-grow flex-col justify-between"> + <div class="flex flex-1 flex-col p-2 sm:p-8"> + <img class="mx-auto h-16 flex-shrink-0 sm:h-32 sm:w-32" src={level.image} alt="" /> + <h1 class="mt-1 text-2xl font-medium sm:mt-4 sm:text-6xl">{level.name}</h1> + <dl class="flex flex-grow flex-col justify-between sm:mt-1"> <dd class="text-sm font-light text-gray-500">{level.size} personnes</dd> </dl> </div> diff --git a/src/routes/quiz/new/images/baby.png b/src/routes/quiz/new/images/baby.png deleted file mode 100644 index 60d09632825cea2366b7f0f19f7f2802ec29042c..0000000000000000000000000000000000000000 Binary files a/src/routes/quiz/new/images/baby.png and /dev/null differ diff --git a/src/routes/quiz/new/images/certificate.png b/src/routes/quiz/new/images/certificate.png new file mode 100644 index 0000000000000000000000000000000000000000..5e5682b03f8a1cc5b869af1ab019b6f185d87e50 Binary files /dev/null and b/src/routes/quiz/new/images/certificate.png differ diff --git a/src/routes/quiz/new/images/conference-call.png b/src/routes/quiz/new/images/conference-call.png new file mode 100644 index 0000000000000000000000000000000000000000..2594c20613134712b1262a1302b30761456964de Binary files /dev/null and b/src/routes/quiz/new/images/conference-call.png differ diff --git a/src/routes/quiz/new/images/crowd.png b/src/routes/quiz/new/images/crowd.png new file mode 100644 index 0000000000000000000000000000000000000000..e324420f53f76da8ed08ac07b025709ae646d315 Binary files /dev/null and b/src/routes/quiz/new/images/crowd.png differ diff --git a/src/routes/quiz/new/images/elderly-person.png b/src/routes/quiz/new/images/elderly-person.png new file mode 100644 index 0000000000000000000000000000000000000000..c58b9cfdac86f7b68b8569836fcd786390a6d950 Binary files /dev/null and b/src/routes/quiz/new/images/elderly-person.png differ diff --git a/src/routes/quiz/new/images/index.ts b/src/routes/quiz/new/images/index.ts index a947a639425f81e7eb45c8e11b46e1c8ba4f5810..9cc1875aadfbb2ef92aa15b616f932650657ab1f 100644 --- a/src/routes/quiz/new/images/index.ts +++ b/src/routes/quiz/new/images/index.ts @@ -1,7 +1,19 @@ -import baby from './baby.png'; -import student from './student.png'; +import elderlyPerson from './elderly-person.png'; +import crowd from './crowd.png'; +import stroller from './stroller.png'; +import wallet from './wallet.png'; +import conferenceCall from './conference-call.png'; +import certificate from './certificate.png'; +import running from './running.png'; +import stickFighting from './stick-fighting.png'; export default { - baby, - student + elderlyPerson, + crowd, + stroller, + wallet, + conferenceCall, + certificate, + running, + stickFighting }; diff --git a/src/routes/quiz/new/images/running.png b/src/routes/quiz/new/images/running.png new file mode 100644 index 0000000000000000000000000000000000000000..afbb12a81a44c009762f1cff9919e897c59198e6 Binary files /dev/null and b/src/routes/quiz/new/images/running.png differ diff --git a/src/routes/quiz/new/images/stick-fighting.png b/src/routes/quiz/new/images/stick-fighting.png new file mode 100644 index 0000000000000000000000000000000000000000..c36060f3a9484decb6613b75608f80b3a56e8e34 Binary files /dev/null and b/src/routes/quiz/new/images/stick-fighting.png differ diff --git a/src/routes/quiz/new/images/stroller.png b/src/routes/quiz/new/images/stroller.png new file mode 100644 index 0000000000000000000000000000000000000000..214794cf73cab8a45babd1437a696a471b1215bb Binary files /dev/null and b/src/routes/quiz/new/images/stroller.png differ diff --git a/src/routes/quiz/new/images/student.png b/src/routes/quiz/new/images/student.png deleted file mode 100644 index 4df8222c20902f02cdb712ab556b047e1fa2ad68..0000000000000000000000000000000000000000 Binary files a/src/routes/quiz/new/images/student.png and /dev/null differ diff --git a/src/routes/quiz/new/images/wallet.png b/src/routes/quiz/new/images/wallet.png new file mode 100644 index 0000000000000000000000000000000000000000..92aceb444fcab5f82dfb472e98097a29367b288e Binary files /dev/null and b/src/routes/quiz/new/images/wallet.png differ