Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache GameBanana API Results #774

Merged
merged 10 commits into from
Jun 1, 2024
Merged

Cache GameBanana API Results #774

merged 10 commits into from
Jun 1, 2024

Conversation

otobot1
Copy link
Member

@otobot1 otobot1 commented Apr 30, 2024

Closes #764.

otobot1 added 3 commits April 28, 2024 15:59
-need to fix use of hooks. can't have early returns before calling hooks.
- next step is to make the hook generic and consume that hook in the function-specific global context hooks
- also still need to implement the helper functions that the global context hooks use
@otobot1 otobot1 force-pushed the Cache-Gamebanana-API-Results branch 2 times, most recently from da9df83 to 5985e4e Compare May 5, 2024 23:52
@otobot1
Copy link
Member Author

otobot1 commented May 9, 2024

I haven't been able to test this yet, and I'm not sure when I'll have time. Theoretically the code is done and should work, but my code never works first try lol

@otobot1 otobot1 added the status: help wanted This issue is low-priority for maintainers. Any user is welcome to submit a pull request label May 19, 2024
@otobot1
Copy link
Member Author

otobot1 commented May 19, 2024

I still haven't had a chance to sit down and try this code. It'll probably be another week or two before I can.

@otobot1
Copy link
Member Author

otobot1 commented May 21, 2024

Finally had a chance to quickly test out this code. It isn't currently working - the requests to GameBanana to retrieve the download link and image URLs are still happening every time.

@ShouvikGhosh2048
Copy link
Collaborator

ShouvikGhosh2048 commented May 29, 2024

diff --git a/src/components/mods/modCarousel.tsx b/src/components/mods/modCarousel.tsx
index 15a458e..cae7afc 100644
--- a/src/components/mods/modCarousel.tsx
+++ b/src/components/mods/modCarousel.tsx
@@ -1,7 +1,7 @@
 import { Carousel } from "@mantine/carousel";
-import { useGamebananaModImageUrls } from "~/hooks/gamebananaApi/useModImageUrls";
 import { createStyles } from "@mantine/core";
 import { Image } from "@mantine/core";      //TODO!: replace with nextjs Image component once next.config.mjs is fixed
+import { useModImageUrls } from "~/hooks/globalContexts/modImageUrls";
 // import Image from "next/image";
 import type { DifficultyColor } from "~/styles/difficultyColors";
 
@@ -68,36 +68,32 @@ type modCarouselProps = {
 
 
 export const ModCarousel = ({ gamebananaModId, numberOfMaps, colors }: modCarouselProps) => {
-    const { imageUrls } = useGamebananaModImageUrls({ gamebananaModId });
+    const imageUrls = useModImageUrls({ gamebananaModId });
 
 
     const { cx, classes } = useStyles({ colors });
 
 
     return (
-        !imageUrls ? (
-            null
-        ) : (
-            <Carousel classNames={{
-                root: classes.carousel,
-                viewport: classes.viewport,
-                slide: cx(classes.slide, numberOfMaps >= 4 ? classes.imgMaxHeight400 : classes.imgMaxHeight250),
-                controls: classes.controls,
-                control: classes.control,
-            }}>
-                {imageUrls.map((imageUrl) => (
-                    <Carousel.Slide
-                        key={imageUrl}
-                        gap={"md"}
-                        size={"400px"}
-                    >
-                        <Image
-                            src={imageUrl}
-                            alt="Mod image"
-                        />
-                    </Carousel.Slide>
-                ))}
-            </Carousel>
-        )
+        <Carousel classNames={{
+            root: classes.carousel,
+            viewport: classes.viewport,
+            slide: cx(classes.slide, numberOfMaps >= 4 ? classes.imgMaxHeight400 : classes.imgMaxHeight250),
+            controls: classes.controls,
+            control: classes.control,
+        }}>
+            {imageUrls.map((imageUrl) => (
+                <Carousel.Slide
+                    key={imageUrl}
+                    gap={"md"}
+                    size={"400px"}
+                >
+                    <Image
+                        src={imageUrl}
+                        alt="Mod image"
+                    />
+                </Carousel.Slide>
+            ))}
+        </Carousel>
     );
 };
\ No newline at end of file
diff --git a/src/components/mods/modDownloadButton.tsx b/src/components/mods/modDownloadButton.tsx
index cdad42c..bbd0114 100644
--- a/src/components/mods/modDownloadButton.tsx
+++ b/src/components/mods/modDownloadButton.tsx
@@ -3,10 +3,10 @@ import Image from "next/image";
 import { Group, Popover, Text, createStyles } from "@mantine/core";
 import { useDebouncedValue, useDisclosure } from "@mantine/hooks";
 import { LinkButton } from "~/components/linkButton";
-import { useModDownloadUrl } from "~/hooks/gamebananaApi/useModDownloadUrl";
 import { FAQ_PAGE_PATHNAME } from "~/consts/pathnames";
 import { OLYMPUS_INSTALLATION_URL } from "~/consts/olympusInstallationUrl";
 import everestLogo from "../../../public/images/everest-logo/everest-logo.png";
+import { useModDownloadUrl } from "~/hooks/globalContexts/modDownloadUrl";
 
 
 
@@ -46,7 +46,7 @@ const useStyles = createStyles(
 
 
 export const ModDownloadButton = ({ gamebananaModId }: ModDownloadButtonProps) => {
-    const { downloadUrl } = useModDownloadUrl({ gamebananaModId });
+    const downloadUrl = useModDownloadUrl({ gamebananaModId });
 
     const [isOpened, { close, open }] = useDisclosure(false);
 
@@ -68,7 +68,7 @@ export const ModDownloadButton = ({ gamebananaModId }: ModDownloadButtonProps) =
         >
             <Popover.Target>
                 <LinkButton
-                    href={downloadUrl ?? ""}
+                    href={downloadUrl}
                     onMouseEnter={open}
                     onMouseLeave={close}
                     linkWrapper={false}

This seems to make it work? I think you used the wrong functions from other files.

Also after this fix src\hooks\gamebananaApi\useModImageUrls.ts's line 148 throws an error - I think due to React's rerendering during development, a request is cancelled, and so we get undefined/null for dataJSON? Not sure.

@otobot1 otobot1 marked this pull request as ready for review June 1, 2024 22:01
@otobot1 otobot1 merged commit c251ca2 into main Jun 1, 2024
2 checks passed
@otobot1 otobot1 deleted the Cache-Gamebanana-API-Results branch June 1, 2024 22:03
@otobot1
Copy link
Member Author

otobot1 commented Jun 1, 2024

I'm going to merge this and create a follow-up issue to better handle errors from this stuff. It doesn't crash anything, so it's fine for now imo.

@otobot1 otobot1 added status: needs follow-up issue Remove this label when all follow-up issues have been created and removed status: help wanted This issue is low-priority for maintainers. Any user is welcome to submit a pull request labels Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs follow-up issue Remove this label when all follow-up issues have been created
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache GameBanana API Results
2 participants