From 1f94b517cba4a4e90fa56dbb67ffb49595bc0fc8 Mon Sep 17 00:00:00 2001 From: nikolai-sim Date: Fri, 7 Apr 2023 11:39:43 +1200 Subject: [PATCH] update next.config --- next.config.js | 23 ++++++++- pages/_app.tsx | 134 ++++++++++++++++++++++++++----------------------- 2 files changed, 92 insertions(+), 65 deletions(-) diff --git a/next.config.js b/next.config.js index a843cbe..b26ce84 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,25 @@ /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, -} + compress: true, + async headers() { + return [ + { + source: "/:all*(gz)", + locale: false, + headers: [ + { + key: "Content-Encoding", + value: "gzip", + }, + { + key: "Content-Type", + value: "application/gzip", + }, + ], + }, + ]; + }, +}; -module.exports = nextConfig +module.exports = nextConfig; diff --git a/pages/_app.tsx b/pages/_app.tsx index 7ebc184..d6f639e 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useEffect, useState } from "react"; import { Unity, useUnityContext } from "react-unity-webgl"; -import '@/styles/globals.scss' +import "@/styles/globals.scss"; import PrinciplePage from "@/components/PrinciplePage"; import LandingPage from "@/components/LandingPage"; import MuteLottie from "@/components/UI/MuteLottie"; @@ -15,7 +15,6 @@ import { playSound } from "@/hooks/utils/audio"; import Loader from "@/components/Loader"; export default function App() { - // react-unity-webgl config // const { unityProvider, sendMessage, addEventListener, removeEventListener, isLoaded } = useUnityContext({ // loaderUrl: "/unity/BuildGzip.loader.js", @@ -23,20 +22,29 @@ export default function App() { // frameworkUrl: "/unity/BuildGzip.framework.js", // codeUrl: "/unity/BuildGzip.wasm.gz", // }); - // const { unityProvider, sendMessage, addEventListener, removeEventListener, isLoaded } = useUnityContext({ - // loaderUrl: "/Build/Build_Gzip/BuildGzip.loader.js", - // dataUrl: "/Build/Build_Gzip/BuildGzip.data.gz", - // frameworkUrl: "/Build/Build_Gzip/BuildGzip.framework.js", - // codeUrl: "/Build/Build_Gzip/BuildGzip.wasm.gz", - // }); - const { unityProvider, sendMessage, addEventListener, removeEventListener, loadingProgression, isLoaded } = useUnityContext({ - loaderUrl: "/Build/Build.loader.js", - dataUrl: "/Build/Build.data", - frameworkUrl: "/Build/Build.framework.js", - codeUrl: "/Build/Build.wasm", + const { + unityProvider, + sendMessage, + addEventListener, + removeEventListener, + isLoaded, + loadingProgression, + initialisationError, + } = useUnityContext({ + loaderUrl: "/Build/Build_Gzip/BuildGzip.loader.js", + dataUrl: "/Build/Build_Gzip/BuildGzip.data.gz", + frameworkUrl: "/Build/Build_Gzip/BuildGzip.framework.js.gz", + codeUrl: "/Build/Build_Gzip/BuildGzip.wasm.gz", }); + // const { unityProvider, sendMessage, addEventListener, removeEventListener, loadingProgression, isLoaded } = useUnityContext({ + // loaderUrl: "/Build/Build.loader.js", + // dataUrl: "/Build/Build.data", + // frameworkUrl: "/Build/Build.framework.js", + // codeUrl: "/Build/Build.wasm", + // }); + // global state management for interactions const landingPage = useStore((state: any) => state.landingPage); const setLandingPage = useStore((state: any) => state.setLandingPage); @@ -45,60 +53,64 @@ export default function App() { const spotLight = useStore((state: any) => state.spotLight); const hamburgerMenu = useStore((state: any) => state.hamburgerMenu); const backToMap = useStore((state: any) => state.backToMap); - const setBackToMap = useStore((state: any) => state.setBackToMap) - const principle = useStore((state: any) => state.principle) - const openPrinciple = useStore((state: any) => state.openPrinciple) - const setSpotLight = useStore((state: any) => state.setSpotLight) + const setBackToMap = useStore((state: any) => state.setBackToMap); + const principle = useStore((state: any) => state.principle); + const openPrinciple = useStore((state: any) => state.openPrinciple); + const setSpotLight = useStore((state: any) => state.setSpotLight); // returning visitor state - const [visited, setVisited] = useState('false') + const [visited, setVisited] = useState("false"); useEffect(() => { - const siteState = window.sessionStorage.getItem("siteState"); + const siteState = window.sessionStorage.getItem("siteState"); console.log(siteState); - + if (visited == "true") { - sendMessage("Spotlight_Manager","unity_open") + sendMessage("Spotlight_Manager", "unity_open"); setLandingPage(false); } - if (siteState == 'true') { - setVisited('true') - } else if (siteState == 'false') { - setVisited('false') + if (siteState == "true") { + setVisited("true"); + } else if (siteState == "false") { + setVisited("false"); } - }, [visited, isLoaded]) + }, [visited, isLoaded]); // send messages to Unity Build useEffect(() => { if (!videoSequence) { - sendMessage("Spotlight_Manager","unity_open") + sendMessage("Spotlight_Manager", "unity_open"); } - }, [videoSequence]) + }, [videoSequence]); useEffect(() => { if (!welcomeScreen) { - sendMessage("Spotlight_Manager", "map_intro") + sendMessage("Spotlight_Manager", "map_intro"); } - }, [welcomeScreen]) + }, [welcomeScreen]); useEffect(() => { if (spotLight) { - sendMessage("Spotlight_Manager", "open_spotlight", `${principle.toString()}`) + sendMessage( + "Spotlight_Manager", + "open_spotlight", + `${principle.toString()}` + ); } - }, [spotLight, principle]) + }, [spotLight, principle]); useEffect(() => { if (backToMap == true) { - sendMessage("Spotlight_Manager", "return_to_map") + sendMessage("Spotlight_Manager", "return_to_map"); } - }, [backToMap]) + }, [backToMap]); // handle spotlight open functionality const openSpotlight = useCallback((principle: any) => { - setSpotLight(true) - setBackToMap(false) - playSound('ui_click') - playSound('transition') + setSpotLight(true); + setBackToMap(false); + playSound("ui_click"); + playSound("transition"); }, []); // event listeners for Unity functions @@ -108,49 +120,45 @@ export default function App() { removeEventListener("PageOpen", openSpotlight); }; }, [addEventListener, removeEventListener, openSpotlight]); - - return ( + + useEffect(() => { + console.log(initialisationError); + }, [initialisationError]); + + return ( <>
- {welcomeScreen && ( - - )} + {welcomeScreen && } {!welcomeScreen && ( <> - {!openPrinciple && ( - - )} + {!openPrinciple && } )} - + {openPrinciple && ( <> - + )} - {((spotLight) && (!openPrinciple))&& ( - - )} + {spotLight && !openPrinciple && } - {hamburgerMenu && ( - - )} + {hamburgerMenu && }
{!isLoaded && ( - - )} - + + )} + - ) -} \ No newline at end of file + ); +}