|
1 | 1 | import "./styles/HomeView.css"; |
2 | | -import { useLocation, useNavigate } from "react-router-dom"; |
| 2 | +import { Outlet, useLocation, useNavigate, useParams } from "react-router-dom"; |
3 | 3 | import { useContext, useEffect, useState } from "react"; |
4 | 4 | import HomeViewHeader from "./HomeViewHeader"; |
5 | 5 | import HomeViewFooter from "./HomeViewFooter"; |
6 | | -import HomeViewContent from "./HomeViewContent"; |
7 | | -import StyleContext from "../contexts/StyleContext"; |
| 6 | +import AppContext from "../contexts/AppContext"; |
8 | 7 | import AppConfig from "../AppConfig.json"; |
| 8 | +import LandingPage from "./LandingPage"; |
9 | 9 |
|
10 | 10 | interface Props {} |
11 | 11 |
|
12 | 12 | const HomeView = ({}: Props) => { |
13 | | - // - - - - GENERAL STATES - - - - |
14 | | - const { hueRotation, setHueDuration } = useContext(StyleContext); |
| 13 | + // - - - - - NAVIGATION - - - - - |
| 14 | + const location = useLocation(); |
| 15 | + const navigate = useNavigate(); |
| 16 | + // Valid URL Parameter Options to check against |
| 17 | + let { landingOrHome, category1, gameOrWeb, project } = useParams(); |
| 18 | + const param1_Opts = ["landing", "home"]; |
| 19 | + const param2_Opts = ["portfolio", "blog", "introduction", "intro"]; |
| 20 | + const param3_Opts = ["gamedev", "webdev"]; |
| 21 | + const param4_Opts = AppConfig.projectURL_Params; |
| 22 | + // useStates for Interfacing with URL Params |
| 23 | + const [param1, setParam1] = useState<string>(""); |
| 24 | + const [param2, setParam2] = useState<string>(""); |
| 25 | + const [param3, setParam3] = useState<string>(""); |
| 26 | + const [param4, setParam4] = useState<string>(""); |
| 27 | + const [allParamsObj, setAllParamsObj] = useState<any>({ |
| 28 | + param1, |
| 29 | + param2, |
| 30 | + param3, |
| 31 | + param4, |
| 32 | + }); |
| 33 | + const setParamsArray = [setParam1, setParam2, setParam3, setParam4]; |
| 34 | + // check if this is the landing page |
| 35 | + const [isLanding, setIsLanding] = useState<boolean>(false); |
| 36 | + // - - - - CONTEXT - - - - |
| 37 | + const { hueRotation, setHueDuration } = useContext(AppContext); |
15 | 38 | // - - - - - TITLES AND TEXT - - - - - |
16 | | - const [currentProject, setCurrentProject] = useState<string>("Deerfall"); |
| 39 | + const [currentContent, setCurrentContent] = useState<string>("Deerfall"); |
17 | 40 | const [title, setTitle] = useState<string>("Dev Blog"); |
18 | 41 | const [subtitle, setSubtitle] = useState<string>("Welcome! "); |
19 | 42 | const [subEmoji, setSubEmoji] = useState<string>(" 🙂"); |
20 | | - // - - - - - LINKS - - - - - |
21 | | - const [gameDevLink, setGameDevLink] = useState<string>(""); |
22 | | - const [webDevLink, setWebDevLink] = useState<string>(""); |
23 | | - const [portfolioLink, setPortfolioLink] = useState<string>(""); |
24 | | - const [blogLink, setBlogLink] = useState<string>(""); |
25 | | - const [isPortfolio, setIsPortfolio] = useState<boolean>(true); |
26 | | - const [isGameDev, setIsGameDev] = useState<boolean>(true); |
27 | | - const navigate = useNavigate(); |
28 | | - const currentPath = useLocation().pathname; |
29 | 43 | // - - - - - PROJECTS - - - - - |
30 | 44 | const gameDevProjList = ["Deerfall"]; |
31 | 45 | const webDevProjList = ["MediaMatchup"]; |
32 | 46 |
|
33 | | - useEffect(() => { |
34 | | - if (currentPath.includes("/gamedev/portfolio")) { |
35 | | - if (currentPath.includes("home/")) { |
36 | | - navigate(`/home/gamedev/portfolio/${currentProject}`); |
37 | | - } |
38 | | - setTitle("GameDev Portfolio"); |
39 | | - setWebDevLink(`/home/webdev/portfolio/${currentProject}`); |
40 | | - setBlogLink(`/home/gamedev/blog/${currentProject}`); |
41 | | - setIsPortfolio(true); |
42 | | - setIsGameDev(true); |
43 | | - } else if (currentPath.includes("/gamedev/blog")) { |
44 | | - if (currentPath.includes("home/")) { |
45 | | - navigate(`/home/gamedev/blog/${currentProject}`); |
46 | | - } |
47 | | - setTitle("GameDev Blog"); |
48 | | - setWebDevLink(`/home/webdev/blog/${currentProject}`); |
49 | | - setPortfolioLink(`/home/gamedev/portfolio/${currentProject}`); |
50 | | - setIsPortfolio(false); |
51 | | - setIsGameDev(true); |
52 | | - } else if (currentPath.includes("/webdev/portfolio")) { |
53 | | - if (currentPath.includes("home/")) { |
54 | | - navigate(`/home/webdev/portfolio/${currentProject}`); |
55 | | - } |
56 | | - setTitle("WebDev Portfolio"); |
57 | | - setGameDevLink(`/home/gamedev/portfolio/${currentProject}`); |
58 | | - setBlogLink(`/home/webdev/blog/${currentProject}`); |
59 | | - setIsPortfolio(true); |
60 | | - setIsGameDev(false); |
61 | | - } else if (currentPath.includes("/webdev/blog")) { |
62 | | - if (currentPath.includes("home/")) { |
63 | | - navigate(`/home/webdev/blog/${currentProject}`); |
64 | | - } |
65 | | - setTitle("WebDev Blog"); |
66 | | - setGameDevLink(`/home/gamedev/blog/${currentProject}`); |
67 | | - setPortfolioLink(`/home/webdev/portfolio/${currentProject}`); |
68 | | - setIsPortfolio(false); |
69 | | - setIsGameDev(false); |
| 47 | + // - - - - - FUNCTIONS - - - - - |
| 48 | + const checkURL = () => { |
| 49 | + let URLSegments = [landingOrHome, category1, gameOrWeb, project]; |
| 50 | + let paramArray = [param1_Opts, param2_Opts, param3_Opts, param4_Opts]; |
| 51 | + if (location.pathname === "/") { |
| 52 | + navigate("/landing"); |
| 53 | + setIsLanding(true); |
| 54 | + } else if (location.pathname === "/landing") { |
| 55 | + setIsLanding(true); |
70 | 56 | } |
71 | | - if (currentPath.includes("/gamedev/")) { |
72 | | - setCurrentProject(gameDevProjList[0]); |
73 | | - } else if (currentPath.includes("/webdev/")) { |
74 | | - setCurrentProject(webDevProjList[0]); |
| 57 | + for (let i = 0; i < URLSegments.length; i++) { |
| 58 | + if (URLSegments[i]) { |
| 59 | + let found = paramArray[i].find((item) => item === URLSegments[i]); |
| 60 | + if (found === undefined) { |
| 61 | + navigate("/404NotFound"); |
| 62 | + } else { |
| 63 | + setParamsArray[i](found); |
| 64 | + } |
| 65 | + } |
75 | 66 | } |
| 67 | + }; |
| 68 | + |
| 69 | + // - - - - - useEffects - - - - - |
| 70 | + useEffect(() => { |
| 71 | + setAllParamsObj({ param1, param2, param3, param4 }); |
| 72 | + }, [param1, param2, param3, param4]); |
76 | 73 |
|
77 | | - if (hueRotation != AppConfig.hueAnimDuration_Slow) { |
78 | | - setHueDuration(AppConfig.hueAnimDuration_Slow); |
| 74 | + useEffect(() => { |
| 75 | + if (!isLanding) { |
| 76 | + checkURL(); |
| 77 | + if (hueRotation != AppConfig.hueAnimDuration_Slow) { |
| 78 | + setHueDuration(AppConfig.hueAnimDuration_Slow); |
| 79 | + } |
79 | 80 | } |
80 | | - }, [currentPath]); |
| 81 | + console.log(category1); |
| 82 | + }, [location]); |
81 | 83 |
|
| 84 | + // - - - - - JSX - - - - - |
82 | 85 | return ( |
83 | 86 | <div className='HomeView'> |
| 87 | + {isLanding ? ( |
| 88 | + <LandingPage |
| 89 | + setIsLanding={setIsLanding} |
| 90 | + setParamsArray={setParamsArray} |
| 91 | + /> |
| 92 | + ) : ( |
| 93 | + "" |
| 94 | + )} |
84 | 95 | <HomeViewHeader |
85 | | - isPortfolio={isPortfolio} |
86 | | - gamedevOrWebdev={isGameDev} |
87 | | - hueRotation={hueRotation} |
88 | | - title={title} |
89 | 96 | subtitle={subtitle} |
90 | 97 | subEmoji={subEmoji} |
91 | | - gameDevLink={gameDevLink} |
92 | | - webDevLink={webDevLink} |
93 | | - portfolioLink={portfolioLink} |
94 | | - currentProject={currentProject} |
95 | | - blogLink={blogLink} |
96 | | - /> |
97 | | - <HomeViewContent |
98 | | - pathname={currentPath} |
99 | | - isPortfolio={isPortfolio} |
100 | | - currentProject={currentProject} |
101 | | - /> |
102 | | - <HomeViewFooter |
103 | | - pathname={currentPath} |
104 | | - gamedevOrWebdev={isGameDev} |
105 | | - hueRotation={hueRotation} |
106 | | - gameDevLink={gameDevLink} |
107 | | - webDevLink={webDevLink} |
108 | | - currentProject={currentProject} |
| 98 | + currentContent={currentContent} |
| 99 | + allParamsObj={allParamsObj} |
| 100 | + isLanding={isLanding} |
109 | 101 | /> |
| 102 | + <Outlet /> |
| 103 | + <HomeViewFooter currentContent={"deerfall"} allParamsObj={allParamsObj} /> |
110 | 104 | </div> |
111 | 105 | ); |
112 | 106 | }; |
|
0 commit comments