From a56191689a66d171184f6134af960127197ed3a5 Mon Sep 17 00:00:00 2001 From: joelte Date: Mon, 16 Nov 2026 11:36:16 +0100 Subject: [PATCH 1/3] feat: Add paging to My Ratings Extract the page counter and chevron arrows from Toolbar into a shared Pagination component, then reuse it on the My Ratings page so rated games are paged the same way as the main grid. --- frontend/src/components/Pagination.module.css | 14 ++++++ frontend/src/components/Pagination.tsx | 45 +++++++++++++++++++ .../src/components/Toolbar/Toolbar.module.css | 15 ------- frontend/src/components/Toolbar/Toolbar.tsx | 41 ++++------------- frontend/src/pages/MyRatings.tsx | 25 ++++++++++- 5 files changed, 90 insertions(+), 50 deletions(-) create mode 100644 frontend/src/components/Pagination.module.css create mode 100644 frontend/src/components/Pagination.tsx diff --git a/frontend/src/components/Pagination.module.css b/frontend/src/components/Pagination.module.css new file mode 100644 index 0000000..ff3bf19 --- /dev/null +++ b/frontend/src/components/Pagination.module.css @@ -0,0 +1,14 @@ +.pagination { + display: inline-flex; + align-items: center; + justify-self: center; + gap: 0.75rem; +} + +.pageButton { + display: inline-flex; + align-items: center; + padding: 0; + color: inherit; + font: inherit; +} diff --git a/frontend/src/components/Pagination.tsx b/frontend/src/components/Pagination.tsx new file mode 100644 index 0000000..4e6a8eb --- /dev/null +++ b/frontend/src/components/Pagination.tsx @@ -0,0 +1,45 @@ +import { Button } from "react-bootstrap"; +import { ChevronLeft, ChevronRight } from "react-bootstrap-icons"; +import styles from "./Pagination.module.css"; + +interface PaginationProps { + page: number; + totalPages: number; + onPrevPage: () => void; + onNextPage: () => void; +} + +export default function Pagination({ + page, + totalPages, + onPrevPage, + onNextPage, +}: PaginationProps) { + return ( +
+ + + Page {page} of {totalPages} + + +
+ ); +} diff --git a/frontend/src/components/Toolbar/Toolbar.module.css b/frontend/src/components/Toolbar/Toolbar.module.css index 901e1a4..d0f4173 100644 --- a/frontend/src/components/Toolbar/Toolbar.module.css +++ b/frontend/src/components/Toolbar/Toolbar.module.css @@ -38,21 +38,6 @@ background-color: var(--color-brand); } -.pagination { - display: inline-flex; - align-items: center; - justify-self: center; - gap: 0.75rem; -} - -.pageButton { - display: inline-flex; - align-items: center; - padding: 0; - color: inherit; - font: inherit; -} - .sort { display: inline-flex; align-items: center; diff --git a/frontend/src/components/Toolbar/Toolbar.tsx b/frontend/src/components/Toolbar/Toolbar.tsx index 4a9fe71..56a597a 100644 --- a/frontend/src/components/Toolbar/Toolbar.tsx +++ b/frontend/src/components/Toolbar/Toolbar.tsx @@ -1,14 +1,7 @@ import { useEffect, useRef, useState } from "react"; import type { ChangeEvent } from "react"; import { Button, Form } from "react-bootstrap"; -import { - ArrowDownUp, - ChevronDown, - ChevronLeft, - ChevronRight, - Funnel, - X, -} from "react-bootstrap-icons"; +import { ArrowDownUp, ChevronDown, Funnel, X } from "react-bootstrap-icons"; import { ESRB_OPTIONS, PLATFORM_OPTIONS, @@ -18,6 +11,7 @@ import { } from "../../constants/filterOptions"; import type { GameFilters, SortField, SortState } from "../../types/gameQuery"; import { EMPTY_FILTERS, hasActiveFilters } from "../../types/gameQuery"; +import Pagination from "../Pagination"; import styles from "./Toolbar.module.css"; interface ToolbarProps { @@ -101,31 +95,12 @@ export default function Toolbar({ )} -
- - - Page {page} of {totalPages} - - -
+
diff --git a/frontend/src/pages/MyRatings.tsx b/frontend/src/pages/MyRatings.tsx index 999bd44..d5a0700 100644 --- a/frontend/src/pages/MyRatings.tsx +++ b/frontend/src/pages/MyRatings.tsx @@ -1,4 +1,4 @@ -import { useMemo } from "react"; +import { useMemo, useState } from "react"; import { gql } from "@apollo/client"; import { useQuery } from "@apollo/client/react"; import Header from "../components/Header"; @@ -7,6 +7,9 @@ import Card from "react-bootstrap/esm/Card"; import StarRating from "../components/StarRating"; import { useIsMobile } from "../constants/global"; import { Link } from "react-router-dom"; +import Pagination from "../components/Pagination"; + +const RATINGS_PAGE_SIZE = 10; const GET_MY_REVIEWS = gql` query GetMyReviews($userId: String!) { @@ -81,6 +84,14 @@ export default function MyRatings() { }) .sort((a, b) => b.score - a.score); + const [rawPage, setPage] = useState(1); + const totalPages = Math.max(1, Math.ceil(ratings.length / RATINGS_PAGE_SIZE)); + const page = Math.min(rawPage, totalPages); + const pagedRatings = ratings.slice( + (page - 1) * RATINGS_PAGE_SIZE, + page * RATINGS_PAGE_SIZE, + ); + return ( <>
@@ -106,9 +117,19 @@ export default function MyRatings() { {!error && !loading && ratings.length === 0 && (

You haven’t rated any games yet.

)} + {!error && !loading && ratings.length > 0 && ( +
+ setPage((p) => Math.max(1, p - 1))} + onNextPage={() => setPage((p) => Math.min(totalPages, p + 1))} + /> +
+ )} {!error && (
- {ratings.map(({ game, score }) => ( + {pagedRatings.map(({ game, score }) => (
Date: Mon, 16 Nov 2026 17:00:13 +0100 Subject: [PATCH 2/3] fix: Update Tests to match frontend Updatet GameListItem and Header tests to match the updates for delivery 4. --- frontend/src/components/GameListItem.test.tsx | 4 ++-- frontend/src/components/Header.test.tsx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/GameListItem.test.tsx b/frontend/src/components/GameListItem.test.tsx index 4244c16..098c814 100644 --- a/frontend/src/components/GameListItem.test.tsx +++ b/frontend/src/components/GameListItem.test.tsx @@ -29,9 +29,9 @@ describe("GameListItem", () => { expect(screen.getByRole("img", { name: "Great Game" })).toHaveAttribute("src", "/game.png"); }); - it("falls back to an em dash when year or tags are missing", () => { + it("falls back to N/A when year or tags are missing", () => { renderItem({ year: null, tags: "" }); - expect(screen.getAllByText("—")).toHaveLength(2); + expect(screen.getAllByText("N/A")).toHaveLength(2); }); it("links to the game's detail page", () => { diff --git a/frontend/src/components/Header.test.tsx b/frontend/src/components/Header.test.tsx index 616f198..31d4cf1 100644 --- a/frontend/src/components/Header.test.tsx +++ b/frontend/src/components/Header.test.tsx @@ -28,7 +28,7 @@ describe("Header", () => { it("renders the wordmark, search field and My Ratings link", () => { renderHeader("/project2"); - expect(screen.getByText("Working Title")).toBeInTheDocument(); + expect(screen.getByText("NTNU GameShelf")).toBeInTheDocument(); expect(screen.getByPlaceholderText("Search games...")).toHaveValue(""); expect(screen.getByText("My Ratings")).toBeInTheDocument(); expect(screen.queryByRole("button", { name: "Clear" })).not.toBeInTheDocument(); @@ -58,7 +58,7 @@ describe("Header", () => { it("links home to the current query on the grid page", () => { renderHeader("/project2?search=zelda"); - expect(screen.getByText("Working Title").closest("a")).toHaveAttribute( + expect(screen.getByText("NTNU GameShelf").closest("a")).toHaveAttribute( "href", "/project2/?search=zelda", ); @@ -67,7 +67,7 @@ describe("Header", () => { it("links home to the persisted grid query from other pages", () => { sessionStorage.setItem(GRID_QUERY_STORAGE_KEY, "search=bar"); renderHeader("/project2/my-ratings"); - expect(screen.getByText("Working Title").closest("a")).toHaveAttribute( + expect(screen.getByText("NTNU GameShelf").closest("a")).toHaveAttribute( "href", "/project2/?search=bar", ); @@ -75,6 +75,6 @@ describe("Header", () => { it("links home plainly when there is no persisted query", () => { renderHeader("/project2/my-ratings"); - expect(screen.getByText("Working Title").closest("a")).toHaveAttribute("href", "/project2"); + expect(screen.getByText("NTNU GameShelf").closest("a")).toHaveAttribute("href", "/project2"); }); }); From ddb97a40ecad25d991388983dcf130600f8eacf6 Mon Sep 17 00:00:00 2001 From: Ayse Zeynep Aydin Date: Mon, 16 Nov 2026 17:55:58 +0100 Subject: [PATCH 3/3] arrowupdown color fix and refactor --- frontend/src/components/Pagination.module.css | 14 -------------- frontend/src/components/Pagination.tsx | 10 ++++++---- frontend/src/components/Toolbar/Toolbar.tsx | 3 ++- 3 files changed, 8 insertions(+), 19 deletions(-) delete mode 100644 frontend/src/components/Pagination.module.css diff --git a/frontend/src/components/Pagination.module.css b/frontend/src/components/Pagination.module.css deleted file mode 100644 index ff3bf19..0000000 --- a/frontend/src/components/Pagination.module.css +++ /dev/null @@ -1,14 +0,0 @@ -.pagination { - display: inline-flex; - align-items: center; - justify-self: center; - gap: 0.75rem; -} - -.pageButton { - display: inline-flex; - align-items: center; - padding: 0; - color: inherit; - font: inherit; -} diff --git a/frontend/src/components/Pagination.tsx b/frontend/src/components/Pagination.tsx index 4e6a8eb..a99869c 100644 --- a/frontend/src/components/Pagination.tsx +++ b/frontend/src/components/Pagination.tsx @@ -1,6 +1,5 @@ import { Button } from "react-bootstrap"; import { ChevronLeft, ChevronRight } from "react-bootstrap-icons"; -import styles from "./Pagination.module.css"; interface PaginationProps { page: number; @@ -16,10 +15,12 @@ export default function Pagination({ onNextPage, }: PaginationProps) { return ( -
+