Skip to content

Commit abb0576

Browse files
committed
While trying to use param4 (/:project) to link to the default project associated with a category (web dev or gamedev), I realized using the parameter in the link will always link to whatever the current param is, even though state sets things properly immediately after for displaying the project name and other elements of the param. What this means is I will HAVE to handle this navigation programattically (at least I believe). Working on handling the check and navigating properly if this is the case.
1 parent faae7ac commit abb0576

File tree

8 files changed

+90
-65
lines changed

8 files changed

+90
-65
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: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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

@@ -36,24 +37,50 @@ const HomeView = ({}: Props) => {
3637
// - - - - CONTEXT - - - -
3738
const { hueRotation, setHueDuration } = useContext(AppContext);
3839
// - - - - - TITLES AND TEXT - - - - -
39-
const [currentContent, setCurrentContent] = useState<string>("Deerfall");
40-
const [title, setTitle] = useState<string>("Dev Blog");
4140
const [subtitle, setSubtitle] = useState<string>("Welcome! ");
4241
const [subEmoji, setSubEmoji] = useState<string>(" 🙂");
4342
// - - - - - PROJECTS - - - - -
44-
const gameDevProjList = ["Deerfall"];
45-
const webDevProjList = ["MediaMatchup"];
43+
const gameDevProjList = ["deerfall"];
44+
const webDevProjList = ["mediamatchup"];
45+
const [currentContent, setCurrentContent] = useState<string | undefined>();
4646

4747
// - - - - - FUNCTIONS - - - - -
48-
const checkURL = () => {
48+
const checkDefaultProject = () => {
49+
let isGameDev = param3 === "gamedev";
50+
let isWebDev = param3 === "webdev";
51+
let isGameDevProj = gameDevProjList.includes(param4);
52+
let isWebDevProj = webDevProjList.includes(param4);
53+
// checks location and
54+
if (isGameDev && !isGameDevProj) {
55+
setParam4(gameDevProjList[0]);
56+
} else if (isWebDev && !isWebDevProj) {
57+
setParam4(webDevProjList[0]);
58+
}
59+
};
60+
61+
const checkProjectParams = () => {
62+
let construct_URL = `/${param1}/${param2}/${param3}/${param4}`;
63+
// booleans
64+
let projectIsCurrent_URL = param4 === project;
65+
let isSame_URL = construct_URL === location.pathname;
66+
let isIntroduction_URL = param2 === "introduction";
67+
68+
if (param4 && !projectIsCurrent_URL && !isSame_URL && !isIntroduction_URL) {
69+
navigate(construct_URL);
70+
}
71+
};
72+
73+
const validateURL = () => {
4974
let URLSegments = [landingOrHome, category1, gameOrWeb, project];
5075
let paramArray = [param1_Opts, param2_Opts, param3_Opts, param4_Opts];
76+
// verifies if this should be the landing page
5177
if (location.pathname === "/") {
5278
navigate("/landing");
5379
setIsLanding(true);
5480
} else if (location.pathname === "/landing") {
5581
setIsLanding(true);
5682
}
83+
// compares segments of the URL against valid options
5784
for (let i = 0; i < URLSegments.length; i++) {
5885
if (URLSegments[i]) {
5986
let found = paramArray[i].find((item) => item === URLSegments[i]);
@@ -67,20 +94,31 @@ const HomeView = ({}: Props) => {
6794
};
6895

6996
// - - - - - useEffects - - - - -
70-
useEffect(() => {
71-
setAllParamsObj({ param1, param2, param3, param4 });
72-
}, [param1, param2, param3, param4]);
73-
7497
useEffect(() => {
7598
if (!isLanding) {
76-
checkURL();
99+
validateURL();
77100
if (hueRotation != AppConfig.hueAnimDuration_Slow) {
78101
setHueDuration(AppConfig.hueAnimDuration_Slow);
79102
}
80103
}
81-
console.log(category1);
104+
console.log("- - - - - - - -");
105+
106+
console.log(`individual params: /${param1}/${param2}/${param3}/${param4}`);
107+
console.log(
108+
`params object: /${allParamsObj.param1}/${allParamsObj.param2}/${allParamsObj.param3}/${allParamsObj.param4}`
109+
);
110+
console.log(`current URL: ${location.pathname}`);
111+
console.log("- - - - - - - -");
82112
}, [location]);
83113

114+
useEffect(() => {
115+
setAllParamsObj({ param1, param2, param3, param4 });
116+
}, [param1, param2, param3, param4]);
117+
118+
useEffect(() => {
119+
checkDefaultProject();
120+
}, [allParamsObj]);
121+
84122
// - - - - - JSX - - - - -
85123
return (
86124
<div className='HomeView'>
@@ -95,12 +133,11 @@ const HomeView = ({}: Props) => {
95133
<HomeViewHeader
96134
subtitle={subtitle}
97135
subEmoji={subEmoji}
98-
currentContent={currentContent}
99-
allParamsObj={allParamsObj}
136+
allParams={allParamsObj}
100137
isLanding={isLanding}
101138
/>
102-
<Outlet />
103-
<HomeViewFooter currentContent={"deerfall"} allParamsObj={allParamsObj} />
139+
<HomeViewContent currentContent={param4} />
140+
<HomeViewFooter allParams={allParamsObj} />
104141
</div>
105142
);
106143
};

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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import AppContext from "../contexts/AppContext";
55
import "./styles/HomeViewFooter.css";
66

77
interface Props {
8-
currentContent: string;
9-
allParamsObj: {
8+
allParams: {
109
param1: string;
1110
param2: string;
1211
param3: string;
1312
param4: string;
1413
};
1514
}
1615

17-
const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
16+
const HomeViewFooter = ({ allParams }: Props) => {
1817
const currentYear = new Date();
1918
const { hueRotation } = useContext(AppContext);
2019

@@ -23,15 +22,15 @@ const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
2322
<div className='project-nav-ctr'>
2423
<div className='project-nav'>
2524
<span className='material-symbols-outlined'>chevron_left</span>
26-
<h2>{currentContent}</h2>
25+
<h2>{allParams.param4}</h2>
2726
<span className='material-symbols-outlined'>chevron_right</span>
2827
</div>
2928

3029
<div className='nav-ctr'>
3130
<ul>
3231
<li>
3332
<NavLink
34-
to={`/${allParamsObj.param1}/portfolio/${allParamsObj.param3}`}
33+
to={`/${allParams.param1}/portfolio/${allParams.param3}`}
3534
className={({ isActive }) =>
3635
isActive ? "highlighted-link" : ""
3736
}>
@@ -40,7 +39,7 @@ const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
4039
</li>
4140
<li>
4241
<NavLink
43-
to={`/${allParamsObj.param1}/blog/${allParamsObj.param3}`}
42+
to={`/${allParams.param1}/blog/${allParams.param3}`}
4443
className={({ isActive }) =>
4544
isActive ? "highlighted-link" : ""
4645
}>
@@ -49,7 +48,7 @@ const HomeViewFooter = ({ currentContent, allParamsObj }: Props) => {
4948
</li>
5049
<li>
5150
<NavLink
52-
to={`/${allParamsObj.param1}/introduction`}
51+
to={`/${allParams.param1}/introduction`}
5352
className={({ isActive }) =>
5453
isActive ? "highlighted-link" : ""
5554
}>

src/components/HomeViewHeader.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import "./styles/HomeViewHeader.css";
77
interface Props {
88
subtitle: string;
99
subEmoji: string;
10-
currentContent: string;
1110
isLanding: boolean;
12-
allParamsObj: {
11+
allParams: {
1312
param1: string;
1413
param2: string;
1514
param3: string;
@@ -20,22 +19,21 @@ interface Props {
2019
const HomeViewHeader = ({
2120
subtitle,
2221
subEmoji,
23-
currentContent,
2422
isLanding,
25-
allParamsObj,
23+
allParams,
2624
}: Props) => {
2725
// GENERAL
2826
const { hueRotation } = useContext(AppContext);
2927
const [isIntro, setIsIntro] = useState<boolean>(false);
3028
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0);
3129

3230
useEffect(() => {
33-
if (allParamsObj.param2 === "introduction") {
31+
if (allParams.param2 === "introduction") {
3432
setIsIntro(true);
3533
} else {
3634
setIsIntro(false);
3735
}
38-
}, [allParamsObj.param2]);
36+
}, [allParams.param2]);
3937

4038
useEffect(() => {
4139
forceUpdate();
@@ -54,8 +52,8 @@ const HomeViewHeader = ({
5452
{`${isIntro ? "?" : "'s"} `}
5553
</animated.span>
5654
<animated.span style={hueRotation} className='highlighted-link'>
57-
{isIntro ? "" : `${allParamsObj.param3}`}
58-
{isIntro ? "" : ` ${allParamsObj.param2}`}
55+
{isIntro ? "" : `${allParams.param3}`}
56+
{isIntro ? "" : ` ${allParams.param2}`}
5957
</animated.span>
6058
</h1>
6159
<p className='subtitle'>
@@ -67,18 +65,18 @@ const HomeViewHeader = ({
6765
<div className='project-nav-ctr'>
6866
<div className='project-nav'>
6967
<span className='material-symbols-outlined'>chevron_left</span>
70-
<h2>{currentContent}</h2>
68+
<h2>{allParams.param4}</h2>
7169
<span className='material-symbols-outlined'>chevron_right</span>
7270
</div>
7371

7472
<div className='project-nav-type-cat'>
7573
<NavLink
76-
to={`/${allParamsObj.param1}/${allParamsObj.param2}/gamedev`}
74+
to={`/${allParams.param1}/${allParams.param2}/gamedev`}
7775
className={({ isActive }) => (isActive ? "highlighted-link" : "")}>
7876
<animated.p style={hueRotation}>gamedev</animated.p>
7977
</NavLink>
8078
<NavLink
81-
to={`/${allParamsObj.param1}/${allParamsObj.param2}/webdev`}
79+
to={`/${allParams.param1}/${allParams.param2}/webdev`}
8280
className={({ isActive }) => (isActive ? "highlighted-link" : "")}>
8381
<animated.p style={hueRotation}>webdev</animated.p>
8482
</NavLink>
@@ -89,7 +87,7 @@ const HomeViewHeader = ({
8987
<ul>
9088
<li>
9189
<NavLink
92-
to={`/${allParamsObj.param1}/${allParamsObj.param2}/gamedev`}
90+
to={`/${allParams.param1}/${allParams.param2}/gamedev`}
9391
className={({ isActive }) =>
9492
isActive ? "highlighted-link" : ""
9593
}>
@@ -98,7 +96,7 @@ const HomeViewHeader = ({
9896
</li>
9997
<li>
10098
<NavLink
101-
to={`/${allParamsObj.param1}/${allParamsObj.param2}/webdev`}
99+
to={`/${allParams.param1}/${allParams.param2}/webdev`}
102100
className={({ isActive }) =>
103101
isActive ? "highlighted-link" : ""
104102
}>

src/components/LandingPage.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ const LandingPage = ({ setIsLanding, setParamsArray }: Props) => {
2626
const navigate = useNavigate();
2727

2828
// - - - - - CONTEXT - - - - -
29-
const { currentPathContext, setCurrentPathContext } = useContext(AuthContext);
29+
const { setCurrentPathContext } = useContext(AuthContext);
3030
const { hueRotation, setHueDuration } = useContext(AppContext);
3131

3232
// - - - - - BG TRANSITION - - - - -
3333
const [hideLP, setHideLP] = useState<string>("");
34-
const [hideHV, setHideHV] = useState<string>("hide");
3534
const [isActivePage, setIsActivePage] = useState<boolean>(true);
3635
const [currBG, setCurrBG] = useState<string>(pixelBG);
3736

@@ -65,7 +64,6 @@ const LandingPage = ({ setIsLanding, setParamsArray }: Props) => {
6564
) {
6665
setCurrBG(pixelFadeBG);
6766
setIsActivePage(false);
68-
setHideHV("");
6967
setTimeout(() => setIsLanding(false), 1500);
7068
setParamsArray[0]("home");
7169
setHueDuration(AppConfig.hueAnimDuration_Slow);
@@ -75,7 +73,6 @@ const LandingPage = ({ setIsLanding, setParamsArray }: Props) => {
7573
navigate("/landing");
7674
setCurrBG(pixelBG);
7775
setIsActivePage(true);
78-
setHideHV("hide");
7976
setHideLP("");
8077
setHueDuration(4000);
8178
} else if (currentPath === "/landing") {

src/components/styles/HomeViewFooter.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
/* Style */
2525
color: white;
2626
border: solid white 2px;
27-
background-color: rgba(96, 96, 96, 0.4);
27+
background-color: rgba(96, 96, 96, 0.3);
28+
backdrop-filter: blur(2px);
2829
font-size: 16px;
2930
}
3031

0 commit comments

Comments
 (0)