diff --git a/frontend/index.html b/frontend/index.html index d4263e3..b20be89 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -4,7 +4,7 @@ - it2810-t33-p2 + NTNU GameShelf
diff --git a/frontend/src/components/GameListItem.tsx b/frontend/src/components/GameListItem.tsx index 881703d..ca55737 100644 --- a/frontend/src/components/GameListItem.tsx +++ b/frontend/src/components/GameListItem.tsx @@ -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 { @@ -29,7 +30,7 @@ export default function GameListItem({ > {title} diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index d4f0928..26c4fd8 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -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(); @@ -56,9 +56,11 @@ export default function Header() {
- - { isMobile ? : "Working Title" } - +
@@ -83,9 +85,11 @@ export default function Header() {
- - { isMobile ? :"My Ratings" } - +
); } diff --git a/frontend/src/pages/GameDetails.tsx b/frontend/src/pages/GameDetails.tsx index b06cb0a..6cd96ce 100644 --- a/frontend/src/pages/GameDetails.tsx +++ b/frontend/src/pages/GameDetails.tsx @@ -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!) { @@ -231,85 +232,87 @@ export default function GameDetails() { return ( <>
- - {alertingUser && ( - - Your rating is locally stored and will be updated next time you are here. - - )} -
- {loading && !data &&

Loading…

} - {!loading && (error || !game) && ( -

Game not found.

- )} +
+ + {alertingUser && ( + + Your rating is locally stored and will be updated next time you are here. + + )} +
+ {loading && !data &&

Loading…

} + {!loading && (error || !game) && ( +

Game not found.

+ )} - {game && ( - <> -

- {game.releaseDate - ? new Date(game.releaseDate).getFullYear() - : "Unknown year"}{" "} - | Age Rating: {game.esrbRating || "Not rated"} -

-

{game.name}

+ {game && ( + <> +

+ {game.releaseDate + ? new Date(game.releaseDate).getFullYear() + : "Unknown year"}{" "} + | Age Rating: {game.esrbRating || "Not rated"} +

+

{game.name}

- - {game.name} - -
-

NTNU Rating

- -
-
-

Your Rating

- -
+ + {game.name} + +
+

NTNU Rating

+ +
+
+

Your Rating

+ +
+
-
-

- {game.tags.join(", ") || "—"} -

+

+ {game.tags.join(", ") || "—"} +

-

- Developer: - {game.developers.join(", ") || "—"} -

-

- Publishers: - {game.publishers.join(", ") || "—"} -

-

- Platform: - {game.platforms.join(", ") || "—"} -

+

+ Developer: + {game.developers.join(", ") || "—"} +

+

+ Publishers: + {game.publishers.join(", ") || "—"} +

+

+ Platform: + {game.platforms.join(", ") || "—"} +

-

- Description - {game.description || "No description available."} -

- - )} -
-
+

+ Description + {game.description || "No description available."} +

+ + )} +
+
+ ); } diff --git a/frontend/src/pages/GamesGrid.tsx b/frontend/src/pages/GamesGrid.tsx index a45ffdf..7ef9dd2 100644 --- a/frontend/src/pages/GamesGrid.tsx +++ b/frontend/src/pages/GamesGrid.tsx @@ -244,55 +244,57 @@ export default function GamesGrid() { return ( <>
- - setPage((p) => Math.max(1, p - 1))} - onNextPage={() => setPage((p) => Math.min(totalPages, p + 1))} - filters={filters} - onFiltersChange={updateFilters} - sort={sort} - onSortChange={updateSort} - /> -
-

- {!loading && `${totalCount} game${totalCount === 1 ? "" : "s"} found`} -

- {error &&

Failed to load games.

} - {!error && loading && !data && ( -

Loading games…

- )} - {!error && !loading && games.length === 0 && ( -

- No games match{" "} - {hasActiveFilters(filters) || search - ? "these filters" - : "the catalog"} - . +

+ + setPage((p) => Math.max(1, p - 1))} + onNextPage={() => setPage((p) => Math.min(totalPages, p + 1))} + filters={filters} + onFiltersChange={updateFilters} + sort={sort} + onSortChange={updateSort} + /> +
+

+ {!loading && `${totalCount} game${totalCount === 1 ? "" : "s"} found`}

- )} - {games.map((game, index) => ( - - ))} -
-
+ {error &&

Failed to load games.

} + {!error && loading && !data && ( +

Loading games…

+ )} + {!error && !loading && games.length === 0 && ( +

+ No games match{" "} + {hasActiveFilters(filters) || search + ? "these filters" + : "the catalog"} + . +

+ )} + {games.map((game, index) => ( + + ))} +
+
+ ); } diff --git a/frontend/src/pages/MyRatings.tsx b/frontend/src/pages/MyRatings.tsx index 999bd44..017ca76 100644 --- a/frontend/src/pages/MyRatings.tsx +++ b/frontend/src/pages/MyRatings.tsx @@ -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!) { @@ -84,6 +85,7 @@ export default function MyRatings() { return ( <>
+
+
); } diff --git a/frontend/src/constants/global.ts b/frontend/src/utils/isMobile.ts similarity index 76% rename from frontend/src/constants/global.ts rename to frontend/src/utils/isMobile.ts index 342907f..e2986cd 100644 --- a/frontend/src/constants/global.ts +++ b/frontend/src/utils/isMobile.ts @@ -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'; diff --git a/frontend/src/utils/resizedImage.ts b/frontend/src/utils/resizedImage.ts new file mode 100644 index 0000000..ae8f755 --- /dev/null +++ b/frontend/src/utils/resizedImage.ts @@ -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/-/") ?? ""; +} \ No newline at end of file