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