From 8d5aeec457fe0141f24d7c37dcac2cb3a1a51cad Mon Sep 17 00:00:00 2001 From: carmennt Date: Tue, 17 Nov 2026 18:31:27 +0100 Subject: [PATCH 1/5] fix: seperate ActiveGameCard Seperating ActiveGameGard into 3 components, ActiveGameCard, ActiveGameCardInfo and ActiveGameCardReviews --- .../ActiveGameCard/ActiveGameCard.css | 47 ------- .../ActiveGameCard/ActiveGameCard.tsx | 123 +----------------- .../ActiveGameCardInfo/ActiveGameCardInfo.css | 44 +++++++ .../ActiveGameCardInfo/ActiveGameCardInfo.tsx | 64 +++++++++ .../ActiveGameCardReviews.css | 11 ++ .../ActiveGameCardReviews.tsx | 74 +++++++++++ 6 files changed, 199 insertions(+), 164 deletions(-) create mode 100644 Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css create mode 100644 Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx create mode 100644 Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css create mode 100644 Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx diff --git a/Frontend/src/components/ActiveGameCard/ActiveGameCard.css b/Frontend/src/components/ActiveGameCard/ActiveGameCard.css index a2efe63..9493863 100644 --- a/Frontend/src/components/ActiveGameCard/ActiveGameCard.css +++ b/Frontend/src/components/ActiveGameCard/ActiveGameCard.css @@ -49,33 +49,6 @@ gap: 1.25rem; } -.activeGameInfoCard, -.activeGameReviewsCard { - min-width: 0; - background-color: var(--primary-component-color) !important; - color: var(--primary-text-color); - box-shadow: var(--card-shadow); -} - -.activeGameReviewsCard { - display: flex; - min-height: 0; -} - -.activeGameInfoContent.MuiCardContent-root { - display: flex; - flex-direction: column; - gap: 1rem; - padding: 1.25rem; -} - -.activeGameInfoHeader { - display: flex; - align-items: center; - justify-content: space-between; - gap: 1rem; -} - .activeGameTitle { min-width: 0; margin: 0; @@ -138,12 +111,6 @@ font-weight: 700; } -.activeGameInfoMiddle { - display: flex; - flex-direction: column; - gap: 1rem; -} - .activeGameDeveloper { line-height: 1.5; } @@ -165,11 +132,6 @@ color: var(--primary-text-color); } -.activeGameInfoContent .MuiDivider-root { - width: 100%; - border-color: rgb(0 0 0 / 20%); -} - @media (max-width: 64rem) { .activeGameLayout { margin-block: 1rem; @@ -180,18 +142,9 @@ align-items: start; gap: 1rem; } - - .activeGameInfoContent.MuiCardContent-root { - padding: 1.125rem; - } } @media (max-width: 26rem) { - .activeGameInfoHeader { - align-items: flex-start; - flex-direction: column; - } - .activeGamePriceGroup { justify-content: flex-start; } diff --git a/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx b/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx index 35b15c2..205f180 100644 --- a/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx +++ b/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx @@ -1,4 +1,4 @@ -import { Box, Button, Card, CardContent, CardMedia, Chip, Divider, Typography } from '@mui/material' +import { Box, Button, Card, CardMedia } from '@mui/material' import './ActiveGameCard.css' import type { GameData } from '../../types/Game' import { GetSavedUser } from '../../FrontendLogic/UserLogicFrontend' @@ -8,15 +8,8 @@ import { AddToWishlistFrontend, FetchWishlistFrontend } from '../../FrontendLogic/WishlistLogicFrontend' -import { - CreateReview, - DeleteReview, - GetReviewsForGame, - UpdateReview -} from '../../FrontendLogic/ReviewLogicFrontend' -import type { Review } from '../../types/Review' -import Reviews from '../Reviews/Reviews' -import { UseAuth } from '../../context/AuthContext' +import ActiveGameCardInfo from '../ActiveGameCardInfo/ActiveGameCardInfo.tsx' +import ActiveGameCardReviews from '../ActiveGameCardReviews/ActiveGameCardReviews.tsx' type ActiveGameCardProps = { game: GameData @@ -29,60 +22,13 @@ export default function ActiveGameCard({ onAddToWishlist, onRemoveFromWishlist }: ActiveGameCardProps) { - const { user } = UseAuth() const [isWishlisted, setIsWishlisted] = useState(false) const [isChecking, setIsChecking] = useState(() => GetSavedUser() !== null) const [isBusy, setIsBusy] = useState(false) const [error, setError] = useState(null) - const [reviews, setReviews] = useState([]) - const [reviewError, setReviewError] = useState(null) - const currentUserId = user?.id ?? null const isLoggedIn = GetSavedUser() !== null - const isOnSale = - game.salePercent !== undefined && game.salePercent > 0 && game.salePercent <= 100 - const showOriginalPrice = - isOnSale && game.originalPrice !== undefined && game.originalPrice > game.price - - //Loads the game's reviews, again when the user signs in or out so their own review comes first - useEffect(() => { - let cancelled = false - - GetReviewsForGame(game.id, currentUserId) - .then((loadedReviews) => { - if (cancelled) return - setReviews(loadedReviews) - setReviewError(null) - }) - .catch((loadError: unknown) => { - if (!cancelled) { - setReviewError( - loadError instanceof Error ? loadError.message : 'Could not load reviews.' - ) - } - }) - - return () => { - cancelled = true - } - }, [game.id, currentUserId]) - - async function HandleSubmitReview(rating: number, text: string) { - if (!user) throw new Error('Sign in to submit a review.') - setReviews(await CreateReview(game.id, user.id, rating, text)) - } - - async function HandleEditReview(reviewId: number, rating: number, text: string) { - if (!user) throw new Error('Sign in to edit a review.') - setReviews(await UpdateReview(game.id, reviewId, user.id, rating, text)) - } - - async function HandleDeleteReview(reviewId: number) { - if (!user) throw new Error('Sign in to delete a review.') - setReviews(await DeleteReview(game.id, reviewId, user.id)) - } - // Finds out if the signed in user already has this game on their wishlist useEffect(() => { let cancelled = false @@ -135,7 +81,7 @@ export default function ActiveGameCard({ } return ( - + )} - - - - - {game.name} - - - {isOnSale && ( - - )} - - {game.price.toFixed(2)} $ - - {showOriginalPrice && ( - - - Original price:{' '} - - {game.originalPrice!.toFixed(2)} $ - - )} - - - - - - {game.description} - - - - - {game.genre.map((genre) => ( - - ))} - - - - - - + + ) diff --git a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css new file mode 100644 index 0000000..3716887 --- /dev/null +++ b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css @@ -0,0 +1,44 @@ +.activeGameInfoCard { + min-width: 0; + background-color: var(--primary-component-color) !important; + color: var(--primary-text-color); + box-shadow: var(--card-shadow); +} + +.activeGameInfoContent.MuiCardContent-root { + display: flex; + flex-direction: column; + gap: 1rem; + padding: 1.25rem; +} + +.activeGameInfoHeader { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1rem; +} + +.activeGameInfoMiddle { + display: flex; + flex-direction: column; + gap: 1rem; +} + +.activeGameInfoContent .MuiDivider-root { + width: 100%; + border-color: rgb(0 0 0 / 20%); +} + +@media (max-width: 64rem) { + .activeGameInfoContent.MuiCardContent-root { + padding: 1.125rem; + } +} + +@media (max-width: 26rem) { + .activeGameInfoHeader { + align-items: flex-start; + flex-direction: column; + } +} \ No newline at end of file diff --git a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx new file mode 100644 index 0000000..a87b53d --- /dev/null +++ b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx @@ -0,0 +1,64 @@ +import { Box, Card, CardContent, Chip, Divider, Typography } from '@mui/material' +import './ActiveGameCardInfo.css' +import type { GameData } from '../../types/Game' + +type ActiveGameInfoProps = { + game: GameData +} + +export default function ActiveGameCardInfo({ game }: ActiveGameInfoProps) { + const isOnSale = + game.salePercent !== undefined && game.salePercent > 0 && game.salePercent <= 100 + const showOriginalPrice = + isOnSale && game.originalPrice !== undefined && game.originalPrice > game.price + + return ( + + + + + {game.name} + + + {isOnSale && ( + + )} + + {game.price.toFixed(2)} $ + + {showOriginalPrice && ( + + Original price: + {game.originalPrice!.toFixed(2)} $ + + )} + + + + + + {game.description} + + + + + {game.genre.map((genre) => ( + + ))} + + + + ) +} \ No newline at end of file diff --git a/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css new file mode 100644 index 0000000..9b7aae3 --- /dev/null +++ b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css @@ -0,0 +1,11 @@ +.activeGameReviewsCard { + min-width: 0; + background-color: var(--primary-component-color) !important; + color: var(--primary-text-color); + box-shadow: var(--card-shadow); +} + +.activeGameReviewsCard { + display: flex; + min-height: 0; +} \ No newline at end of file diff --git a/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx new file mode 100644 index 0000000..9d4a40a --- /dev/null +++ b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx @@ -0,0 +1,74 @@ +import { Card } from '@mui/material' +import './ActiveGameCardReviews.css' +import { useState, useEffect } from 'react' +import { + CreateReview, + DeleteReview, + GetReviewsForGame, + UpdateReview +} from '../../FrontendLogic/ReviewLogicFrontend' +import type { Review } from '../../types/Review' +import Reviews from '../Reviews/Reviews' +import { UseAuth } from '../../context/AuthContext' + +type ActiveGameReviewsProps = { + gameId: number +} + +export default function ActiveGameCardReviews({ gameId }: ActiveGameReviewsProps) { + const { user } = UseAuth() + const [reviews, setReviews] = useState([]) + const [reviewError, setReviewError] = useState(null) + const currentUserId = user?.id ?? null + + // Loads the game's reviews, again when the user signs in or out so their own review comes first + useEffect(() => { + let cancelled = false + + GetReviewsForGame(gameId, currentUserId) + .then((loadedReviews) => { + if (cancelled) return + setReviews(loadedReviews) + setReviewError(null) + }) + .catch((loadError: unknown) => { + if (!cancelled) { + setReviewError( + loadError instanceof Error ? loadError.message : 'Could not load reviews.' + ) + } + }) + + return () => { + cancelled = true + } + }, [gameId, currentUserId]) + + async function HandleSubmitReview(rating: number, text: string) { + if (!user) throw new Error('Sign in to submit a review.') + setReviews(await CreateReview(gameId, user.id, rating, text)) + } + + async function HandleEditReview(reviewId: number, rating: number, text: string) { + if (!user) throw new Error('Sign in to edit a review.') + setReviews(await UpdateReview(gameId, reviewId, user.id, rating, text)) + } + + async function HandleDeleteReview(reviewId: number) { + if (!user) throw new Error('Sign in to delete a review.') + setReviews(await DeleteReview(gameId, reviewId, user.id)) + } + + return ( + + + + ) +} \ No newline at end of file From 941067b33225979658da2d61668b6426a2bc9b56 Mon Sep 17 00:00:00 2001 From: carmennt Date: Tue, 17 Nov 2026 18:33:30 +0100 Subject: [PATCH 2/5] fix: replace all gamepage with GamePage --- E2E/Mainpage.spec.ts | 2 +- E2E/MainpageToGamepage.spec.ts | 2 +- E2E/Reviews.spec.ts | 2 +- E2E/Wishlist.spec.ts | 6 +++--- E2E/helpers.ts | 2 +- Frontend/App.tsx | 2 +- Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx | 2 +- Frontend/src/components/ReviewCard/ReviewCard.tsx | 2 +- .../src/components/WishlistGameCard/WishlistGameCard.tsx | 2 +- Frontend/src/tests/MainPage.test.tsx | 2 +- Frontend/src/tests/RecentReviews.test.tsx | 2 +- Frontend/src/tests/ReviewCard.test.tsx | 2 +- Frontend/src/tests/UserReviews.test.tsx | 4 ++-- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/E2E/Mainpage.spec.ts b/E2E/Mainpage.spec.ts index 0ffd9b5..0af3207 100644 --- a/E2E/Mainpage.spec.ts +++ b/E2E/Mainpage.spec.ts @@ -2,7 +2,7 @@ import { test, expect } from './fixtures' import { openMainPage, testCarousel } from './helpers' -const GAME_PAGE = /#\/gamepage\/\d+$/ +const GAME_PAGE = /#\/GamePage\/\d+$/ async function checkFeaturedGames(page: import('@playwright/test').Page) { const section = page diff --git a/E2E/MainpageToGamepage.spec.ts b/E2E/MainpageToGamepage.spec.ts index 07de9db..1b8650d 100644 --- a/E2E/MainpageToGamepage.spec.ts +++ b/E2E/MainpageToGamepage.spec.ts @@ -3,7 +3,7 @@ import { test, expect } from './fixtures' import { openMainPage } from './helpers' import type { Page } from '@playwright/test' -const GAME_PAGE = /#\/gamepage\/\d+$/ +const GAME_PAGE = /#\/GamePage\/\d+$/ const WISHLIST_PAGE = /#\/WishlistPage$/ async function openTopGameAndToggleWishlist(page: Page) { diff --git a/E2E/Reviews.spec.ts b/E2E/Reviews.spec.ts index c1e14b5..decb2e9 100644 --- a/E2E/Reviews.spec.ts +++ b/E2E/Reviews.spec.ts @@ -3,7 +3,7 @@ import { test, expect } from './fixtures' import { openMainPage } from './helpers' import type { Page } from '@playwright/test' -const GAME_PAGE = /#\/gamepage\/\d+$/ +const GAME_PAGE = /#\/GamePage\/\d+$/ async function navigateFromRecentReviewToGame( page: Page, diff --git a/E2E/Wishlist.spec.ts b/E2E/Wishlist.spec.ts index 7d3c0c7..4eed4e1 100644 --- a/E2E/Wishlist.spec.ts +++ b/E2E/Wishlist.spec.ts @@ -4,7 +4,7 @@ import { openMainPage } from './helpers' import type { Page } from '@playwright/test' const WISHLIST_PAGE = /#\/WishlistPage$/ -const GAME_PAGE = /#\/gamepage\/\d+$/ +const GAME_PAGE = /#\/GamePage\/\d+$/ async function openDesktopWishlistPage( page: Page, @@ -48,7 +48,7 @@ async function waitForWishlistPage(page: Page) { } async function openWishlistedGameAndGoBack(page: Page) { - const firstGame = page.locator('a[href*="gamepage"]').first() + const firstGame = page.locator('a[href*="GamePage"]').first() await expect(firstGame).toBeVisible() await firstGame.click() @@ -78,7 +78,7 @@ async function sortWishlistGames(page: Page) { } async function removeGameFromWishlist(page: Page) { - const firstGame = page.locator('a[href*="gamepage"]').first() + const firstGame = page.locator('a[href*="GamePage"]').first() await expect(firstGame).toBeVisible() diff --git a/E2E/helpers.ts b/E2E/helpers.ts index 1de3ce2..71e666d 100644 --- a/E2E/helpers.ts +++ b/E2E/helpers.ts @@ -36,7 +36,7 @@ export async function testCarousel(page: Page, heading: string) { }) const gameCards = section.locator( - '.genre-games-row a[href*="gamepage/"]' + '.genre-games-row a[href*="GamePage/"]' ) await expect(nextButton).toBeVisible() diff --git a/Frontend/App.tsx b/Frontend/App.tsx index a83d330..b084660 100644 --- a/Frontend/App.tsx +++ b/Frontend/App.tsx @@ -16,7 +16,7 @@ function App() { } /> } /> - } /> + } /> } /> } /> } /> diff --git a/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx b/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx index 7e65127..be5e738 100644 --- a/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx +++ b/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx @@ -51,7 +51,7 @@ export default function PassiveGameCard({ game, rank }: Props) { + See this game )} diff --git a/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx b/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx index 805ba5c..a0ed4e7 100644 --- a/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx +++ b/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx @@ -53,7 +53,7 @@ export default function WishlistGameCard({ />

- + {game.name}

diff --git a/Frontend/src/tests/MainPage.test.tsx b/Frontend/src/tests/MainPage.test.tsx index fac15d7..6602af8 100644 --- a/Frontend/src/tests/MainPage.test.tsx +++ b/Frontend/src/tests/MainPage.test.tsx @@ -210,7 +210,7 @@ describe('MainPage', () => { screen .getAllByRole('link', { name: 'See this game' }) .map((link) => link.getAttribute('href')) - ).toEqual(['/gamepage/2', '/gamepage/1', '/gamepage/1']) + ).toEqual(['/GamePage/2', '/GamePage/1', '/GamePage/1']) // Genres are sorted, and the first one is selected by default const selectors = screen.getAllByLabelText('Choose a genre') as HTMLSelectElement[] diff --git a/Frontend/src/tests/RecentReviews.test.tsx b/Frontend/src/tests/RecentReviews.test.tsx index c5f813a..86c7716 100644 --- a/Frontend/src/tests/RecentReviews.test.tsx +++ b/Frontend/src/tests/RecentReviews.test.tsx @@ -86,7 +86,7 @@ describe('RecentReviews', () => { screen .getAllByRole('link', { name: 'See this game' }) .map((link) => link.getAttribute('href')) - ).toEqual(['/gamepage/30', '/gamepage/20', '/gamepage/10']) + ).toEqual(['/GamePage/30', '/GamePage/20', '/GamePage/10']) }) it('shows all reviews when the list has no height to measure', () => { diff --git a/Frontend/src/tests/ReviewCard.test.tsx b/Frontend/src/tests/ReviewCard.test.tsx index b6bf61d..a2e420e 100644 --- a/Frontend/src/tests/ReviewCard.test.tsx +++ b/Frontend/src/tests/ReviewCard.test.tsx @@ -47,7 +47,7 @@ describe('ReviewCard', () => { expect(screen.getByText('Dota 2')).toBeTruthy() expect(screen.getByRole('link', { name: 'See this game' }).getAttribute('href')).toBe( - '/gamepage/570' + '/GamePage/570' ) }) diff --git a/Frontend/src/tests/UserReviews.test.tsx b/Frontend/src/tests/UserReviews.test.tsx index a6a8d49..11060e1 100644 --- a/Frontend/src/tests/UserReviews.test.tsx +++ b/Frontend/src/tests/UserReviews.test.tsx @@ -76,8 +76,8 @@ describe('UserReviews', () => { expect(GetReviewsByUser).toHaveBeenCalledWith(7, 1) const links = screen.getAllByRole('link', { name: 'See this game' }) expect(links.map((link) => link.getAttribute('href'))).toEqual([ - '/gamepage/730', - '/gamepage/570' + '/GamePage/730', + '/GamePage/570' ]) expect(screen.queryByRole('navigation')).toBeNull() }) From 8cf2670f3e2d5bd85c31c4ccd5cd4bdcbeec48da Mon Sep 17 00:00:00 2001 From: carmennt Date: Tue, 17 Nov 2026 19:18:54 +0100 Subject: [PATCH 3/5] feat: make "Write review" look unclickable if not logged in --- Frontend/src/components/Reviews/Reviews.css | 5 +++++ Frontend/src/components/Reviews/Reviews.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Frontend/src/components/Reviews/Reviews.css b/Frontend/src/components/Reviews/Reviews.css index de5a440..d884546 100644 --- a/Frontend/src/components/Reviews/Reviews.css +++ b/Frontend/src/components/Reviews/Reviews.css @@ -32,6 +32,11 @@ text-transform: none; } +.reviewComposerToggleDisabled { + cursor: not-allowed !important; + opacity: 0.8; +} + .reviewComposerHint { margin: -0.5rem 0 0; color: var(--primary-text-color); diff --git a/Frontend/src/components/Reviews/Reviews.tsx b/Frontend/src/components/Reviews/Reviews.tsx index 1647fc8..d688fe7 100644 --- a/Frontend/src/components/Reviews/Reviews.tsx +++ b/Frontend/src/components/Reviews/Reviews.tsx @@ -105,7 +105,7 @@ export default function Reviews({ {(!hasCurrentUserReview || isComposerOpen) && (