From d76c4fd52d100c5641ef51887a235fa40bb070a6 Mon Sep 17 00:00:00 2001 From: Ariful Alam Date: Sat, 19 Mar 2022 00:55:03 +0600 Subject: [PATCH] Add sections --- src/App.jsx | 219 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 184 insertions(+), 35 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 282947c..676d911 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,42 +1,191 @@ -import { useState } from 'react'; +import axios from 'axios'; +import { Fragment, useCallback, useContext, useEffect, useState } from 'react'; +import moment from 'moment'; +import { ThemeContext } from './contexts/ThemeContext'; +import { LoadingContext } from './contexts/LoadingContext'; +import config from './ezprofile.config'; +import HeadTagEditor from './components/head-tag-editor'; +import ErrorPage from './components/error-page'; +import ThemeChanger from './components/theme-changer'; +import AvatarCard from './components/avatar-card'; +import Details from './components/details'; +import Skill from './components/skill'; +import Experience from './components/experience'; +import Education from './components/education'; +import Project from './components/project'; +import Blog from './components/blog'; function App() { - const [count, setCount] = useState(0); + const [theme] = useContext(ThemeContext); + const [, setLoading] = useContext(LoadingContext); + const [profile, setProfile] = useState(null); + const [repo, setRepo] = useState(null); + const [error, setError] = useState(null); + const [rateLimit, setRateLimit] = useState(null); + + useEffect(() => { + if (theme) { + document.documentElement.setAttribute('data-theme', theme); + } + }, [theme]); + + const loadData = useCallback(() => { + axios + .get(`https://api.github.com/users/${config.github.username}`) + .then((response) => { + let data = response.data; + + let profileData = { + avatar: data.avatar_url, + name: data.name ? data.name : '', + bio: data.bio ? data.bio : '', + location: data.location ? data.location : '', + company: data.company ? data.company : '', + }; + + setProfile(profileData); + }) + .then(() => { + let excludeRepo = ``; + + config.github.exclude.projects.forEach((project) => { + excludeRepo += `+-repo:${config.github.username}/${project}`; + }); + + let query = `user:${config.github.username}+fork:${!config.github + .exclude.forks}${excludeRepo}`; + + let url = `https://api.github.com/search/repositories?q=${query}&sort=${config.github.sortBy}&per_page=${config.github.limit}&type=Repositories`; + + axios + .get(url, { + headers: { + 'Content-Type': 'application/vnd.github.v3+json', + }, + }) + .then((response) => { + let data = response.data; + + setRepo(data.items); + }) + .catch((error) => { + handleError(error); + }); + }) + .catch((error) => { + handleError(error); + }) + .finally(() => { + setLoading(false); + }); + }, [setLoading]); + + useEffect(() => { + loadData(); + }, [loadData]); + + const handleError = (error) => { + console.error('Error:', error); + try { + setRateLimit({ + remaining: error.response.headers['x-ratelimit-remaining'], + reset: moment( + new Date(error.response.headers['x-ratelimit-reset'] * 1000) + ).fromNow(), + }); + + if (error.response.status === 403) { + setError(429); + } else if (error.response.status === 404) { + setError(404); + } else { + setError(500); + } + } catch (error2) { + setError(500); + } + }; return ( -
-
- logo -

Hello Vite + React!

-

- -

-

- Edit App.jsx and save to test HMR updates. -

-

- - Learn React - - {' | '} - - Vite Docs - -

-
-
+ + +
+ {error ? ( + + Please provide correct github username in{' '} + src/ezprofile.config.js +

+ ) : error === 429 ? ( +

+ Oh no, you hit the{' '} + + rate limit + + ! Try again later{rateLimit && ` ${rateLimit.reset}`}. +

+ ) : ( + `Something went wrong` + ) + } + /> + ) : ( + +
+
+
+
+ {!config.themeConfig.disableSwitch && } + +
+ + + +
+
+
+
+ + +
+
+
+
+ {/* DO NOT REMOVE/MODIFY THE FOOTER. FOR MORE INFO https://github.com/arifszn/ezprofile#-please-read */} + +
+ )} +
+
); }