├── .gitignore
├── License.md
├── README.md
├── README_images
├── contact.png
├── hero.png
├── heroDark.png
└── speed.png
├── package-lock.json
├── package.json
├── public
├── GH.png
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
├── maskable_icon.png
└── robots.txt
└── src
├── App.js
├── app
├── apiSlice.js
├── appSlice.js
├── projectsSlice.js
└── store.js
├── components
├── AboutMe.jsx
├── AppFallback.jsx
├── BackToTop.jsx
├── Contact.jsx
├── ContactForm.jsx
├── Footer.jsx
├── GlobalStyles.js
├── Hero.jsx
├── Loading.jsx
├── NavBar.jsx
├── ProjectCard.jsx
├── Projects.jsx
├── ScrollToTop.js
├── Skills.jsx
├── SocialLinks.jsx
├── ThemeToggle.jsx
└── Title.jsx
├── config.js
├── custom.scss
├── images
├── GH.svg
├── defaultNavLogo.svg
├── hero-dark.jpg
├── hero-light.jpg
└── logo.svg
├── index.js
├── pages
├── AllProjects.jsx
├── Home.jsx
└── NotFound.jsx
├── service-worker.js
├── serviceWorkerRegistration.js
└── utils.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 | .eslintcache
21 | .prettierrc
22 |
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2020 Michael Huber
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # A React Portfolio Template for GitHub
2 |
3 | [](https://github.com/mshuber1981/github-react-portfolio-template/stargazers/) [](https://github.com/mshuber1981/github-react-portfolio-template/network/members) [](https://twitter.com/intent/tweet?text=Thanks%20for%20the%20awesome%20Portfolio%20Template!%20https://github.com/mshuber1981/github-react-portfolio-template&via=MikeyHuber1981)
4 |
5 | A performant, accessible, progressive React portfolio template that uses the [GitHub REST API](https://docs.github.com/en/free-pro-team@latest/rest).
6 |
7 | Add your GitHub username once and all of your info will automatically be updated. Deploy to GitHub pages in a few simple steps.
8 |
9 | ## [Live Demo](https://mshuber1981.github.io/github-react-portfolio-template/#/)
10 |
11 | [Google PageSpeed Insights](https://developers.google.com/speed/pagespeed/insights/)
12 |
13 | 
14 |
15 | ## Light And Dark Themes
16 |
17 | 
18 |
19 | 
20 |
21 | ### Getting Started
22 |
23 | 1. [Create a repository from this template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
24 | 2. [Clone your new repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
25 | 3. Make sure [Node](https://nodejs.org/en/) is installed
26 | 4. Open your project and install the dependencies
27 |
28 | ```bash
29 | npm install
30 | ```
31 |
32 | 5. Navigate to the src directory and open src/config.js
33 | 6. Add your GitHub username ([src/config.js](https://github.com/mshuber1981/github-react-portfolio-template/blob/main/src/config.js#L18) line 18)
34 |
35 | ```javascript
36 | /* START HERE
37 | **************************************************************
38 | Add your GitHub username (string - "YourUsername") below.
39 | */
40 | export const githubUsername = "Your GitHub username here";
41 | ```
42 |
43 | 7. Start the development server to view the results
44 |
45 | ```bash
46 | npm start
47 | ```
48 |
49 | ### Updating the Contact section
50 |
51 | 
52 |
53 | 1. The contact form uses [Formspree](https://formspree.io/), create an account and add your endpoint URL ([src/config.js](https://github.com/mshuber1981/github-react-portfolio-template/blob/main/src/config.js#L114) line 114)
54 |
55 | ```javascript
56 | /* Contact Info
57 | **************************************************************
58 | Add your formspree endpoint below.
59 | https://formspree.io/
60 | */
61 | export const formspreeUrl = "https://formspree.io/f/YourEndpoint";
62 | ```
63 |
64 | ### Deploy
65 |
66 | A helpful guide for Create React App deployments with GitHub Pages can be found [here](https://create-react-app.dev/docs/deployment#github-pages).
67 |
68 | 1. Update the homepage value ([package.json](https://github.com/mshuber1981/github-react-portfolio-template/blob/main/package.json#L3) line 3)
69 |
70 | ```json
71 | "homepage": "https://YourUserName.github.io/your-repo/",
72 | ```
73 |
74 | 2. Run the deploy command
75 |
76 | ```bash
77 | npm run deploy
78 | ```
79 |
80 | ### Customization Options
81 |
82 | Checkout the [Wiki](https://github.com/mshuber1981/github-react-portfolio-template/wiki) for additional customization options:
83 |
84 | - [Updating the Navbar Logo](https://github.com/mshuber1981/github-react-portfolio-template/wiki/Updating-the-Navbar-Logo)
85 | - [Updating the Main section](https://github.com/mshuber1981/github-react-portfolio-template/wiki/Updating-the-Main-section)
86 | - [Updating the About Me section](https://github.com/mshuber1981/github-react-portfolio-template/wiki/Updating-the-About-Me-section)
87 | - [Updating the Skills section](https://github.com/mshuber1981/github-react-portfolio-template/wiki/Updating-the-Skills-section)
88 | - [Updating the Projects section](https://github.com/mshuber1981/github-react-portfolio-template/wiki/Updating-the-Projects-section)
89 | - [Updating the theme color](https://github.com/mshuber1981/github-react-portfolio-template/wiki/Updating-the-theme-color)
90 | - [Updating the Footer icons theme (light or dark)](https://github.com/mshuber1981/github-react-portfolio-template/wiki/Updating-the-Footer-icons-theme)
91 |
92 | [Back to top :top:](#a-react-portfolio-template-for-github)
93 |
94 | ### License
95 |
96 | [MIT](https://choosealicense.com/licenses/mit/)
97 |
--------------------------------------------------------------------------------
/README_images/contact.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/README_images/contact.png
--------------------------------------------------------------------------------
/README_images/hero.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/README_images/hero.png
--------------------------------------------------------------------------------
/README_images/heroDark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/README_images/heroDark.png
--------------------------------------------------------------------------------
/README_images/speed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/README_images/speed.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "github-react-portfolio-template",
3 | "homepage": "https://YourUserName.github.io/your-repo/",
4 | "version": "1.0.4",
5 | "private": true,
6 | "dependencies": {
7 | "@iconify/react": "^4.1.0",
8 | "@reduxjs/toolkit": "^2.5.0",
9 | "bootstrap": "^5.3.3",
10 | "prop-types": "^15.8.1",
11 | "react": "^18.3.1",
12 | "react-bootstrap": "^2.10.7",
13 | "react-dom": "^18.3.1",
14 | "react-error-boundary": "^4.1.2",
15 | "react-redux": "^9.2.0",
16 | "react-router-dom": "^6.28.1",
17 | "react-scroll": "^1.8.7",
18 | "sass": "^1.77.6",
19 | "styled-components": "^6.1.14",
20 | "workbox-core": "^7.3.0",
21 | "workbox-expiration": "^7.3.0",
22 | "workbox-precaching": "^7.3.0",
23 | "workbox-routing": "^7.3.0",
24 | "workbox-strategies": "^7.3.0"
25 | },
26 | "devDependencies": {
27 | "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
28 | "gh-pages": "^6.3.0",
29 | "react-scripts": "^5.0.1"
30 | },
31 | "scripts": {
32 | "predeploy": "npm run build",
33 | "deploy": "gh-pages -d build",
34 | "start": "react-scripts start",
35 | "build": "react-scripts build",
36 | "test": "react-scripts test",
37 | "eject": "react-scripts eject"
38 | },
39 | "eslintConfig": {
40 | "extends": [
41 | "react-app",
42 | "react-app/jest"
43 | ]
44 | },
45 | "browserslist": {
46 | "production": [
47 | ">0.2%",
48 | "not dead",
49 | "not op_mini all"
50 | ],
51 | "development": [
52 | "last 1 chrome version",
53 | "last 1 firefox version",
54 | "last 1 safari version"
55 | ]
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/public/GH.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/public/GH.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
32 |
33 |
42 | React App
43 |
44 |
45 | You need to enable JavaScript to run this app.
46 |
47 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "Portfolio",
3 | "name": "My GitHub Portfolio",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | },
20 | {
21 | "src": "maskable_icon.png",
22 | "type": "image/png",
23 | "sizes": "240x240",
24 | "purpose": "any maskable"
25 | }
26 | ],
27 | "start_url": ".",
28 | "display": "standalone",
29 | "theme_color": "#000000",
30 | "background_color": "#ffffff"
31 | }
32 |
--------------------------------------------------------------------------------
/public/maskable_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/public/maskable_icon.png
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import { ThemeProvider } from "styled-components";
4 | // State
5 | import { useDispatch, useSelector } from "react-redux";
6 | import { selectMode, setMode } from "./app/appSlice";
7 | import {
8 | setProjects,
9 | setMainProjects,
10 | selectProjects,
11 | } from "./app/projectsSlice";
12 | import { useGetUsersQuery, useGetProjectsQuery } from "./app/apiSlice";
13 | import PropTypes from "prop-types";
14 | // Router
15 | import { HashRouter, Routes, Route } from "react-router-dom";
16 | // Pages
17 | import Home from "./pages/Home";
18 | import AllProjects from "./pages/AllProjects";
19 | import NotFound from "./pages/NotFound";
20 | // Components
21 | import { ErrorBoundary } from "react-error-boundary";
22 | import AppFallback from "./components/AppFallback";
23 | import GlobalStyles from "./components/GlobalStyles";
24 | import ScrollToTop from "./components/ScrollToTop";
25 | import Loading from "./components/Loading";
26 | import { Element } from "react-scroll";
27 | import { Container } from "react-bootstrap";
28 | import NavBar from "./components/NavBar";
29 | import Footer from "./components/Footer";
30 | // Config
31 | import { footerTheme, navLogo } from "./config";
32 | // Util
33 | import { getStoredTheme, getPreferredTheme, setTheme } from "./utils";
34 |
35 | // #region component
36 | const propTypes = {
37 | filteredProjects: PropTypes.arrayOf(PropTypes.string),
38 | projectCardImages: PropTypes.arrayOf(
39 | PropTypes.shape({
40 | name: PropTypes.string.isRequired,
41 | image: PropTypes.node.isRequired,
42 | })
43 | ),
44 | };
45 |
46 | const App = ({ projectCardImages = [], filteredProjects = [] }) => {
47 | const theme = useSelector(selectMode);
48 | const projects = useSelector(selectProjects);
49 | const dispatch = useDispatch();
50 | const { isLoading, isSuccess, isError, error } = useGetUsersQuery();
51 | const { data: projectsData } = useGetProjectsQuery();
52 | let content;
53 |
54 | // Set all projects state
55 | React.useEffect(() => {
56 | const tempData = [];
57 | if (projectsData !== undefined && projectsData.length !== 0) {
58 | projectsData.forEach((element) => {
59 | const tempObj = {
60 | id: null,
61 | homepage: null,
62 | description: null,
63 | image: null,
64 | name: null,
65 | html_url: null,
66 | };
67 | tempObj.id = element.id;
68 | tempObj.homepage = element.homepage;
69 | tempObj.description = element.description;
70 | tempObj.name = element.name;
71 | tempObj.html_url = element.html_url;
72 | tempData.push(tempObj);
73 | });
74 | if (
75 | projectCardImages !== (undefined && null) &&
76 | projectCardImages.length !== 0
77 | ) {
78 | projectCardImages.forEach((element) => {
79 | tempData.forEach((ele) => {
80 | if (element.name.toLowerCase() === ele.name.toLowerCase()) {
81 | ele.image = element.image;
82 | }
83 | });
84 | });
85 | }
86 | dispatch(setProjects(tempData));
87 | }
88 | }, [projectsData, projectCardImages, dispatch]);
89 |
90 | // Set main projects state
91 | React.useEffect(() => {
92 | if (projects.length !== 0) {
93 | if (
94 | filteredProjects !== (undefined && null) &&
95 | filteredProjects.length !== 0
96 | ) {
97 | const tempArray = projects.filter((obj) =>
98 | filteredProjects.includes(obj.name)
99 | );
100 | tempArray.length !== 0
101 | ? dispatch(setMainProjects([...tempArray]))
102 | : dispatch(setMainProjects([...projects.slice(0, 3)]));
103 | } else {
104 | dispatch(setMainProjects([...projects.slice(0, 3)]));
105 | }
106 | }
107 | }, [projects, filteredProjects, dispatch]);
108 |
109 | // Theme
110 | const setThemes = React.useCallback(
111 | (theme) => {
112 | if (theme) {
113 | dispatch(setMode(theme));
114 | setTheme(theme);
115 | } else {
116 | dispatch(setMode(getPreferredTheme()));
117 | setTheme(getPreferredTheme());
118 | }
119 | },
120 | [dispatch]
121 | );
122 |
123 | React.useEffect(() => {
124 | setThemes();
125 | }, [setThemes]);
126 |
127 | window
128 | .matchMedia("(prefers-color-scheme: dark)")
129 | .addEventListener("change", () => {
130 | const storedTheme = getStoredTheme();
131 | if (storedTheme !== "light" && storedTheme !== "dark") {
132 | setThemes();
133 | }
134 | });
135 |
136 | if (isLoading) {
137 | content = (
138 |
139 |
140 |
141 | );
142 | } else if (isSuccess) {
143 | content = (
144 | <>
145 |
146 | setThemes(theme)} />
147 |
148 |
149 | } />
150 | } />
151 | } />
152 |
153 |
154 | >
155 | );
156 | } else if (isError) {
157 | content = (
158 |
159 |
160 | {error.status !== "FETCH_ERROR"
161 | ? `${error.status}: ${error.data.message} - check githubUsername in src/config.js`
162 | : `${error.status} - check URLs in src/app/apiSlice.js`}
163 |
164 |
165 | );
166 | }
167 |
168 | return (
169 |
170 | {/* https://reactrouter.com/6.28.0/upgrading/future#v7_starttransition */}
171 | {/* https://reactrouter.com/6.28.0/upgrading/future#v7_relativesplatpath */}
172 |
173 |
174 |
175 |
176 | {content}
177 |
178 |
179 |
180 | );
181 | };
182 |
183 | App.propTypes = propTypes;
184 | // #endregion
185 |
186 | export default App;
187 |
--------------------------------------------------------------------------------
/src/app/apiSlice.js:
--------------------------------------------------------------------------------
1 | // https://redux-toolkit.js.org/rtk-query/overview
2 | import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
3 | // Config
4 | import { githubUsername } from "../config";
5 |
6 | export const apiSlice = createApi({
7 | reducerPath: "api",
8 | baseQuery: fetchBaseQuery({ baseUrl: "https://api.github.com" }),
9 | endpoints: (builder) => ({
10 | // https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-a-user
11 | getUsers: builder.query({
12 | query: () => `/users/${githubUsername}`,
13 | }),
14 | // https://docs.github.com/en/rest/users/social-accounts?apiVersion=2022-11-28#list-social-accounts-for-a-user
15 | getSocials: builder.query({
16 | query: () => `/users/${githubUsername}/social_accounts`,
17 | }),
18 | // https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-a-user
19 | getProjects: builder.query({
20 | query: () => `/users/${githubUsername}/repos`,
21 | }),
22 | }),
23 | });
24 |
25 | export const { useGetUsersQuery, useGetSocialsQuery, useGetProjectsQuery } =
26 | apiSlice;
27 |
--------------------------------------------------------------------------------
/src/app/appSlice.js:
--------------------------------------------------------------------------------
1 | // https://redux-toolkit.js.org/usage/usage-guide#simplifying-slices-with-createslice
2 | import { createSlice } from "@reduxjs/toolkit";
3 |
4 | const initialState = {
5 | mode: "light",
6 | };
7 |
8 | export const appSlice = createSlice({
9 | name: "app",
10 | initialState,
11 | reducers: {
12 | setMode: (state, action) => {
13 | state.mode = action.payload;
14 | },
15 | },
16 | });
17 |
18 | export const selectMode = (state) => state.app.mode;
19 | export const { setMode } = appSlice.actions;
20 |
21 | export default appSlice.reducer;
22 |
--------------------------------------------------------------------------------
/src/app/projectsSlice.js:
--------------------------------------------------------------------------------
1 | // https://redux-toolkit.js.org/usage/usage-guide#simplifying-slices-with-createslice
2 | import { createSlice } from "@reduxjs/toolkit";
3 |
4 | const initialState = {
5 | projects: [],
6 | mainProjects: [],
7 | };
8 |
9 | export const projectsSlice = createSlice({
10 | name: "projects",
11 | initialState,
12 | reducers: {
13 | setProjects: (state, action) => {
14 | state.projects = action.payload;
15 | },
16 | setMainProjects: (state, action) => {
17 | state.mainProjects = action.payload;
18 | },
19 | },
20 | });
21 |
22 | export const selectProjects = (state) => state.projects.projects;
23 | export const selectMainProjects = (state) => state.projects.mainProjects;
24 | export const { setProjects, setMainProjects } = projectsSlice.actions;
25 |
26 | export default projectsSlice.reducer;
27 |
--------------------------------------------------------------------------------
/src/app/store.js:
--------------------------------------------------------------------------------
1 | // https://redux-toolkit.js.org/usage/usage-guide#simplifying-slices-with-createslice
2 | import { configureStore } from "@reduxjs/toolkit";
3 | //Reducers
4 | import appReducer from "./appSlice";
5 | import projectsReducer from "./projectsSlice";
6 | // API
7 | import { apiSlice } from "./apiSlice";
8 |
9 | export const store = configureStore({
10 | reducer: {
11 | app: appReducer,
12 | projects: projectsReducer,
13 | [apiSlice.reducerPath]: apiSlice.reducer,
14 | },
15 | middleware: (getDefaultMiddleware) => {
16 | return getDefaultMiddleware().concat(apiSlice.middleware);
17 | },
18 | });
19 |
--------------------------------------------------------------------------------
/src/components/AboutMe.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import PropTypes from "prop-types";
6 | // Components
7 | import { Element } from "react-scroll";
8 | import { Col, Container, Row } from "react-bootstrap";
9 | import Title from "./Title";
10 |
11 | // #region styled-components
12 | const StyledAboutMe = styled.section`
13 | p {
14 | font-size: 1.25rem;
15 | }
16 | .img {
17 | width: 18rem;
18 | height: 18rem;
19 | }
20 | `;
21 | // #endregion
22 |
23 | // #region component
24 | const propTypes = {
25 | avatar_url: PropTypes.string.isRequired,
26 | bio: PropTypes.string,
27 | moreInfo: PropTypes.string,
28 | };
29 |
30 | const AboutMe = ({ avatar_url, bio, moreInfo }) => {
31 | return (
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | {bio && {bio}
}
42 | {moreInfo && {moreInfo}
}
43 |
44 |
45 |
46 |
53 |
54 |
55 |
56 |
57 |
58 | );
59 | };
60 |
61 | AboutMe.propTypes = propTypes;
62 | // #endregion
63 |
64 | export default AboutMe;
65 |
--------------------------------------------------------------------------------
/src/components/AppFallback.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // State
3 | import PropTypes from "prop-types";
4 | // Components
5 | import { Container } from "react-bootstrap";
6 | // Utils
7 | import { getPreferredTheme, setTheme } from "../utils";
8 |
9 | // #region component
10 | const propTypes = { error: PropTypes.object.isRequired };
11 |
12 | const AppFallback = ({ error }) => {
13 | React.useEffect(() => {
14 | setTheme(getPreferredTheme());
15 | }, []);
16 |
17 | return (
18 |
19 |
20 | Something went wrong:
21 | {`${error.name}: ${error.message}`}
25 |
26 |
27 | );
28 | };
29 |
30 | AppFallback.propTypes = propTypes;
31 | // #endregion
32 |
33 | export default AppFallback;
34 |
--------------------------------------------------------------------------------
/src/components/BackToTop.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import PropTypes from "prop-types";
6 | // Icons
7 | import { Icon } from "@iconify/react";
8 | // Components
9 | import { Link } from "react-scroll";
10 |
11 | // #region styled-components
12 | const StyledDiv = styled.div`
13 | position: fixed;
14 | bottom: calc(var(--min-footer-height) + 1.5rem);
15 | right: 1.5rem;
16 | visibility: hidden;
17 | z-index: 2;
18 |
19 | .link-icons {
20 | color: ${({ theme }) => (theme.name === "light" ? "#45413C" : "#F5F2E8")};
21 | }
22 |
23 | &.show-up {
24 | visibility: visible;
25 | }
26 | `;
27 | // #endregion
28 |
29 | // #region component
30 | const propTypes = { home: PropTypes.string };
31 |
32 | const BackToTop = ({ home = "Home" }) => {
33 | const [scrollYNum, setScrollYNum] = React.useState(null);
34 | const up = React.useRef(null);
35 |
36 | React.useEffect(() => {
37 | const updateScrollY = () => {
38 | setScrollYNum(window.scrollY);
39 | if (scrollYNum > 500) {
40 | up.current.classList.add("show-up");
41 | } else {
42 | up.current.classList.remove("show-up");
43 | }
44 | };
45 | window.addEventListener("scroll", updateScrollY);
46 |
47 | return () => window.removeEventListener("scroll", updateScrollY);
48 | }, [scrollYNum]);
49 |
50 | return (
51 |
52 |
53 |
54 |
55 |
56 | );
57 | };
58 |
59 | BackToTop.propTypes = propTypes;
60 | // #endregion
61 |
62 | export default BackToTop;
63 |
--------------------------------------------------------------------------------
/src/components/Contact.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // Components
5 | import { Element } from "react-scroll";
6 | import Title from "./Title";
7 | import { Container } from "react-bootstrap";
8 | import ContactForm from "./ContactForm";
9 |
10 | // #region styled-components
11 | const StyledSection = styled.section`
12 | min-height: calc(100vh - var(--nav-height) - 2rem);
13 | `;
14 | // #endregion
15 |
16 | // #region component
17 | const Contact = () => {
18 | return (
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | );
30 | };
31 | // #endregion
32 |
33 | export default Contact;
34 |
--------------------------------------------------------------------------------
/src/components/ContactForm.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import { useSelector } from "react-redux";
6 | import { selectMode } from "../app/appSlice";
7 | // Components
8 | import { Alert, Button, Form, Spinner } from "react-bootstrap";
9 | // Config
10 | import { formspreeUrl } from "../config";
11 | // Util
12 | import { postData } from "../utils";
13 |
14 | // #region styled-components
15 | const StyledForm = styled.div`
16 | .form-control {
17 | background: ${({ theme }) =>
18 | theme.name === "light"
19 | ? "rgba(var(--bs-body-color-rgb), 0.03)"
20 | : "var(--bs-gray-dark)"};
21 | }
22 | `;
23 | // #endregion
24 |
25 | // #region component
26 | const ContactForm = () => {
27 | const [isValidated, setIsValidated] = React.useState(false);
28 | const [isProcessing, setIsProcessing] = React.useState(false);
29 | const [success, setSuccess] = React.useState(false);
30 | const [danger, setDanger] = React.useState(false);
31 | const [dangerMessage, setDangerMessage] = React.useState(null);
32 | const theme = useSelector(selectMode);
33 |
34 | const handleSubmit = async (event) => {
35 | const form = event.currentTarget;
36 | setSuccess(false);
37 | setDanger(false);
38 | setDangerMessage(null);
39 | if (form.checkValidity() === false) {
40 | event.preventDefault();
41 | event.stopPropagation();
42 | }
43 | setIsValidated(true);
44 | const { name, email, message } = form.elements;
45 | const data = {
46 | name: name.value,
47 | email: email.value,
48 | message: message.value,
49 | };
50 | if (form.checkValidity()) {
51 | event.preventDefault();
52 | event.persist();
53 | setIsProcessing(true);
54 | try {
55 | const response = await postData(formspreeUrl, data);
56 | if (!response.ok) {
57 | throw new Error(`${response.status}: check formspreeUrl in data.js`);
58 | }
59 | setIsProcessing(false);
60 | setIsValidated(false);
61 | event.target.reset();
62 | setSuccess(true);
63 | } catch (error) {
64 | setIsProcessing(false);
65 | setIsValidated(false);
66 | event.target.reset();
67 | setDangerMessage(error.message);
68 | setDanger(true);
69 | }
70 | }
71 | };
72 |
73 | return (
74 |
75 |
77 | Name
78 |
79 |
80 | Name must be at least one character.
81 |
82 |
83 |
84 | Email address
85 |
90 |
91 | Please enter a valid email.
92 |
93 |
94 |
95 | Message
96 |
97 |
98 | Please provide a valid message.
99 |
100 |
101 |
102 | {formspreeUrl && (
103 |
110 | Submit{" "}
111 | {isProcessing && (
112 |
113 | )}
114 |
115 | )}
116 | setSuccess(false)}
120 | dismissible
121 | >
122 | Success! I will contact you soon.
123 |
124 | setDanger(false)}
128 | dismissible
129 | >
130 | {dangerMessage}
131 |
132 |
133 |
134 | You must provide a valid formspree url in src/config.js
135 |
136 |
137 |
138 |
139 |
140 | );
141 | };
142 | // #endregion
143 |
144 | export default ContactForm;
145 |
--------------------------------------------------------------------------------
/src/components/Footer.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import PropTypes from "prop-types";
6 | // Components
7 | import SocialLinks from "./SocialLinks";
8 |
9 | // #region styled-components
10 | const StyledFooter = styled.footer`
11 | height: calc(var(--nav-height) + 1rem);
12 | background: var(--bs-primary);
13 |
14 | a {
15 | color: ${({ $mode }) => {
16 | if ($mode !== undefined && $mode !== null) {
17 | return $mode.toLowerCase() === "light"
18 | ? "var(--bs-light)"
19 | : "var(--bs-gray-dark)";
20 | } else {
21 | return "var(--bs-gray-dark)";
22 | }
23 | }};
24 |
25 | &:hover {
26 | color: ${({ $mode }) => {
27 | if ($mode !== undefined && $mode !== null) {
28 | return $mode.toLowerCase() === "light"
29 | ? "var(--bs-gray-dark)"
30 | : "var(--bs-light)";
31 | } else {
32 | return "var(--bs-gray-dark)";
33 | }
34 | }};
35 | }
36 | }
37 | `;
38 | // #endregion
39 |
40 | // #region component
41 | const propTypes = {
42 | mode: PropTypes.string.isRequired,
43 | };
44 |
45 | const Footer = ({ mode }) => {
46 | return (
47 |
51 |
52 |
53 | );
54 | };
55 |
56 | Footer.propTypes = propTypes;
57 | // #endregion
58 |
59 | export default Footer;
60 |
--------------------------------------------------------------------------------
/src/components/GlobalStyles.js:
--------------------------------------------------------------------------------
1 | import { createGlobalStyle } from "styled-components";
2 |
3 | const GlobalStyles = createGlobalStyle`
4 | /*
5 | ===============
6 | Variables
7 | ===============
8 | */
9 | :root {
10 | --border: 1px solid var(--bs-primary);
11 | --transition: all 0.3s linear;
12 | --nav-height: 55px;
13 | --min-footer-height: 11vh;
14 | --card-height: 29rem;
15 | }
16 |
17 | /*
18 | ===============
19 | Global Styles
20 | ===============
21 | */
22 | main {
23 | min-height: calc(100vh - 2 * var(--nav-height) - 2rem);
24 | }
25 |
26 | section {
27 | margin: 1rem 0;
28 | }
29 |
30 | .section {
31 | min-height: 100vh;
32 | display: grid;
33 | place-items: center;
34 | padding: var(--nav-height) 0;
35 | }
36 |
37 | a:hover {
38 | cursor: pointer;
39 | }
40 |
41 | .title {
42 | font-family: "Permanent Marker";
43 | }
44 |
45 | .link-icons {
46 | line-height: 0;
47 | font-size: 2.25rem;
48 | margin: 0 1rem;
49 | color: ${({ theme }) =>
50 | theme.name === "light" ? "var(--bs-dark)" : "var(--bs-light)"};
51 |
52 | &:hover {
53 | color: ${({ theme }) =>
54 | theme.name === "light" ? "var(--bs-light)" : "var(--bs-dark)"};
55 | }
56 | }
57 |
58 | .page-item.active .page-link {
59 | background-color: var(--bs-primary);
60 | border-color: var(--bs-primary);
61 | }
62 |
63 | @media screen and (min-width: 800px) {
64 | .link-icons {
65 | font-size: 2.5rem;
66 | }
67 | .form-group {
68 | max-width: 750px;
69 | }
70 | }
71 |
72 | @media screen and (min-width: 1367px) {
73 | .link-icons:hover {
74 | color: var(--bs-primary);
75 | }
76 | }
77 | `;
78 |
79 | export default GlobalStyles;
80 |
--------------------------------------------------------------------------------
/src/components/Hero.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled, { keyframes } from "styled-components";
4 | // State
5 | import PropTypes from "prop-types";
6 | // Icons
7 | import { Icon } from "@iconify/react";
8 | // Images
9 | import Logo from "../images/logo.svg";
10 | import { Light, Dark } from "../config";
11 | // Components
12 | import { useErrorBoundary } from "react-error-boundary";
13 | import { Link } from "react-scroll";
14 | import { Button, Col, Container, Row } from "react-bootstrap";
15 | import SocialLinks from "./SocialLinks";
16 |
17 | // #region styled-components
18 | const spin = keyframes`
19 | from {
20 | transform: rotate(0deg);
21 | }
22 | to {
23 | transform: rotate(360deg);
24 | }
25 | `;
26 |
27 | const StyledHero = styled.header`
28 | position: relative;
29 | display: grid;
30 | place-items: center;
31 | max-width: 1920px;
32 | margin: 0 auto;
33 | min-height: calc(100vh - var(--nav-height));
34 |
35 | &::before {
36 | content: "";
37 | position: absolute;
38 | top: 0;
39 | left: 0;
40 | width: 100%;
41 | height: 100%;
42 | background: ${({ theme }) =>
43 | theme.name === "light"
44 | ? "linear-gradient(135deg, var(--bs-primary), var(--bs-light))"
45 | : "linear-gradient(135deg, var(--bs-primary), var(--bs-dark))"};
46 | z-index: -2;
47 | }
48 |
49 | /* Overlay for contrast */
50 | &::after {
51 | content: "";
52 | position: absolute;
53 | top: 0;
54 | left: 0;
55 | width: 100%;
56 | height: 100%;
57 | background: ${({ theme }) =>
58 | theme.name === "light"
59 | ? "rgba(255, 255, 255, 0.2)"
60 | : "rgba(0, 0, 0, 0.2)"};
61 | z-index: -1;
62 | }
63 |
64 | .down-container {
65 | height: 10rem;
66 | }
67 |
68 | @media (prefers-reduced-motion: no-preference) {
69 | .hero-img {
70 | animation: ${spin} infinite 20s linear;
71 | }
72 | }
73 |
74 | @media screen and (min-width: 1180px) {
75 | &::before {
76 | background: ${({ theme }) =>
77 | theme.name === "light"
78 | ? `url(${Light}) top center fixed no-repeat`
79 | : `url(${Dark}) top center fixed no-repeat`};
80 | background-size: 100vw auto;
81 | }
82 | }
83 |
84 | @media screen and (min-width: 1367px) {
85 | &::before {
86 | background: ${({ theme }) =>
87 | theme.name === "light"
88 | ? `url(${Light}) center center fixed no-repeat`
89 | : `url(${Dark}) center center fixed no-repeat`};
90 | background-size: cover;
91 | }
92 | }
93 | `;
94 | // #endregion
95 |
96 | // #region component
97 | const propTypes = {
98 | name: PropTypes.string,
99 | };
100 |
101 | const Hero = ({ name }) => {
102 | const { showBoundary } = useErrorBoundary();
103 |
104 | return (
105 |
106 |
107 |
108 |
109 |
110 | {name === null ? "null" : name}
111 |
112 |
113 |
114 |
115 |
116 |
117 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
134 | showBoundary({
135 | name: "Error",
136 | message: "Simulated error message",
137 | })
138 | }
139 | >
140 | Simulate Error Boundary
141 |
142 |
143 |
144 | );
145 | };
146 |
147 | Hero.propTypes = propTypes;
148 | // #endregion
149 |
150 | export default Hero;
151 |
--------------------------------------------------------------------------------
/src/components/Loading.jsx:
--------------------------------------------------------------------------------
1 | // Styles
2 | import styled, { keyframes } from "styled-components";
3 |
4 | // #region styled-components
5 | const spin = keyframes`
6 | to {
7 | transform: rotate(360deg)
8 | }
9 | `;
10 |
11 | const Loading = styled.div`
12 | display: inline-block;
13 | width: 5rem;
14 | height: 5rem;
15 | border: 5px solid;
16 | border-radius: 50%;
17 | border-top-color: var(--bs-primary);
18 | margin: 1rem auto;
19 | animation: ${spin} 0.6s linear infinite;
20 | `;
21 | // #endregion
22 |
23 | export default Loading;
24 |
--------------------------------------------------------------------------------
/src/components/NavBar.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import styled from "styled-components";
3 | // State
4 | import { useSelector } from "react-redux";
5 | import { selectMode } from "../app/appSlice";
6 | import PropTypes from "prop-types";
7 | // Router
8 | import { Link, useLocation } from "react-router-dom";
9 | // Images
10 | import defaultLogo from "../images/defaultNavLogo.svg";
11 | // Components
12 | import { Link as ScrollLink } from "react-scroll";
13 | import { Container, Nav, Navbar } from "react-bootstrap";
14 | import ThemeToggle from "./ThemeToggle";
15 |
16 | // #region constants
17 | const navLinks = {
18 | routes: [
19 | { id: "1R", name: "Home", route: "/" },
20 | { id: "2R", name: "All Projects", route: "/All-Projects" },
21 | ],
22 | to: [
23 | { id: "1T", name: "Home", to: "Home" },
24 | { id: "2T", name: "About Me", to: "About" },
25 | { id: "3T", name: "Skills", to: "Skills" },
26 | { id: "4T", name: "Projects", to: "Projects" },
27 | { id: "5T", name: "Contact", to: "Contact" },
28 | ],
29 | };
30 | // #endregion
31 |
32 | // #region styled-components
33 | const StyledDiv = styled.div`
34 | .navbar {
35 | border-bottom: var(--border);
36 | }
37 |
38 | .spacer {
39 | height: var(--nav-height);
40 | }
41 |
42 | .logo-img {
43 | background: ${({ theme }) =>
44 | theme.name === "light" ? "var(--bs-dark)" : "var(--bs-light)"};
45 | }
46 | `;
47 | // #endregion
48 |
49 | // #region component
50 | const propTypes = {
51 | Logo: PropTypes.node,
52 | callBack: PropTypes.func,
53 | closeDelay: PropTypes.number,
54 | };
55 |
56 | const NavBar = ({ Logo = defaultLogo, callBack, closeDelay = 125 }) => {
57 | const theme = useSelector(selectMode);
58 | const [isExpanded, setisExpanded] = React.useState(false);
59 | const { pathname } = useLocation();
60 |
61 | return (
62 |
63 |
64 |
73 |
74 |
75 |
82 |
83 | setisExpanded(!isExpanded)}
86 | />
87 |
88 |
89 | {pathname === "/"
90 | ? navLinks.to.map((el) => {
91 | return (
92 |
93 | {
99 | setTimeout(() => {
100 | setisExpanded(false);
101 | }, closeDelay);
102 | }}
103 | >
104 | {el.name}
105 |
106 |
107 | );
108 | })
109 | : navLinks.routes.map((el) => {
110 | return (
111 |
112 | {
120 | setTimeout(() => {
121 | setisExpanded(false);
122 | }, closeDelay);
123 | }}
124 | >
125 | {el.name}
126 |
127 |
128 | );
129 | })}
130 |
131 |
132 |
137 |
138 |
139 |
140 |
141 |
142 | );
143 | };
144 |
145 | NavBar.propTypes = propTypes;
146 | // #endregion
147 |
148 | export default NavBar;
149 |
--------------------------------------------------------------------------------
/src/components/ProjectCard.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import PropTypes from "prop-types";
6 | // Icons
7 | import { Icon } from "@iconify/react";
8 | // Images
9 | import GH from "../images/GH.svg";
10 | // Components
11 | import { Card } from "react-bootstrap";
12 |
13 | // #region styled-components
14 | const StyledCard = styled.div`
15 | .card {
16 | height: var(--card-height);
17 | border: var(--border);
18 | transition: all 0.2s ease-in-out;
19 | background: ${({ theme }) =>
20 | theme.name === "light" ? "" : "var(--bs-gray)"};
21 | box-shadow: ${({ theme }) =>
22 | theme.name === "light"
23 | ? "0 3px 10px rgb(0 0 0 / 0.2)"
24 | : "0 3px 10px rgb(255 255 255 / 0.2)"};
25 |
26 | .card-img-top {
27 | height: 50%;
28 | object-fit: contain;
29 | }
30 |
31 | .card-link {
32 | text-decoration: none;
33 | font-size: 1.5rem;
34 |
35 | &:hover {
36 | color: ${({ theme }) =>
37 | theme.name === "light" ? "var(--bs-dark)" : "var(--bs-light)"};
38 | }
39 | }
40 |
41 | .card-footer {
42 | border-top: var(--border);
43 | background: ${({ theme }) =>
44 | theme.name === "light" ? "" : "var(--bs-gray-dark)"};
45 |
46 | .card-link {
47 | color: ${({ theme }) =>
48 | theme.name === "light" ? "var(--bs-dark)" : "var(--bs-light)"};
49 |
50 | &:hover {
51 | color: var(--bs-primary);
52 | }
53 | }
54 | }
55 |
56 | &:hover {
57 | transform: scale(1.03);
58 | }
59 | }
60 | `;
61 | // #endregion
62 |
63 | // #region component
64 | const propTypes = {
65 | demo: PropTypes.string,
66 | description: PropTypes.string,
67 | image: PropTypes.node,
68 | name: PropTypes.string.isRequired,
69 | url: PropTypes.string.isRequired,
70 | };
71 |
72 | const ProjectCard = ({ demo, description, image, name, url }) => {
73 | return (
74 |
75 |
76 |
82 |
83 | {name}
84 | {description}
85 | {demo !== (undefined && null && "") ? (
86 |
87 | {"Live Demo "}
88 |
89 |
90 | ) : null}
91 |
92 |
93 |
94 | {"View on GitHub "}
95 |
96 |
97 |
98 |
99 |
100 | );
101 | };
102 |
103 | ProjectCard.propTypes = propTypes;
104 | // #endregion
105 |
106 | export default ProjectCard;
107 |
--------------------------------------------------------------------------------
/src/components/Projects.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // State
3 | import { useSelector } from "react-redux";
4 | import { selectMode } from "../app/appSlice";
5 | import { selectProjects, selectMainProjects } from "../app/projectsSlice";
6 | import { useGetProjectsQuery } from "../app/apiSlice";
7 | // Router
8 | import { Link } from "react-router-dom";
9 | // Icons
10 | import { Icon } from "@iconify/react";
11 | // Components
12 | import { Element } from "react-scroll";
13 | import { Button, Col, Container, Row } from "react-bootstrap";
14 | import Loading from "./Loading";
15 | import Title from "./Title";
16 | import ProjectCard from "./ProjectCard";
17 |
18 | // #region component
19 | const Projects = () => {
20 | const theme = useSelector(selectMode);
21 | const projects = useSelector(selectProjects);
22 | const mainProjects = useSelector(selectMainProjects);
23 | const { isLoading, isSuccess, isError, error } = useGetProjectsQuery();
24 | let content;
25 |
26 | if (isLoading) {
27 | content = (
28 |
29 |
30 |
31 | );
32 | } else if (isSuccess) {
33 | content = (
34 | <>
35 | {!error && projects.length === 0 && (
36 |
37 | Oops, you do not have any GitHub projects yet...
38 |
39 | )}
40 | {mainProjects.length !== 0 && (
41 | <>
42 |
43 | {mainProjects.map((element) => {
44 | return (
45 |
46 |
53 |
54 | );
55 | })}
56 |
57 | {projects.length > 3 && (
58 |
59 |
60 |
66 | All Projects
67 |
68 |
69 |
70 | )}
71 | >
72 | )}
73 | >
74 | );
75 | } else if (isError) {
76 | content = (
77 |
78 | {`${error.status} - check getProjects query in src/app/apiSlice.js`}
79 |
80 | );
81 | }
82 |
83 | return (
84 |
85 |
86 |
87 |
88 |
89 |
90 | {content}
91 |
92 |
93 |
94 | );
95 | };
96 | // #endregion
97 |
98 | export default Projects;
99 |
--------------------------------------------------------------------------------
/src/components/ScrollToTop.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Router
3 | import { useLocation, useNavigate } from "react-router-dom";
4 |
5 | // #region component
6 | const ScrollToTop = () => {
7 | const { pathname, hash } = useLocation();
8 | const navigate = useNavigate();
9 |
10 | // https://reactjs.org/docs/hooks-reference.html#uselayouteffect
11 | React.useLayoutEffect(() => {
12 | // If not a hash link scroll to top
13 | if (hash === "") {
14 | setTimeout(() => {
15 | window.scrollTo(0, 0);
16 | }, 100);
17 | }
18 | // Else scroll to id
19 | else {
20 | const id = hash.replace("#", "");
21 | const element = document.getElementById(id);
22 | if (element) {
23 | element.scrollIntoView();
24 | } else {
25 | navigate("404", { replace: false });
26 | }
27 | }
28 | }, [pathname, hash, navigate]);
29 |
30 | return null;
31 | };
32 | // #endregion
33 |
34 | export default ScrollToTop;
35 |
--------------------------------------------------------------------------------
/src/components/Skills.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // State
3 | import { useSelector } from "react-redux";
4 | import { selectMode } from "../app/appSlice";
5 | // Components
6 | import { Element } from "react-scroll";
7 | import { Button, Col, Container, Row } from "react-bootstrap";
8 | import Title from "./Title";
9 | // Config
10 | import { skillData, resume } from "../config";
11 |
12 | // #region component
13 | const Skills = () => {
14 | const theme = useSelector(selectMode);
15 |
16 | return (
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | {skillData.map((skills) => {
25 | return (
26 |
27 |
28 | {skills.skill}
29 | {skills.name}
30 |
31 |
32 | );
33 | })}
34 |
35 | {resume && (
36 |
37 |
42 | Résumé
43 |
44 |
45 | )}
46 |
47 |
48 |
49 | );
50 | };
51 | // #endregion
52 |
53 | export default Skills;
54 |
--------------------------------------------------------------------------------
/src/components/SocialLinks.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import { useGetUsersQuery, useGetSocialsQuery } from "../app/apiSlice";
6 | // Icons
7 | import { Icon } from "@iconify/react";
8 | // Config
9 | import { Blog } from "../config";
10 |
11 | // #region styled-components
12 | const StyledSocialLinks = styled.div`
13 | a {
14 | margin: 0 1rem;
15 | }
16 | `;
17 | // #endregion
18 |
19 | // #region component
20 | const SocialLinks = () => {
21 | const { data: userData } = useGetUsersQuery();
22 | const { isSuccess, error, data: socialsData } = useGetSocialsQuery();
23 |
24 | React.useEffect(() => {
25 | if (error) {
26 | console.log(
27 | `${error.status} - check getSocials query in src/app/apiSlice.js`
28 | );
29 | }
30 | }, [error, socialsData]);
31 |
32 | return (
33 |
34 |
39 |
40 |
41 | {isSuccess &&
42 | socialsData.map((element, index) => {
43 | let icon;
44 | switch (element.provider) {
45 | case "linkedin":
46 | icon = ;
47 | break;
48 | case "twitter":
49 | icon = ;
50 | break;
51 | case "facebook":
52 | icon = ;
53 | break;
54 | case "instagram":
55 | icon = ;
56 | break;
57 | case "tiktok":
58 | icon = ;
59 | break;
60 |
61 | default:
62 | icon = ;
63 | break;
64 | }
65 | return (
66 |
72 | {icon}
73 |
74 | );
75 | })}
76 | {userData.blog && (
77 |
82 | {Blog ? Blog : }
83 |
84 | )}
85 |
86 | );
87 | };
88 | // #endregion
89 |
90 | export default SocialLinks;
91 |
--------------------------------------------------------------------------------
/src/components/ThemeToggle.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import { useSelector } from "react-redux";
6 | import { selectMode } from "../app/appSlice";
7 | import PropTypes from "prop-types";
8 | // Icons
9 | import { Icon } from "@iconify/react";
10 |
11 | // #region styled-components
12 | const StyledSwitch = styled.label`
13 | /* Slider pill */
14 | display: flex;
15 | width: 3.2rem;
16 | font-size: 1.5rem;
17 | border-radius: 30px;
18 | transition: var(--transition);
19 | border: 2px solid;
20 |
21 | /* Hide defualt checkbox */
22 | input[type="checkbox"] {
23 | height: 0;
24 | width: 0;
25 | opacity: 0;
26 | }
27 |
28 | /* Move span when checked */
29 | input[type="checkbox"]:checked + div {
30 | transform: translateX(100%);
31 | }
32 |
33 | div {
34 | display: flex;
35 | justify-content: center;
36 | align-items: center;
37 | transition: var(--transition);
38 | }
39 | `;
40 | // #endregion
41 |
42 | // #region functions
43 | const setStoredTheme = (theme) => localStorage.setItem("theme", theme);
44 | // #endregion
45 |
46 | // #region component
47 | const propTypes = {
48 | closeDelay: PropTypes.number,
49 | setExpanded: PropTypes.func.isRequired,
50 | setTheme: PropTypes.func.isRequired,
51 | };
52 |
53 | const ThemeToggle = ({ closeDelay = 250, setExpanded, setTheme }) => {
54 | const theme = useSelector(selectMode);
55 |
56 | const toggleTheme = () => {
57 | const themType = theme === "light" ? "dark" : "light";
58 | setTheme(themType);
59 | setStoredTheme(themType);
60 | };
61 |
62 | return (
63 | {
65 | setTimeout(() => {
66 | setExpanded(false);
67 | }, closeDelay);
68 | }}
69 | >
70 | toggleTheme()}
74 | />
75 |
76 | {theme === "light" ? (
77 |
78 | ) : (
79 |
80 | )}
81 |
82 |
83 | );
84 | };
85 |
86 | ThemeToggle.propTypes = propTypes;
87 | // #endregion
88 |
89 | export default ThemeToggle;
90 |
--------------------------------------------------------------------------------
/src/components/Title.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import PropTypes from "prop-types";
6 |
7 | // #region styled-components
8 | const TitleDiv = styled.div`
9 | display: inline-block;
10 | max-width: 90vw;
11 | word-wrap: break-word;
12 | margin: 0.5rem 0;
13 |
14 | .underline {
15 | height: 0.25rem;
16 | width: 75%;
17 | min-width: 3rem;
18 | border-radius: 0.25rem;
19 | margin: 0 auto 0 auto;
20 | background: ${({ theme }) =>
21 | theme.name === "light"
22 | ? "linear-gradient(to right, var(--bs-primary), #D3D3D3)"
23 | : "linear-gradient(to left, var(--bs-primary), var(--bs-light))"};
24 | }
25 | `;
26 | // #endregion
27 |
28 | // #region component
29 | const propTypes = {
30 | size: PropTypes.oneOf(["h1", "h2"]),
31 | text: PropTypes.string.isRequired,
32 | };
33 |
34 | const Title = ({ size = "h1", text }) => {
35 | return (
36 |
37 | {size === "h1" ? (
38 | {text}
39 | ) : (
40 | {text}
41 | )}
42 |
43 |
44 | );
45 | };
46 |
47 | Title.propTypes = propTypes;
48 | // #endregion
49 |
50 | export default Title;
51 |
--------------------------------------------------------------------------------
/src/config.js:
--------------------------------------------------------------------------------
1 | // Skills icons - https://icon-sets.iconify.design/
2 | import { Icon } from "@iconify/react";
3 |
4 | // Navbar Logo image (add your image to the src/images directory and uncomment the line below to import your image)
5 | // import newLogo from "./images/yourFileName"
6 |
7 | // Hero Images (add your images to the /images directory with the same names)
8 | import HeroLight from "./images/hero-light.jpg";
9 | import HeroDark from "./images/hero-dark.jpg";
10 |
11 | // Projects Images (add your images to the images directory and import below)
12 | import Logo from "./images/logo.svg";
13 |
14 | /* START HERE
15 | **************************************************************
16 | Add your GitHub username (string - "YourUsername") below.
17 | */
18 | export const githubUsername = "Your GitHub username here";
19 |
20 | // Navbar Logo image
21 | export const navLogo = null;
22 |
23 | /* Main
24 | **************************************************************
25 | Add a custom blog icon or update the hero images for the Main section.
26 | */
27 | export const Blog = null;
28 |
29 | // Hero images (imported above - lines 8-9)
30 | export { HeroLight as Light };
31 | export { HeroDark as Dark };
32 |
33 | /* About Me
34 | **************************************************************
35 | Add a second paragraph for the about me section.
36 | */
37 | export const moreInfo =
38 | "I enjoy learning about technology and helping others use it to improve their lives and be more productive. I built this site with React, React Bootstrap, Redux, and the GitHub REST API.";
39 |
40 | /* Skills
41 | **************************************************************
42 | Add or remove skills in the SAME format below, choose icons here - https://icon-sets.iconify.design/
43 | */
44 | export const skillData = [
45 | {
46 | id: 1,
47 | skill: ,
48 | name: "HTML5",
49 | },
50 | {
51 | id: 2,
52 | skill: ,
53 | name: "CSS3",
54 | },
55 | {
56 | id: 3,
57 | skill: ,
58 | name: "JavaScript",
59 | },
60 | {
61 | id: 4,
62 | skill: ,
63 | name: "BootStrap",
64 | },
65 | {
66 | id: 5,
67 | skill: ,
68 | name: "React",
69 | },
70 | {
71 | id: 6,
72 | skill: ,
73 | name: "Styled Components",
74 | },
75 | {
76 | id: 7,
77 | skill: ,
78 | name: "Redux",
79 | },
80 | {
81 | id: 8,
82 | skill: ,
83 | name: "Git",
84 | },
85 | {
86 | id: 9,
87 | skill: ,
88 | name: "GitHub",
89 | },
90 | ];
91 |
92 | // Resume link (string - "https://YourResumeUrl") - I am using CloudFront to share my resume (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html)
93 | export const resume = null;
94 |
95 | /* Projects
96 | **************************************************************
97 | List the repo names (string - "your-repo-name") you want to include (they will be sorted alphabetically). If empty, only the first 3 will be included.
98 | */
99 | export const filteredProjects = ["example-1", "example-2", "example-3"];
100 |
101 | // Replace the defualt GitHub image for matching repos below (images imported above - lines 7-8)
102 | export const projectCardImages = [
103 | {
104 | name: "example-1",
105 | image: Logo,
106 | },
107 | ];
108 |
109 | /* Contact Info
110 | **************************************************************
111 | Add your formspree endpoint below.
112 | https://formspree.io/
113 | */
114 | export const formspreeUrl = "https://formspree.io/f/YourEndpoint";
115 |
116 | // Footer icons theme (light or dark)
117 | export const footerTheme = "dark";
118 |
--------------------------------------------------------------------------------
/src/custom.scss:
--------------------------------------------------------------------------------
1 | // https://getbootstrap.com/docs/5.3/utilities/colors/#sass-variables
2 |
3 | // Set the primary color for the theme
4 | $blue: #61dbfb;
5 | // Import Bootstrap and its default variables
6 | @import "~bootstrap/scss/bootstrap.scss";
7 |
--------------------------------------------------------------------------------
/src/images/GH.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/images/defaultNavLogo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/images/hero-dark.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/src/images/hero-dark.jpg
--------------------------------------------------------------------------------
/src/images/hero-light.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mshuber1981/github-react-portfolio-template/e26304f7601af35cf0ac32ae959694ae5df84ee6/src/images/hero-light.jpg
--------------------------------------------------------------------------------
/src/images/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom/client";
3 | // Styles
4 | import "./custom.scss";
5 | // State
6 | import { Provider } from "react-redux";
7 | import { store } from "./app/store";
8 | // Config
9 | import { filteredProjects, projectCardImages } from "./config";
10 | import App from "./App";
11 | import * as serviceWorkerRegistration from "./serviceWorkerRegistration";
12 |
13 | const root = ReactDOM.createRoot(document.getElementById("root"));
14 |
15 | root.render(
16 |
17 |
21 |
22 | );
23 |
24 | // If you want your app to work offline and load faster, you can change
25 | // unregister() to register() below. Note this comes with some pitfalls.
26 | // Learn more about service workers: https://cra.link/PWA
27 | serviceWorkerRegistration.register();
28 |
--------------------------------------------------------------------------------
/src/pages/AllProjects.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled from "styled-components";
4 | // State
5 | import { useSelector } from "react-redux";
6 | import { selectProjects } from "../app/projectsSlice";
7 | import { useGetUsersQuery, useGetProjectsQuery } from "../app/apiSlice";
8 | // Icons
9 | import { Icon } from "@iconify/react/dist/iconify.js";
10 | // Components
11 | import {
12 | Col,
13 | Container,
14 | FormControl,
15 | InputGroup,
16 | Pagination,
17 | Row,
18 | } from "react-bootstrap";
19 | import Loading from "../components/Loading";
20 | import Title from "../components/Title";
21 | import ProjectCard from "../components/ProjectCard";
22 | import BackToTop from "../components/BackToTop";
23 | // Utils
24 | import { updateTitle } from "../utils";
25 |
26 | // #region styled-components
27 | const StyledSection = styled.section`
28 | .input-group {
29 | max-width: 90vw;
30 | }
31 |
32 | @media screen and (min-width: 800px) {
33 | .input-group {
34 | width: 75%;
35 | }
36 | }
37 | `;
38 | // #endregion
39 |
40 | // #region component
41 | const AllProjects = () => {
42 | const [searchInput, setSearchInput] = React.useState("");
43 | const [filteredResults, setFilteredResults] = React.useState([]);
44 | const [pageItems, setPageItems] = React.useState([]);
45 | const [activePage, setActivePage] = React.useState(1);
46 | const data = useSelector(selectProjects);
47 | const { data: userData } = useGetUsersQuery();
48 | const { isLoading, isSuccess, isError, error } = useGetProjectsQuery();
49 | let content;
50 |
51 | React.useEffect(() => {
52 | updateTitle(`${userData.name} | All Projects`);
53 | }, [userData]);
54 |
55 | React.useEffect(() => {
56 | if (searchInput !== "") {
57 | const filteredData = data.filter((item) => {
58 | return item.name.toLowerCase().includes(searchInput.toLowerCase());
59 | });
60 | const tempPageItems = [];
61 | for (
62 | let number = 1;
63 | number <= Math.ceil(filteredData.length / 6);
64 | number++
65 | ) {
66 | tempPageItems.push(
67 | setActivePage(number)}
71 | >
72 | {number}
73 |
74 | );
75 | setPageItems([...tempPageItems]);
76 | }
77 | if (activePage === 1) {
78 | setFilteredResults(filteredData.slice(0, 6));
79 | } else {
80 | setFilteredResults(
81 | filteredData.slice((activePage - 1) * 6, (activePage - 1) * 6 + 6)
82 | );
83 | }
84 | } else {
85 | const tempPageItems = [];
86 | for (let number = 1; number <= Math.ceil(data.length / 6); number++) {
87 | tempPageItems.push(
88 | setActivePage(number)}
92 | >
93 | {number}
94 |
95 | );
96 | setPageItems([...tempPageItems]);
97 | }
98 | if (activePage === 1) {
99 | setFilteredResults(data.slice(0, 6));
100 | } else {
101 | setFilteredResults(
102 | data.slice((activePage - 1) * 6, (activePage - 1) * 6 + 6)
103 | );
104 | }
105 | }
106 | }, [searchInput, data, pageItems.length, activePage]);
107 |
108 | React.useEffect(() => {
109 | setActivePage(1);
110 | }, [searchInput]);
111 |
112 | if (isLoading) {
113 | content = (
114 | <>
115 |
116 |
117 |
118 |
119 |
120 |
121 | >
122 | );
123 | } else if (isSuccess) {
124 | content = (
125 | <>
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | setSearchInput(e.currentTarget.value)}
139 | />
140 |
141 |
142 | {searchInput.length > 0
143 | ? filteredResults.map((element) => {
144 | return (
145 |
146 |
153 |
154 | );
155 | })
156 | : filteredResults.map((element) => {
157 | return (
158 |
159 |
166 |
167 | );
168 | })}
169 |
170 |
171 | {pageItems.length <= 2 ? (
172 | {pageItems}
173 | ) : (
174 |
175 |
177 | activePage === 1
178 | ? setActivePage(pageItems.length)
179 | : setActivePage(activePage - 1)
180 | }
181 | />
182 | {pageItems[0]}
183 |
184 | {activePage}
185 |
186 | {pageItems[pageItems.length - 1]}
187 |
189 | activePage === pageItems.length
190 | ? setActivePage(1)
191 | : setActivePage(activePage + 1)
192 | }
193 | />
194 |
195 | )}
196 |
197 |
198 | >
199 | );
200 | } else if (isError) {
201 | content = (
202 |
203 | {`${error.status} - check URLs in src/app/apiSlice.js`}
204 |
205 | );
206 | }
207 |
208 | return (
209 | <>
210 |
211 |
212 | {content}
213 |
214 |
215 |
216 | >
217 | );
218 | };
219 | // #endregion
220 |
221 | export default AllProjects;
222 |
--------------------------------------------------------------------------------
/src/pages/Home.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // State
3 | import { useGetUsersQuery } from "../app/apiSlice";
4 | // Components
5 | import Hero from "../components/Hero";
6 | import AboutMe from "../components/AboutMe";
7 | import Skills from "../components/Skills";
8 | import Projects from "../components/Projects";
9 | import Contact from "../components/Contact";
10 | import BackToTop from "../components/BackToTop";
11 | // Config
12 | import { filteredProjects, moreInfo } from "../config";
13 | // Utils
14 | import { updateTitle } from "../utils";
15 |
16 | // #region component
17 | const Home = () => {
18 | const { data: userData } = useGetUsersQuery();
19 |
20 | React.useEffect(() => {
21 | updateTitle(`${userData.name} | Portfolio`);
22 | }, [userData]);
23 |
24 | return (
25 | <>
26 |
27 |
28 |
33 |
34 |
35 |
36 |
37 |
38 | >
39 | );
40 | };
41 | // #endregion
42 |
43 | export default Home;
44 |
--------------------------------------------------------------------------------
/src/pages/NotFound.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // Styles
3 | import styled, { keyframes } from "styled-components";
4 | // Components
5 | import { Container } from "react-bootstrap";
6 | // Images
7 | import Logo from "../images/logo.svg";
8 | // Utils
9 | import { updateTitle } from "../utils";
10 |
11 | // #region styled-components
12 | const Spin = keyframes`
13 | from {
14 | transform: rotate(0deg);
15 | }
16 | to {
17 | transform: rotate(360deg);
18 | }
19 | `;
20 |
21 | const StyledNotFound = styled.main`
22 | display: flex;
23 | flex-direction: column;
24 | justify-content: center;
25 | align-items: center;
26 | min-height: calc(100vh - 2 * var(--nav-height) - 1rem);
27 |
28 | span {
29 | font-size: 5rem;
30 | }
31 |
32 | p {
33 | font-size: 2rem;
34 | }
35 |
36 | .logo-img {
37 | width: 10rem;
38 | }
39 |
40 | @media (prefers-reduced-motion: no-preference) {
41 | img {
42 | animation: ${Spin} infinite 20s linear;
43 | }
44 | }
45 | `;
46 | // #endregion
47 |
48 | // #region component
49 | const NotFound = () => {
50 | React.useEffect(() => {
51 | updateTitle("Not found...");
52 | }, []);
53 |
54 | return (
55 | <>
56 |
57 |
58 | 4
59 |
60 | 4
61 |
62 | Sorry, page not found...
63 |
64 | >
65 | );
66 | };
67 | // #endregion
68 |
69 | export default NotFound;
70 |
--------------------------------------------------------------------------------
/src/service-worker.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-restricted-globals */
2 |
3 | // This service worker can be customized!
4 | // See https://developers.google.com/web/tools/workbox/modules
5 | // for the list of available Workbox modules, or add any other
6 | // code you'd like.
7 | // You can also remove this file if you'd prefer not to use a
8 | // service worker, and the Workbox build step will be skipped.
9 |
10 | import { clientsClaim } from "workbox-core";
11 | import { ExpirationPlugin } from "workbox-expiration";
12 | import { precacheAndRoute, createHandlerBoundToURL } from "workbox-precaching";
13 | import { registerRoute } from "workbox-routing";
14 | import { StaleWhileRevalidate } from "workbox-strategies";
15 |
16 | clientsClaim();
17 |
18 | // Precache all of the assets generated by your build process.
19 | // Their URLs are injected into the manifest variable below.
20 | // This variable must be present somewhere in your service worker file,
21 | // even if you decide not to use precaching. See https://cra.link/PWA
22 | precacheAndRoute(self.__WB_MANIFEST);
23 |
24 | // Set up App Shell-style routing, so that all navigation requests
25 | // are fulfilled with your index.html shell. Learn more at
26 | // https://developers.google.com/web/fundamentals/architecture/app-shell
27 | const fileExtensionRegexp = new RegExp("/[^/?]+\\.[^/]+$");
28 | registerRoute(
29 | // Return false to exempt requests from being fulfilled by index.html.
30 | ({ request, url }) => {
31 | // If this isn't a navigation, skip.
32 | if (request.mode !== "navigate") {
33 | return false;
34 | } // If this is a URL that starts with /_, skip.
35 |
36 | if (url.pathname.startsWith("/_")) {
37 | return false;
38 | } // If this looks like a URL for a resource, because it contains // a file extension, skip.
39 |
40 | if (url.pathname.match(fileExtensionRegexp)) {
41 | return false;
42 | } // Return true to signal that we want to use the handler.
43 |
44 | return true;
45 | },
46 | createHandlerBoundToURL(process.env.PUBLIC_URL + "/index.html")
47 | );
48 |
49 | // An example runtime caching route for requests that aren't handled by the
50 | // precache, in this case same-origin .png requests like those from in public/
51 | registerRoute(
52 | // Add in any other file extensions or routing criteria as needed.
53 | ({ url }) =>
54 | (url.origin === self.location.origin && url.pathname.endsWith(".png")) ||
55 | (url.origin === self.location.origin && url.pathname.endsWith(".svg")) ||
56 | (url.origin === self.location.origin && url.pathname.endsWith(".jpg")), // Customize this strategy as needed, e.g., by changing to CacheFirst.
57 | new StaleWhileRevalidate({
58 | cacheName: "images",
59 | plugins: [
60 | // Ensure that once this runtime cache reaches a maximum size the
61 | // least-recently used images are removed.
62 | new ExpirationPlugin({ maxEntries: 50 }),
63 | ],
64 | })
65 | );
66 |
67 | // This allows the web app to trigger skipWaiting via
68 | // registration.waiting.postMessage({type: 'SKIP_WAITING'})
69 | self.addEventListener("message", (event) => {
70 | if (event.data && event.data.type === "SKIP_WAITING") {
71 | self.skipWaiting();
72 | }
73 | });
74 |
75 | // Any other custom service worker logic can go here.
76 |
--------------------------------------------------------------------------------
/src/serviceWorkerRegistration.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://cra.link/PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === "localhost" ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === "[::1]" ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener("load", () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | "This web app is being served cache-first by a service " +
46 | "worker. To learn more, visit https://cra.link/PWA"
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then((registration) => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === "installed") {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | "New content is available and will be used when all " +
74 | "tabs for this page are closed. See https://cra.link/PWA."
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log("Content is cached for offline use.");
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch((error) => {
97 | console.error("Error during service worker registration:", error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { "Service-Worker": "script" },
105 | })
106 | .then((response) => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get("content-type");
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf("javascript") === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then((registration) => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | "No internet connection found. App is running in offline mode."
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ("serviceWorker" in navigator) {
133 | navigator.serviceWorker.ready
134 | .then((registration) => {
135 | registration.unregister();
136 | })
137 | .catch((error) => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/utils.js:
--------------------------------------------------------------------------------
1 | // Update tab title
2 | export const updateTitle = (title) => (document.title = title);
3 |
4 | // Theme
5 | export const getStoredTheme = () => localStorage.getItem("theme");
6 |
7 | export const getPreferredTheme = () => {
8 | const storedTheme = getStoredTheme();
9 | if (storedTheme) {
10 | return storedTheme;
11 | }
12 |
13 | return window.matchMedia("(prefers-color-scheme: dark)").matches
14 | ? "dark"
15 | : "light";
16 | };
17 |
18 | export const setTheme = (theme) => {
19 | if (
20 | theme === "auto" &&
21 | window.matchMedia("(prefers-color-scheme: dark)").matches
22 | ) {
23 | document.documentElement.setAttribute("data-bs-theme", "dark");
24 | } else {
25 | document.documentElement.setAttribute("data-bs-theme", theme);
26 | }
27 | };
28 |
29 | // Contact Form
30 | export const postData = async (url, data) => {
31 | const response = await fetch(url, {
32 | method: "POST",
33 | body: JSON.stringify(data),
34 | headers: {
35 | Accept: "application/json",
36 | "Content-Type": "application/json",
37 | },
38 | });
39 | return response;
40 | };
41 |
--------------------------------------------------------------------------------