|
76 | 76 | class="row-span-2" |
77 | 77 | loading="lazy" |
78 | 78 | format="avif,webp" |
79 | | - src="/illustrations/tinkering-in-the-garden.png" |
80 | | - sizes="150px md:300px" |
| 79 | + :src=" |
| 80 | + isChristmas() |
| 81 | + ? `/illustrations/tree-needs-power.png` |
| 82 | + : `/illustrations/tinkering-in-the-garden.png` |
| 83 | + " |
| 84 | + :sizes="isChristmas() ? '120px md:200px' : '150px md:300px'" |
81 | 85 | alt="Mint tinkering in the garden" |
82 | 86 | /> |
83 | 87 | <p class="font-bold self-end">Aurrrr naurrr!!!</p> |
84 | 88 | <p class="col-start-2"> |
85 | 89 | There was an error trying to fetch your scroll. Whack that reload |
86 | 90 | button and try again. |
| 91 | + <NuxtLink to="/statistics#api-requests"> |
| 92 | + Go here to check if Dragon Cave is having issues</NuxtLink |
| 93 | + >. |
87 | 94 | </p> |
88 | 95 | </div> |
89 | 96 | <template v-else> |
|
276 | 283 | /> |
277 | 284 | </form> |
278 | 285 |
|
| 286 | + <template v-if="isChristmas()"> |
| 287 | + <div ref="formEnd" aria-hidden="true" class="h-px !m-0" /> |
| 288 | + <Transition |
| 289 | + class="transition-opacity duration-300" |
| 290 | + enter-from-class="opacity-0" |
| 291 | + enter-to-class="opacity-100" |
| 292 | + > |
| 293 | + <div |
| 294 | + v-if="scrollUpdated && isChristmas()" |
| 295 | + class="px-4 max-w-prose justify-items-center text-center grid items-center gap-x-4 !mx-auto sm:grid-cols-[auto_1fr] sm:text-left sm:justify-items-start" |
| 296 | + > |
| 297 | + <NuxtPicture |
| 298 | + class="row-span-2" |
| 299 | + loading="lazy" |
| 300 | + format="avif,webp" |
| 301 | + src="/illustrations/wrapping-presents.png" |
| 302 | + sizes="120px md:200px" |
| 303 | + alt="Matthias wrapping eggs" |
| 304 | + /> |
| 305 | + <p class="font-bold self-end">{{ getUpdatedTexts() }}</p> |
| 306 | + <p class="col-start-2"> |
| 307 | + While you're here... why not give the gift of clicks this Christmas? |
| 308 | + </p> |
| 309 | + </div> |
| 310 | + </Transition> |
| 311 | + </template> |
| 312 | + |
279 | 313 | <section class="space-y-2"> |
280 | 314 | <h2 class="text-2xl text-white">Seed tray</h2> |
281 | 315 | <HatcheryView |
|
364 | 398 |
|
365 | 399 | <script lang="ts" setup> |
366 | 400 | import { pluralise } from '#imports'; |
| 401 | +import { useElementVisibility } from '@vueuse/core'; |
367 | 402 | import ScrollTable from '~/components/ScrollTable.vue'; |
368 | 403 | import WarningNewRelease from '~/components/WarningNewRelease.vue'; |
| 404 | +import isChristmas from '~/utils/isChristmas'; |
369 | 405 | import type { userNotificationTable } from '~~/database/schema'; |
370 | 406 | import HappyMatthias from '~~/public/npc/happy_matthias.webp'; |
371 | 407 |
|
372 | 408 | const { data: authData, signIn } = useAuth(); |
373 | 409 | const { userSettings } = useUserSettings(true); |
374 | 410 |
|
| 411 | +const scrollUpdated = ref(false); |
| 412 | +
|
| 413 | +const savedDragons = reactive({ |
| 414 | + seedTray: 0, |
| 415 | + garden: 0, |
| 416 | +}); |
| 417 | +
|
| 418 | +const formEndVisible = useElementVisibility(useTemplateRef('formEnd'), { |
| 419 | + threshold: 0, |
| 420 | +}); |
| 421 | +
|
375 | 422 | const { |
376 | 423 | data: scroll, |
377 | 424 | execute: fetchScroll, |
@@ -418,34 +465,33 @@ const { |
418 | 465 | inGarden: dragon.inGarden, |
419 | 466 | })) |
420 | 467 | ), |
421 | | - onResponse({ response }) { |
| 468 | + async onResponse({ response }) { |
422 | 469 | if (!response.ok) { |
423 | 470 | toast.error('Failed to save your scroll. Please try again.'); |
| 471 | + scrollUpdated.value = false; |
424 | 472 | return; |
425 | 473 | } |
426 | 474 |
|
427 | | - const seedTray = scroll.value.dragons.filter((dragon) => dragon.inSeedTray); |
428 | | - const garden = scroll.value.dragons.filter((dragon) => dragon.inGarden); |
429 | | - const texts = []; |
| 475 | + savedDragons.seedTray = scroll.value.dragons.filter( |
| 476 | + (dragon) => dragon.inSeedTray |
| 477 | + ).length; |
430 | 478 |
|
431 | | - if (seedTray.length > 0) { |
432 | | - texts.push( |
433 | | - `${seedTray.length} ${pluralise('dragon', seedTray.length)} in the seed tray` |
| 479 | + savedDragons.garden = scroll.value.dragons.filter( |
| 480 | + (dragon) => dragon.inGarden |
| 481 | + ).length; |
| 482 | +
|
| 483 | + scrollUpdated.value = true; |
| 484 | +
|
| 485 | + console.log('formEndVisible', formEndVisible.value); |
| 486 | +
|
| 487 | + if (!formEndVisible.value) { |
| 488 | + toast.success( |
| 489 | + `${getUpdatedTexts()} <img class="inline" src="${HappyMatthias}" alt="Happy Matthias" />`, |
| 490 | + { |
| 491 | + dangerouslyHTMLString: true, |
| 492 | + } |
434 | 493 | ); |
435 | 494 | } |
436 | | -
|
437 | | - texts.push( |
438 | | - `${garden.length > 0 ? garden.length : 'no'} ${pluralise('dragon', garden.length)} in the garden` |
439 | | - ); |
440 | | - toast.success( |
441 | | - 'Scroll updated! You have ' + |
442 | | - texts.join(' and ') + |
443 | | - `. <img class="inline" src="${HappyMatthias}" alt="Happy Matthias" />`, |
444 | | - { |
445 | | - dangerouslyHTMLString: true, |
446 | | - } |
447 | | - ); |
448 | | - return; |
449 | 495 | }, |
450 | 496 | }); |
451 | 497 |
|
@@ -553,4 +599,20 @@ function toggleAll(checked: boolean) { |
553 | 599 | } |
554 | 600 | }); |
555 | 601 | } |
| 602 | +
|
| 603 | +function getUpdatedTexts(): string { |
| 604 | + const texts: string[] = []; |
| 605 | +
|
| 606 | + if (savedDragons.seedTray > 0) { |
| 607 | + texts.push( |
| 608 | + `${savedDragons.seedTray} ${pluralise('dragon', savedDragons.seedTray)} in the seed tray` |
| 609 | + ); |
| 610 | + } |
| 611 | +
|
| 612 | + texts.push( |
| 613 | + `${savedDragons.garden > 0 ? savedDragons.garden : 'no'} ${pluralise('dragon', savedDragons.garden)} in the garden` |
| 614 | + ); |
| 615 | +
|
| 616 | + return 'Scroll updated! You have ' + texts.join(' and ') + `.`; |
| 617 | +} |
556 | 618 | </script> |
0 commit comments