Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="https://www.ntnu.no/o/ntnu-theme/images/logoicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>it2810-t33-p2</title>
<title>NTNU GameShelf</title>
</head>
<body>
<div id="root"></div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/GameListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Image } from "react-bootstrap";
import { Link } from "react-router-dom";
import { resizedImage } from "../utils/resizedImage";
import StarRating from "./StarRating";

interface GameListItemProps {
Expand Down Expand Up @@ -29,7 +30,7 @@ export default function GameListItem({
>
<Image className="object-fit-cover flex-shrink-0"
style={{ width: "95px", height: "95px", backgroundColor: "#ddd" }}
src={image}
src={resizedImage(image)}
alt={title}
loading="lazy"
/>
Expand Down
18 changes: 11 additions & 7 deletions frontend/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useSearchParams,
} from "react-router-dom";
import { GRID_QUERY_STORAGE_KEY } from "../constants/storageKeys";
import { useIsMobile } from "../constants/global";
import { useIsMobile } from "../utils/isMobile";

export default function Header() {
const navigate = useNavigate();
Expand Down Expand Up @@ -56,9 +56,11 @@ export default function Header() {
<header className="d-flex align-items-center justify-content-between gap-2 px-3"
style={{ backgroundColor: "var(--color-brand)", height: "var(--header-height)" }}
>
<Link className="text-decoration-none text-nowrap text-light fw-bold" to={homeHref}>
{ isMobile ? <House size={25} aria-label="Home"/> : "Working Title" }
</Link>
<nav aria-label="Home">
<Link className="text-decoration-none text-nowrap text-light fw-bold" to={homeHref}>
{ isMobile ? <House size={25} aria-label="Home"/> : "NTNU GameShelf" }
</Link>
</nav>

<Form className="flex-grow-1" style={{ maxWidth: "420px"}} role="search" onSubmit={handleSubmit}>
<InputGroup className="overflow-hidden rounded-pill">
Expand All @@ -83,9 +85,11 @@ export default function Header() {
</InputGroup>
</Form>

<Link className="text-decoration-none text-nowrap text-light fw-bold" to="/project2/my-ratings">
{ isMobile ? <Person size={25} aria-label="My Ratings"/> :"My Ratings" }
</Link>
<nav aria-label="My Ratings">
<Link className="text-decoration-none text-nowrap text-light fw-bold" to="/project2/my-ratings">
{ isMobile ? <Person size={25} aria-label="My Ratings"/> :"My Ratings" }
</Link>
</nav>
</header>
);
}
151 changes: 77 additions & 74 deletions frontend/src/pages/GameDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Header from "../components/Header";
import Layout from "../components/Layout";
import StarRating from "../components/StarRating";
import { getUserId } from "../utils/userId";
import { useIsMobile } from "../constants/global";
import { useIsMobile } from "../utils/isMobile";
import { resizedImage } from "../utils/resizedImage";

const GET_GAME = gql`
query GetGame($id: ID!) {
Expand Down Expand Up @@ -231,85 +232,87 @@ export default function GameDetails() {
return (
<>
<Header />
<Layout>
{alertingUser && (
<Alert
variant="info"
className="position-fixed start-50 translate-middle-x shadow"
style={{
top: "calc(var(--header-height) + 1rem)",
zIndex: 1050,
}}
>
Your rating is locally stored and will be updated next time you are here.
</Alert>
)}
<div className="ps-2 pe-2 pt-3 pb-3">
{loading && !data && <p className="text-muted">Loading…</p>}
{!loading && (error || !game) && (
<p className="text-muted">Game not found.</p>
)}
<main>
<Layout>
{alertingUser && (
<Alert
variant="info"
className="position-fixed start-50 translate-middle-x shadow"
style={{
top: "calc(var(--header-height) + 1rem)",
zIndex: 1050,
}}
>
Your rating is locally stored and will be updated next time you are here.
</Alert>
)}
<div className="ps-2 pe-2 pt-3 pb-3">
{loading && !data && <p className="text-muted">Loading…</p>}
{!loading && (error || !game) && (
<p className="text-muted">Game not found.</p>
)}

{game && (
<>
<p className="m-0 text-muted">
{game.releaseDate
? new Date(game.releaseDate).getFullYear()
: "Unknown year"}{" "}
| Age Rating: {game.esrbRating || "Not rated"}
</p>
<h1 className="ms-1 me-1 mt-2 mb-2">{game.name}</h1>
{game && (
<>
<p className="m-0 text-muted">
{game.releaseDate
? new Date(game.releaseDate).getFullYear()
: "Unknown year"}{" "}
| Age Rating: {game.esrbRating || "Not rated"}
</p>
<h1 className="ms-1 me-1 mt-2 mb-2">{game.name}</h1>

<Stack direction="horizontal" className="mb-3" gap={4}>
<Image
className="flex-shrink-0 object-fit-cover"
style={{ width: ` ${imageSize}px`, height: ` ${imageSize}px`, backgroundColor: `var(--color-stripe-odd)` }}
src={game.imageUrl ?? ""}
alt={game.name}
loading="lazy"
/>
<Stack gap={2}>
<div>
<p className="m-0 fw-bold">NTNU Rating</p>
<StarRating score={game.averageScore} size={isMobile ? 1 : 2} />
</div>
<div>
<p className="m-0 fw-bold">Your Rating</p>
<StarRating
score={draftScore}
onChange={handleRate}
onDelete={handleDeleteRating}
size={isMobile ? 1 : 2}
/>
</div>
<Stack direction="horizontal" className="mb-3" gap={4}>
<Image
className="flex-shrink-0 object-fit-cover"
style={{ width: ` ${imageSize}px`, height: ` ${imageSize}px`, backgroundColor: `var(--color-stripe-odd)` }}
src={resizedImage(game.imageUrl)}
alt={game.name}
loading="lazy"
/>
<Stack gap={2}>
<div>
<p className="m-0 fw-bold">NTNU Rating</p>
<StarRating score={game.averageScore} size={isMobile ? 1 : 2} />
</div>
<div>
<p className="m-0 fw-bold">Your Rating</p>
<StarRating
score={draftScore}
onChange={handleRate}
onDelete={handleDeleteRating}
size={isMobile ? 1 : 2}
/>
</div>
</Stack>
</Stack>
</Stack>

<p className="mb-4" style={{ fontWeight: 600 }}>
{game.tags.join(", ") || "—"}
</p>
<p className="mb-4" style={{ fontWeight: 600 }}>
{game.tags.join(", ") || "—"}
</p>

<p className="d-flex gap-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="fw-bold white-space-nowrap">Developer:</span>
{game.developers.join(", ") || "—"}
</p>
<p className="d-flex gap-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="fw-bold white-space-nowrap">Publishers:</span>
{game.publishers.join(", ") || "—"}
</p>
<p className="d-flex gap-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="fw-bold white-space-nowrap">Platform:</span>
{game.platforms.join(", ") || "—"}
</p>
<p className="d-flex gap-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="fw-bold white-space-nowrap">Developer:</span>
{game.developers.join(", ") || "—"}
</p>
<p className="d-flex gap-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="fw-bold white-space-nowrap">Publishers:</span>
{game.publishers.join(", ") || "—"}
</p>
<p className="d-flex gap-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="fw-bold white-space-nowrap">Platform:</span>
{game.platforms.join(", ") || "—"}
</p>

<p className="lh-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="d-block fw-bold mb-2">Description</span>
{game.description || "No description available."}
</p>
</>
)}
</div>
</Layout>
<p className="lh-2" style={{ borderTop: `1px solid var(--color-stripe-odd)`, paddingTop: 8 }}>
<span className="d-block fw-bold mb-2">Description</span>
{game.description || "No description available."}
</p>
</>
)}
</div>
</Layout>
</main>
</>
);
}
98 changes: 50 additions & 48 deletions frontend/src/pages/GamesGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,55 +244,57 @@ export default function GamesGrid() {
return (
<>
<Header />
<Layout>
<Toolbar
page={page}
totalPages={totalPages}
onPrevPage={() => setPage((p) => Math.max(1, p - 1))}
onNextPage={() => setPage((p) => Math.min(totalPages, p + 1))}
filters={filters}
onFiltersChange={updateFilters}
sort={sort}
onSortChange={updateSort}
/>
<div className="d-flex flex-column overflow-hidden"
//style={{ height: "calc(100vh - var(--header-height) - var(--toolbar-height))" }}
ref={listRef}
>
<p className="visually-hidden" aria-live="polite">
{!loading && `${totalCount} game${totalCount === 1 ? "" : "s"} found`}
</p>
{error && <p className="text-muted m-4">Failed to load games.</p>}
{!error && loading && !data && (
<p className="text-muted m-4">Loading games…</p>
)}
{!error && !loading && games.length === 0 && (
<p className="text-muted m-4">
No games match{" "}
{hasActiveFilters(filters) || search
? "these filters"
: "the catalog"}
.
<main>
<Layout>
<Toolbar
page={page}
totalPages={totalPages}
onPrevPage={() => setPage((p) => Math.max(1, p - 1))}
onNextPage={() => setPage((p) => Math.min(totalPages, p + 1))}
filters={filters}
onFiltersChange={updateFilters}
sort={sort}
onSortChange={updateSort}
/>
<div className="d-flex flex-column overflow-hidden"
//style={{ height: "calc(100vh - var(--header-height) - var(--toolbar-height))" }}
ref={listRef}
>
<p className="visually-hidden" aria-live="polite">
{!loading && `${totalCount} game${totalCount === 1 ? "" : "s"} found`}
</p>
)}
{games.map((game, index) => (
<GameListItem
key={game.id}
id={game.id}
title={game.name}
year={
game.releaseDate
? new Date(game.releaseDate).getFullYear()
: null
}
tags={game.tags.join(", ")}
rating={game.averageScore}
image={game.imageUrl ?? ""}
striped={index % 2 === 0}
/>
))}
</div>
</Layout>
{error && <p className="text-muted m-4">Failed to load games.</p>}
{!error && loading && !data && (
<p className="text-muted m-4">Loading games…</p>
)}
{!error && !loading && games.length === 0 && (
<p className="text-muted m-4">
No games match{" "}
{hasActiveFilters(filters) || search
? "these filters"
: "the catalog"}
.
</p>
)}
{games.map((game, index) => (
<GameListItem
key={game.id}
id={game.id}
title={game.name}
year={
game.releaseDate
? new Date(game.releaseDate).getFullYear()
: null
}
tags={game.tags.join(", ")}
rating={game.averageScore}
image={game.imageUrl ?? ""}
striped={index % 2 === 0}
/>
))}
</div>
</Layout>
</main>
</>
);
}
9 changes: 6 additions & 3 deletions frontend/src/pages/MyRatings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import Header from "../components/Header";
import { getUserId } from "../utils/userId";
import Card from "react-bootstrap/esm/Card";
import StarRating from "../components/StarRating";
import { useIsMobile } from "../constants/global";
import { useIsMobile } from "../utils/isMobile";
import { Link } from "react-router-dom";
import { resizedImage } from "../utils/resizedImage";

const GET_MY_REVIEWS = gql`
query GetMyReviews($userId: String!) {
Expand Down Expand Up @@ -84,6 +85,7 @@ export default function MyRatings() {
return (
<>
<Header />
<main>
<section className="d-flex flex-column overflow-hidden"
style={{ height: `calc(100vh - var(--header-height))` }}
aria-label="My Ratings"
Expand Down Expand Up @@ -117,8 +119,8 @@ export default function MyRatings() {
<Card className="h-100" style={{ height: "18rem", backgroundColor: "var(--color-stripe-odd)" }}>
<Card.Img
variant="top"
src={game.imageUrl ?? ""}
alt={game.name}
src={resizedImage(game.imageUrl)}
alt=""
style={{
height: "11rem",
objectFit: "cover",
Expand All @@ -140,6 +142,7 @@ export default function MyRatings() {
</div>
</div>
</section>
</main>
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//We can add our custom mediaquery hooks here, so we can use them in
// We can add our custom mediaquery hooks here, so we can use them in
// any component without having to import react-responsive and write the query each time.

import { useMediaQuery } from 'react-responsive';
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/utils/resizedImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Regex to distinguish between those that are resized and those that are not
const RAWG_MEDIA_URL = /^(https?:\/\/media\.rawg\.io\/media\/)(?!resize\/)/;

export function resizedImage(imageUrl: string | null): string {
return imageUrl?.replace(RAWG_MEDIA_URL, "$1resize/420/-/") ?? "";
}