From 9585e84d899567e34cdf620d89087f2376a9a729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 9 Nov 2026 11:41:11 +0100 Subject: [PATCH 1/2] Refill the not voted list once its page is empty --- .../controllers/not-voted-list-controller.js | 14 ++++++ src/Controller/QotdController.php | 7 ++- templates/components/QotdCard.html.twig | 2 +- templates/qotd/index.html.twig | 18 ++++---- tests/Controller/QotdControllerTest.php | 43 ++++++++++++++++--- 5 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 assets/controllers/not-voted-list-controller.js diff --git a/assets/controllers/not-voted-list-controller.js b/assets/controllers/not-voted-list-controller.js new file mode 100644 index 0000000..f77d439 --- /dev/null +++ b/assets/controllers/not-voted-list-controller.js @@ -0,0 +1,14 @@ +import { Controller } from '@hotwired/stimulus'; +import { visit } from '@hotwired/turbo'; + +export default class extends Controller { + static targets = ['card']; + static values = { url: String }; + + // A voted card leaves the list: without any card left, the page has nothing to offer but stale links + cardTargetDisconnected() { + if (!this.hasCardTarget) { + visit(this.urlValue, { action: 'replace' }); + } + } +} diff --git a/src/Controller/QotdController.php b/src/Controller/QotdController.php index e4ced68..0fa8722 100644 --- a/src/Controller/QotdController.php +++ b/src/Controller/QotdController.php @@ -61,13 +61,18 @@ public function index( #[Route('/not-voted', name: 'qotd_index_not_voted', options: ['expose' => true])] #[Template('qotd/index.html.twig')] - public function notVoted(#[CurrentUser] UserInterface $user): array + public function notVoted(#[CurrentUser] UserInterface $user): array|Response { $pagination = $this ->qotdRepository ->findForHomepageNotVoted($user) ; + // The QOTD on the other side of the cursor may all have been voted since the link was rendered + if ($pagination->isEmpty() && null !== $pagination->getCursor()) { + return $this->redirectToRoute('qotd_index_not_voted'); + } + return [ 'pagination' => $pagination, 'direction' => QotdDirection::NotVoted, diff --git a/templates/components/QotdCard.html.twig b/templates/components/QotdCard.html.twig index 9414e8a..7d865c7 100644 --- a/templates/components/QotdCard.html.twig +++ b/templates/components/QotdCard.html.twig @@ -1,6 +1,6 @@ {% import 'macros/qotd/message.html.twig' as qotd_macro %} -
+
{{ qotd_macro.message(qotd) }} {% for imageUrl in qotd.imageUrls %} diff --git a/templates/qotd/index.html.twig b/templates/qotd/index.html.twig index ab4a866..6ba1bfc 100644 --- a/templates/qotd/index.html.twig +++ b/templates/qotd/index.html.twig @@ -29,15 +29,17 @@ {% endif %} - {% for qotd in pagination %} - - {% else %} -
-
- {{ 'No QOTD found.'|trans }} +
+ {% for qotd in pagination %} + + {% else %} +
+
+ {{ 'No QOTD found.'|trans }} +
-
- {% endfor %} + {% endfor %} +