-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
166 lines (148 loc) · 4.94 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import "./App.css";
import React, { useState } from "react";
import { Toggle } from "./components/toggle";
import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom";
import { Home } from "./pages/Home";
import { GetInTouch } from "./pages/GetInTouch";
import { DSite } from "./pages/DSite";
import { IoMoon } from "react-icons/io5";
import { IoSunny } from "react-icons/io5";
import { Works } from "./pages/Works";
import { useEffect } from "react";
import { useLocation } from "react-router-dom";
import { AddressGen } from "./pages/AddressGen";
import { UI3 } from "./pages/UI3";
import { About } from "./pages/About";
// icons: https://react-icons.github.io/react-icons/icons?name=io5
function setTheme(themeName: string) {
localStorage.setItem("data-theme", themeName);
document.documentElement.setAttribute("data-theme", themeName);
}
(function () {
if (localStorage.getItem("data-theme") === "dark") {
setTheme("dark");
} else {
setTheme("light");
}
})();
function App() {
const [toggleDirection, setToggleDirection] = React.useState(
localStorage.getItem("data-theme") === "light" ? 16 : 0
);
const [selectedNav, setSelectedNav] = React.useState("");
const toggleOn = () => {
setToggleDirection(toggleDirection === 16 ? 0 : 16);
let theme = localStorage.getItem("data-theme");
if (theme === "dark") {
setTheme("light");
} else {
setTheme("dark");
}
};
const toggle = (
<div className="toggle-container">
<div className="body-1">
{localStorage.getItem("data-theme") === "light" ? (
<IoSunny fill="var(--fg-contrast)" />
) : (
<IoMoon fill="var(--fg-contrast)" />
)}
</div>
<Toggle onTap={toggleOn} toggleDirection={toggleDirection} />
</div>
);
const bigDiv = document.getElementById("big-div");
const [currentPage, setCurrentPage] = useState("");
function ScrollToTop() {
const { pathname } = useLocation();
useEffect(() => {
if (bigDiv) bigDiv.scrollTo(0, 0);
setCurrentPage(pathname);
}, [pathname]);
return null;
}
return (
<div
className="App flex flex-col gap-28"
data-theme={localStorage.getItem("data-theme")}
>
<style>
@import
url('https://fonts.googleapis.com/css2?family=DM+Serif+Text:ital@0;1&family=Inter:wght@400;500;700&display=swap');
</style>
<Router>
<ScrollToTop />
<div
id="big-div"
className="h-screen w-screen overflow-scroll bg-gradient-to-tr from-[color:var(--bg-gradient-1)] to-[color:var(--bg-gradient-2)] scroll-smooth"
>
<div className="flex justify-between px-16 py-4 absolute w-full items-center">
{currentPage === "/" ? (
<Link
className="subtitle link"
to="/"
onClick={() => {
setSelectedNav("home");
}}
>
• Donnie's Awesome Website
</Link>
) : (
<Link
className="subtitle link"
to="/"
onClick={() => {
setSelectedNav("home");
if (bigDiv) bigDiv.scrollTo(0, 100);
}}
>
{"<-"} Back
</Link>
)}
<div className="flex gap-10">
<div className="flex flex-row body-2 text-[color:var(--fg-contrast)] font-semibold bg-transparent items-center ">
<Link
className={`body-1 px-3 py-2 rounded-md ${
selectedNav === "about"
? `bg-[color:rgba(0,0,0,0.1)]`
: null
}`}
to="/about"
onClick={() => {
setSelectedNav("about");
}}
>
About
</Link>
<Link
className={`body-1 px-3 py-2 rounded-md ${
selectedNav === "getInTouch"
? `bg-[color:rgba(0,0,0,0.1)]`
: null
}`}
to="/getintouch"
onClick={() => {
setSelectedNav("getInTouch");
}}
>
Get in touch
</Link>
</div>
{toggle}
</div>
</div>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/getintouch" element={<GetInTouch />} />
<Route path="/works/this-site" element={<DSite />} />
<Route path="/works" element={<Works />} />
<Route path="/about" element={<About />} />
<Route path="/works/address-generator" element={<AddressGen />} />
<Route path="/works/ui-3" element={<UI3 />} />
</Routes>
</div>
</Router>
</div>
);
}
export default App;