diff --git a/src/App.jsx b/src/App.jsx index 6724458..3b2b024 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,8 +1,6 @@ import axios from 'axios'; -import { Fragment, useCallback, useContext, useEffect, useState } from 'react'; +import { Fragment, useCallback, 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'; @@ -14,10 +12,11 @@ import Experience from './components/experience'; import Education from './components/education'; import Project from './components/project'; import Blog from './components/blog'; +import { getInitialTheme } from './helpers/utils'; function App() { - const { theme } = useContext(ThemeContext); - const { setLoading } = useContext(LoadingContext); + const [theme, setTheme] = useState(getInitialTheme()); + const [loading, setLoading] = useState(true); const [profile, setProfile] = useState(null); const [repo, setRepo] = useState(null); const [error, setError] = useState(null); @@ -108,7 +107,7 @@ function App() { return ( - +
{error ? (
- {!config.themeConfig.disableSwitch && } - -
- - - + {!config.themeConfig.disableSwitch && ( + + )} + +
+ + +
- - + +
diff --git a/src/components/avatar-card/index.jsx b/src/components/avatar-card/index.jsx index 41ce35e..f09e970 100644 --- a/src/components/avatar-card/index.jsx +++ b/src/components/avatar-card/index.jsx @@ -1,16 +1,12 @@ import PropTypes from 'prop-types'; -import { useContext } from 'react'; -import { LoadingContext } from '../../contexts/LoadingContext'; import { skeleton } from '../../helpers/utils'; import LazyImage from '../lazy-image'; -const AvatarCard = (props) => { - const { loading } = useContext(LoadingContext); - +const AvatarCard = ({ profile, loading }) => { return (
- {loading || !props.profile ? ( + {loading || !profile ? (
{skeleton({ @@ -25,10 +21,8 @@ const AvatarCard = (props) => {
{ { )}
- {loading || !props.profile ? ( + {loading || !profile ? ( skeleton({ width: 'w-48', height: 'h-8' }) ) : ( - {props.profile.name} + {profile.name} )}
- {loading || !props.profile + {loading || !profile ? skeleton({ width: 'w-48', height: 'h-5' }) - : props.profile.bio} + : profile.bio}
diff --git a/src/components/blog/index.jsx b/src/components/blog/index.jsx index aa2ca04..0caae57 100644 --- a/src/components/blog/index.jsx +++ b/src/components/blog/index.jsx @@ -1,8 +1,7 @@ import { getDevtoArticle, getMediumArticle } from 'article-api'; import moment from 'moment'; -import { Fragment, useContext, useEffect, useState } from 'react'; +import { Fragment, useEffect, useState } from 'react'; import { CgHashtag } from 'react-icons/cg'; -import { LoadingContext } from '../../contexts/LoadingContext'; import config from '../../ezprofile.config'; import { ga, skeleton } from '../../helpers/utils'; import LazyImage from '../lazy-image'; @@ -21,9 +20,8 @@ const displaySection = () => { } }; -const Blog = () => { +const Blog = ({loading}) => { const [articles, setArticles] = useState(null); - const { loading } = useContext(LoadingContext); useEffect(() => { if (displaySection()) { diff --git a/src/components/details/index.jsx b/src/components/details/index.jsx index 007d4ba..db303eb 100644 --- a/src/components/details/index.jsx +++ b/src/components/details/index.jsx @@ -12,8 +12,6 @@ import { FaGlobe, } from 'react-icons/fa'; import PropTypes from 'prop-types'; -import { useContext } from 'react'; -import { LoadingContext } from '../../contexts/LoadingContext'; import { skeleton } from '../../helpers/utils'; import config from '../../ezprofile.config'; @@ -31,9 +29,7 @@ const ListItem = ({ icon, title, value, link }) => { ); }; -const Details = (props) => { - const { loading } = useContext(LoadingContext); - +const Details = ({ profile, loading }) => { const renderSkeleton = () => { let array = []; for (let index = 0; index < 4; index++) { @@ -53,22 +49,22 @@ const Details = (props) => { return (
- {loading || !props.profile ? ( + {loading || !profile ? ( renderSkeleton() ) : (
- {props.profile.location && ( + {profile.location && ( } title="Based on" - value={props.profile.location} + value={profile.location} /> )} - {props.profile.company && ( + {profile.company && ( } title="Company" - value={props.profile.company} + value={profile.company} /> )} {
)} {/*
    - {loading || !props.profile ? ( + {loading || !profile ? ( renderSkeleton() ) : ( <> diff --git a/src/components/education/index.jsx b/src/components/education/index.jsx index 5413487..a02de67 100644 --- a/src/components/education/index.jsx +++ b/src/components/education/index.jsx @@ -1,12 +1,8 @@ import { GoPrimitiveDot } from 'react-icons/go'; -import { useContext } from 'react'; -import { LoadingContext } from '../../contexts/LoadingContext'; import { skeleton } from '../../helpers/utils'; import config from '../../ezprofile.config'; -const Education = () => { - const { loading } = useContext(LoadingContext); - +const Education = ({ loading }) => { const renderSkeleton = () => { let array = []; for (let index = 0; index < 2; index++) { diff --git a/src/components/experience/index.jsx b/src/components/experience/index.jsx index 6bcd41d..14bf9a3 100644 --- a/src/components/experience/index.jsx +++ b/src/components/experience/index.jsx @@ -1,12 +1,8 @@ import { GoPrimitiveDot } from 'react-icons/go'; -import { useContext } from 'react'; -import { LoadingContext } from '../../contexts/LoadingContext'; import { skeleton } from '../../helpers/utils'; import config from '../../ezprofile.config'; -const Experience = () => { - const { loading } = useContext(LoadingContext); - +const Experience = ({ loading }) => { const renderSkeleton = () => { let array = []; for (let index = 0; index < 2; index++) { diff --git a/src/components/head-tag-editor/index.jsx b/src/components/head-tag-editor/index.jsx index 59f26d8..beff2a3 100644 --- a/src/components/head-tag-editor/index.jsx +++ b/src/components/head-tag-editor/index.jsx @@ -1,16 +1,13 @@ -import { Fragment, useContext } from 'react'; +import { Fragment } from 'react'; import { Helmet } from 'react-helmet-async'; import PropTypes from 'prop-types'; -import { ThemeContext } from '../../contexts/ThemeContext'; import config from '../../ezprofile.config'; import { isThemeDarkish } from '../../helpers/utils'; -const HeadTagEditor = (props) => { - const { theme } = useContext(ThemeContext); - +const HeadTagEditor = ({ profile, theme }) => { return ( - {props.profile && ( + {profile && ( {config.googleAnalytics?.id && ( )} - Portfolio of {props.profile.name} + Portfolio of {profile.name} - + - - - + + + { } /> - - - + + + - - - + + + )} diff --git a/src/components/project/index.jsx b/src/components/project/index.jsx index 84a0383..084fcd4 100644 --- a/src/components/project/index.jsx +++ b/src/components/project/index.jsx @@ -1,13 +1,10 @@ -import { Fragment, useContext } from 'react'; +import { Fragment } from 'react'; import { AiOutlineStar, AiOutlineFork } from 'react-icons/ai'; import PropTypes from 'prop-types'; -import { LoadingContext } from '../../contexts/LoadingContext'; import config from '../../ezprofile.config'; import { ga, languageColor, skeleton } from '../../helpers/utils'; -const Project = (props) => { - const { loading } = useContext(LoadingContext); - +const Project = ({ repo, loading }) => { const renderSkeleton = () => { let array = []; for (let index = 0; index < config.github.limit; index++) { @@ -55,7 +52,7 @@ const Project = (props) => { }; const renderProjects = () => { - return props.repo.map((item, index) => ( + return repo.map((item, index) => (
    {
    - {loading || !props.repo ? renderSkeleton() : renderProjects()} + {loading || !repo ? renderSkeleton() : renderProjects()}
diff --git a/src/components/skill/index.jsx b/src/components/skill/index.jsx index 26d5491..1f2a583 100644 --- a/src/components/skill/index.jsx +++ b/src/components/skill/index.jsx @@ -1,11 +1,7 @@ -import { useContext } from 'react'; -import { LoadingContext } from '../../contexts/LoadingContext'; import config from '../../ezprofile.config'; import { skeleton } from '../../helpers/utils'; -const Skill = () => { - const { loading } = useContext(LoadingContext); - +const Skill = ({ loading }) => { const renderSkeleton = () => { let array = []; for (let index = 0; index < 12; index++) { diff --git a/src/components/theme-changer/index.jsx b/src/components/theme-changer/index.jsx index 08cd929..3e5ec6d 100644 --- a/src/components/theme-changer/index.jsx +++ b/src/components/theme-changer/index.jsx @@ -1,16 +1,8 @@ import { AiOutlineControl } from 'react-icons/ai'; -import { useContext } from 'react'; -import { ThemeContext } from '../../contexts/ThemeContext'; -import { LoadingContext } from '../../contexts/LoadingContext'; import { skeleton } from '../../helpers/utils'; import config from '../../ezprofile.config'; -const ThemeChanger = () => { - const { theme, setTheme } = useContext(ThemeContext); - const { loading } = useContext(LoadingContext); - - console.log(theme); - +const ThemeChanger = ({ theme, setTheme, loading }) => { const changeTheme = (e, selectedTheme) => { e.preventDefault(); document.querySelector('html').setAttribute('data-theme', selectedTheme); diff --git a/src/contexts/LoadingContext.jsx b/src/contexts/LoadingContext.jsx deleted file mode 100644 index b33cc02..0000000 --- a/src/contexts/LoadingContext.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import { createContext, useState } from 'react'; - -const initialValue = true; - -export const LoadingContext = createContext(); - -export const LoadingProvider = (props) => { - const [loading, setLoading] = useState(initialValue); - - return ( - - {props.children} - - ); -}; diff --git a/src/contexts/ThemeContext.jsx b/src/contexts/ThemeContext.jsx deleted file mode 100644 index fb82452..0000000 --- a/src/contexts/ThemeContext.jsx +++ /dev/null @@ -1,16 +0,0 @@ -import { createContext, useState } from 'react'; -import { getInitialTheme } from '../helpers/utils'; - -const initialValue = getInitialTheme(); - -export const ThemeContext = createContext(); - -export const ThemeProvider = (props) => { - const [theme, setTheme] = useState(initialValue); - - return ( - - {props.children} - - ); -}; diff --git a/src/main.jsx b/src/main.jsx index 19c3e0e..d88f50c 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -2,19 +2,13 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; -import { ThemeProvider } from './contexts/ThemeContext'; -import { LoadingProvider } from './contexts/LoadingContext'; import { HelmetProvider } from 'react-helmet-async'; ReactDOM.render( - - - - - - - + + + , document.getElementById('root') );