Skip to content

Commit e50318b

Browse files
authored
Merge pull request #15 from JS-GitRepo/feature/contentDisplay
More Navigation Tweaking
2 parents b163335 + f94f119 commit e50318b

File tree

9 files changed

+101
-116
lines changed

9 files changed

+101
-116
lines changed

src/App.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
max-height: 100%;
1212
width: 100%;
1313
text-align: center;
14+
background-color: rgb(250, 250, 250);
1415
}
1516

1617
.material-symbols-outlined {

src/App.tsx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import "./App.css";
2-
import { Route, Router, Routes } from "react-router-dom";
3-
import LandingPage from "./components/LandingPage";
2+
import { Route, Routes } from "react-router-dom";
43
import HomeView from "./components/HomeView";
54
import WIPDisclaimer from "./components/WIPDisclaimer";
6-
import HomeViewHeader from "./components/HomeViewHeader";
75
import ErrorNotFound from "./components/ErrorNotFound";
8-
import HomeViewContent from "./components/HomeViewContent";
96

107
// 9-28-22
118
// Refactoring routes, and general way this 'web app' works. Making HomeView the default route, with a 'modal' over it which will be Landing Page. Instead of all this weird routing form Landing Page to Homeview, landing page will be an overlay that exists within HomeView, that is only present when the user is at /landing. Thinking of actually making the LandingPage an option for "HomeViewContent" that steels the entire viewport, so that HomeView is always there behind it.
@@ -19,25 +16,16 @@ function App() {
1916
<div className='App'>
2017
<Routes>
2118
<Route path='/' element={<HomeView />}>
22-
<Route
23-
path='/:landingOrHome'
24-
element={<HomeViewContent currentContent={"Deerfall"} />}>
25-
<Route
26-
path=':category1'
27-
element={<HomeViewContent currentContent={"Deerfall"} />}>
28-
<Route
29-
path=':gameOrWeb'
30-
element={<HomeViewContent currentContent={"Deerfall"} />}>
31-
<Route
32-
path=':project'
33-
element={<HomeViewContent currentContent={"Deerfall"} />}
34-
/>
19+
<Route path='/:landingOrHome' element={<HomeView />}>
20+
<Route path=':category1' element={<HomeView />}>
21+
<Route path=':gameOrWeb' element={<HomeView />}>
22+
<Route path=':project' element={<HomeView />} />
3523
</Route>
3624
</Route>
3725
</Route>
38-
<Route path='404NotFound' element={<ErrorNotFound />} />
39-
<Route path='*' element={<ErrorNotFound />} />
4026
</Route>
27+
<Route path='404NotFound' element={<ErrorNotFound />} />
28+
<Route path='*' element={<ErrorNotFound />} />
4129
</Routes>
4230
<WIPDisclaimer />
4331
</div>

src/components/HomeView.tsx

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import "./styles/HomeView.css";
2-
import { Outlet, useLocation, useNavigate, useParams } from "react-router-dom";
2+
import { useLocation, useNavigate, useParams } from "react-router-dom";
33
import { useContext, useEffect, useState } from "react";
44
import HomeViewHeader from "./HomeViewHeader";
55
import HomeViewFooter from "./HomeViewFooter";
66
import AppContext from "../contexts/AppContext";
77
import AppConfig from "../AppConfig.json";
88
import LandingPage from "./LandingPage";
9+
import HomeViewContent from "./HomeViewContent";
910

1011
interface Props {}
1112

@@ -19,88 +20,106 @@ const HomeView = ({}: Props) => {
1920
const param2_Opts = ["portfolio", "blog", "introduction", "intro"];
2021
const param3_Opts = ["gamedev", "webdev"];
2122
const param4_Opts = AppConfig.projectURL_Params;
22-
// useStates for Interfacing with URL Params
2323
const [param1, setParam1] = useState<string>("");
2424
const [param2, setParam2] = useState<string>("");
2525
const [param3, setParam3] = useState<string>("");
2626
const [param4, setParam4] = useState<string>("");
27-
const [allParamsObj, setAllParamsObj] = useState<any>({
27+
const [allParamsArray, setAllParamsArray] = useState<string[]>([
2828
param1,
2929
param2,
3030
param3,
3131
param4,
32-
});
33-
const setParamsArray = [setParam1, setParam2, setParam3, setParam4];
32+
]);
33+
const paramStateSet = [setParam1, setParam2, setParam3, setParam4];
3434
// check if this is the landing page
3535
const [isLanding, setIsLanding] = useState<boolean>(false);
3636
// - - - - CONTEXT - - - -
3737
const { hueRotation, setHueDuration } = useContext(AppContext);
3838
// - - - - - TITLES AND TEXT - - - - -
39-
const [currentContent, setCurrentContent] = useState<string>("Deerfall");
40-
const [title, setTitle] = useState<string>("Dev Blog");
4139
const [subtitle, setSubtitle] = useState<string>("Welcome! ");
4240
const [subEmoji, setSubEmoji] = useState<string>(" 🙂");
4341
// - - - - - PROJECTS - - - - -
44-
const gameDevProjList = ["Deerfall"];
45-
const webDevProjList = ["MediaMatchup"];
42+
const gameDevProjList = ["deerfall"];
43+
const webDevProjList = ["mediamatchup"];
4644

4745
// - - - - - FUNCTIONS - - - - -
48-
const checkURL = () => {
46+
47+
const validateURL = () => {
48+
// INITIAL SEGMENT VALIDATION
49+
let tempParams = allParamsArray;
4950
let URLSegments = [landingOrHome, category1, gameOrWeb, project];
5051
let paramArray = [param1_Opts, param2_Opts, param3_Opts, param4_Opts];
52+
// checks for landing page
5153
if (location.pathname === "/") {
54+
tempParams = [""];
5255
navigate("/landing");
5356
setIsLanding(true);
54-
} else if (location.pathname === "/landing") {
57+
} else if (landingOrHome === "landing") {
58+
tempParams = ["/landing"];
5559
setIsLanding(true);
5660
}
61+
// loops through each segment and validates it individually
5762
for (let i = 0; i < URLSegments.length; i++) {
5863
if (URLSegments[i]) {
5964
let found = paramArray[i].find((item) => item === URLSegments[i]);
6065
if (found === undefined) {
6166
navigate("/404NotFound");
6267
} else {
63-
setParamsArray[i](found);
68+
// setParamsArray[i](found);
69+
paramStateSet[i](found);
70+
tempParams[i] = found;
6471
}
6572
}
6673
}
74+
// Sets Default Project if none is selected in this category
75+
let isGameDev = tempParams[2] === "gamedev";
76+
let isWebDev = tempParams[2] === "webdev";
77+
let isGameDevProj = gameDevProjList.includes(tempParams[3]);
78+
let isWebDevProj = webDevProjList.includes(tempParams[3]);
79+
80+
if (isGameDev && !isGameDevProj) {
81+
setParam4(gameDevProjList[0]);
82+
tempParams[3] = gameDevProjList[0];
83+
} else if (isWebDev && !isWebDevProj) {
84+
setParam4(webDevProjList[0]);
85+
tempParams[3] = webDevProjList[0];
86+
}
87+
88+
let construct_URL = `/${tempParams[0]}/${tempParams[1]}/${tempParams[2]}/${tempParams[3]}`;
89+
let isSame_URL = construct_URL === location.pathname;
90+
let isIntroduction_URL = tempParams[1] === "introduction";
91+
92+
if (tempParams[3] && !isSame_URL && !isIntroduction_URL) {
93+
navigate(construct_URL, { replace: true });
94+
}
6795
};
6896

6997
// - - - - - useEffects - - - - -
7098
useEffect(() => {
71-
setAllParamsObj({ param1, param2, param3, param4 });
72-
}, [param1, param2, param3, param4]);
73-
74-
useEffect(() => {
99+
validateURL();
75100
if (!isLanding) {
76-
checkURL();
77101
if (hueRotation != AppConfig.hueAnimDuration_Slow) {
78102
setHueDuration(AppConfig.hueAnimDuration_Slow);
79103
}
80104
}
81-
console.log(category1);
82105
}, [location]);
83106

107+
// Necessary to update props. Otherwise, props are always a step behind.
108+
useEffect(() => {
109+
setAllParamsArray([param1, param2, param3, param4]);
110+
}, [param1, param2, param3, param4]);
111+
84112
// - - - - - JSX - - - - -
85113
return (
86114
<div className='HomeView'>
87-
{isLanding ? (
88-
<LandingPage
89-
setIsLanding={setIsLanding}
90-
setParamsArray={setParamsArray}
91-
/>
92-
) : (
93-
""
94-
)}
115+
{isLanding ? <LandingPage setIsLanding={setIsLanding} /> : ""}
95116
<HomeViewHeader
96117
subtitle={subtitle}
97118
subEmoji={subEmoji}
98-
currentContent={currentContent}
99-
allParamsObj={allParamsObj}
100-
isLanding={isLanding}
119+
allParams={allParamsArray}
101120
/>
102-
<Outlet />
103-
<HomeViewFooter currentContent={"deerfall"} allParamsObj={allParamsObj} />
121+
<HomeViewContent currentContent={param4} />
122+
<HomeViewFooter allParams={allParamsArray} />
104123
</div>
105124
);
106125
};

src/components/HomeViewContent.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@ import { animated, useTransition } from "react-spring";
33
import "./styles/HomeViewContent.css";
44
import Deerfall from "./projects/Deerfall";
55
import MediaMatchup from "./projects/MediaMatchup";
6+
import { useNavigate } from "react-router-dom";
67

78
interface Props {
8-
currentContent: string;
9+
currentContent: string | undefined;
910
}
1011

1112
const HomeViewContent = ({ currentContent }: Props) => {
1213
// - - - - States - - - -
1314
// toggleQueue false = projQueue1, toggleQueue true = projQueue2
1415
const [toggleQueue, setToggleQueue] = useState(false);
16+
const navigate = useNavigate();
1517
// - - - - Projects - - - -
1618
const allProjList = {
17-
Deerfall: <Deerfall isPortfolio={true} />,
18-
MediaMatchup: <MediaMatchup isPortfolio={true} />,
19+
deerfall: <Deerfall isPortfolio={true} />,
20+
mediamatchup: <MediaMatchup isPortfolio={true} />,
1921
};
2022
const gameDevProjList = {
21-
Deerfall: <Deerfall isPortfolio={true} />,
23+
deerfall: <Deerfall isPortfolio={true} />,
2224
};
2325
const webDevProjList = {
24-
MediaMatchup: <MediaMatchup isPortfolio={true} />,
26+
mediamatchup: <MediaMatchup isPortfolio={true} />,
2527
};
2628
const [currProjArray, setCurrProjArray] = useState<JSX.Element[]>([]);
2729
// - - - - Transitions - - - -
@@ -34,7 +36,9 @@ const HomeViewContent = ({ currentContent }: Props) => {
3436
});
3537

3638
useEffect(() => {
37-
setCurrProjArray([eval(`allProjList.${currentContent}`)]);
39+
if (currentContent) {
40+
setCurrProjArray([eval(`allProjList.${currentContent}`)]);
41+
}
3842
}, [currentContent]);
3943

4044
return (

src/components/HomeViewFooter.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ import AppContext from "../contexts/AppContext";
55
import "./styles/HomeViewFooter.css";
66

77
interface Props {
8-
currentContent: string;
9-
allParamsObj: {
10-
param1: string;
11-
param2: string;
12-
param3: string;
13-
param4: string;
14-
};
8+
allParams: string[];
159
}
1610

17-
const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
11+
const HomeViewFooter = ({ allParams }: Props) => {
1812
const currentYear = new Date();
1913
const { hueRotation } = useContext(AppContext);
2014

@@ -23,15 +17,15 @@ const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
2317
<div className='project-nav-ctr'>
2418
<div className='project-nav'>
2519
<span className='material-symbols-outlined'>chevron_left</span>
26-
<h2>{currentContent}</h2>
20+
<h2>{allParams[3]}</h2>
2721
<span className='material-symbols-outlined'>chevron_right</span>
2822
</div>
2923

3024
<div className='nav-ctr'>
3125
<ul>
3226
<li>
3327
<NavLink
34-
to={`/${allParamsObj.param1}/portfolio/${allParamsObj.param3}`}
28+
to={`/${allParams[0]}/portfolio/${allParams[2]}`}
3529
className={({ isActive }) =>
3630
isActive ? "highlighted-link" : ""
3731
}>
@@ -40,7 +34,7 @@ const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
4034
</li>
4135
<li>
4236
<NavLink
43-
to={`/${allParamsObj.param1}/blog/${allParamsObj.param3}`}
37+
to={`/${allParams[0]}/blog/${allParams[2]}`}
4438
className={({ isActive }) =>
4539
isActive ? "highlighted-link" : ""
4640
}>
@@ -49,7 +43,7 @@ const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
4943
</li>
5044
<li>
5145
<NavLink
52-
to={`/${allParamsObj.param1}/introduction`}
46+
to={`/${allParams[0]}/introduction`}
5347
className={({ isActive }) =>
5448
isActive ? "highlighted-link" : ""
5549
}>

0 commit comments

Comments
 (0)