mirror of
https://github.com/NohamR/gitprofile.git
synced 2026-05-25 12:27:17 +00:00
Make optional configs
This commit is contained in:
@@ -11,18 +11,16 @@ import Experience from './experience';
|
|||||||
import Education from './education';
|
import Education from './education';
|
||||||
import Project from './project';
|
import Project from './project';
|
||||||
import Blog from './blog';
|
import Blog from './blog';
|
||||||
import { getInitialTheme, setupHotjar } from '../helpers/utils';
|
import {
|
||||||
|
constructConfigWithMissingValues,
|
||||||
|
getInitialTheme,
|
||||||
|
setupHotjar,
|
||||||
|
} from '../helpers/utils';
|
||||||
import { HelmetProvider } from 'react-helmet-async';
|
import { HelmetProvider } from 'react-helmet-async';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import '../assets/index.css';
|
import '../assets/index.css';
|
||||||
|
|
||||||
const GitProfile = ({ config }) => {
|
const GitProfile = ({ config }) => {
|
||||||
const [theme, setTheme] = useState(
|
|
||||||
config ? getInitialTheme(config.themeConfig) : null
|
|
||||||
);
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [profile, setProfile] = useState(null);
|
|
||||||
const [repo, setRepo] = useState(null);
|
|
||||||
const [error, setError] = useState(
|
const [error, setError] = useState(
|
||||||
typeof config === 'undefined'
|
typeof config === 'undefined'
|
||||||
? {
|
? {
|
||||||
@@ -33,6 +31,15 @@ const GitProfile = ({ config }) => {
|
|||||||
: null
|
: null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
typeof config !== 'undefined' && constructConfigWithMissingValues(config);
|
||||||
|
|
||||||
|
const [theme, setTheme] = useState(
|
||||||
|
config ? getInitialTheme(config.themeConfig) : null
|
||||||
|
);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [profile, setProfile] = useState(null);
|
||||||
|
const [repo, setRepo] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (theme) {
|
if (theme) {
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
@@ -187,12 +194,21 @@ const GitProfile = ({ config }) => {
|
|||||||
github={config.github}
|
github={config.github}
|
||||||
social={config.social}
|
social={config.social}
|
||||||
/>
|
/>
|
||||||
<Skill loading={loading} skills={config.skills} />
|
{typeof config.skills !== 'undefined' && (
|
||||||
<Experience
|
<Skill loading={loading} skills={config.skills} />
|
||||||
loading={loading}
|
)}
|
||||||
experiences={config.experiences}
|
{typeof config.experiences !== 'undefined' && (
|
||||||
/>
|
<Experience
|
||||||
<Education loading={loading} education={config.education} />
|
loading={loading}
|
||||||
|
experiences={config.experiences}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{typeof config.education !== 'undefined' && (
|
||||||
|
<Education
|
||||||
|
loading={loading}
|
||||||
|
education={config.education}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="lg:col-span-2 col-span-1">
|
<div className="lg:col-span-2 col-span-1">
|
||||||
@@ -203,11 +219,13 @@ const GitProfile = ({ config }) => {
|
|||||||
github={config.github}
|
github={config.github}
|
||||||
googleAnalytics={config.googleAnalytics}
|
googleAnalytics={config.googleAnalytics}
|
||||||
/>
|
/>
|
||||||
<Blog
|
{typeof config.blog !== 'undefined' && (
|
||||||
loading={loading}
|
<Blog
|
||||||
googleAnalytics={config.googleAnalytics}
|
loading={loading}
|
||||||
blog={config.blog}
|
googleAnalytics={config.googleAnalytics}
|
||||||
/>
|
blog={config.blog}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -244,12 +262,12 @@ GitProfile.propTypes = {
|
|||||||
config: PropTypes.shape({
|
config: PropTypes.shape({
|
||||||
github: PropTypes.shape({
|
github: PropTypes.shape({
|
||||||
username: PropTypes.string.isRequired,
|
username: PropTypes.string.isRequired,
|
||||||
sortBy: PropTypes.oneOf(['stars', 'updated']).isRequired,
|
sortBy: PropTypes.oneOf(['stars', 'updated']),
|
||||||
limit: PropTypes.number.isRequired,
|
limit: PropTypes.number,
|
||||||
exclude: PropTypes.shape({
|
exclude: PropTypes.shape({
|
||||||
forks: PropTypes.bool.isRequired,
|
forks: PropTypes.bool.isRequired,
|
||||||
projects: PropTypes.array.isRequired,
|
projects: PropTypes.array.isRequired,
|
||||||
}).isRequired,
|
}),
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
social: PropTypes.shape({
|
social: PropTypes.shape({
|
||||||
linkedin: PropTypes.string,
|
linkedin: PropTypes.string,
|
||||||
@@ -262,8 +280,8 @@ GitProfile.propTypes = {
|
|||||||
website: PropTypes.string,
|
website: PropTypes.string,
|
||||||
phone: PropTypes.string,
|
phone: PropTypes.string,
|
||||||
email: PropTypes.string,
|
email: PropTypes.string,
|
||||||
}).isRequired,
|
}),
|
||||||
skills: PropTypes.array.isRequired,
|
skills: PropTypes.array,
|
||||||
experiences: PropTypes.arrayOf(
|
experiences: PropTypes.arrayOf(
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
company: PropTypes.string,
|
company: PropTypes.string,
|
||||||
@@ -271,7 +289,7 @@ GitProfile.propTypes = {
|
|||||||
from: PropTypes.string,
|
from: PropTypes.string,
|
||||||
to: PropTypes.string,
|
to: PropTypes.string,
|
||||||
})
|
})
|
||||||
).isRequired,
|
),
|
||||||
education: PropTypes.arrayOf(
|
education: PropTypes.arrayOf(
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
institution: PropTypes.string,
|
institution: PropTypes.string,
|
||||||
@@ -279,26 +297,26 @@ GitProfile.propTypes = {
|
|||||||
from: PropTypes.string,
|
from: PropTypes.string,
|
||||||
to: PropTypes.string,
|
to: PropTypes.string,
|
||||||
})
|
})
|
||||||
).isRequired,
|
),
|
||||||
blog: PropTypes.shape({
|
blog: PropTypes.shape({
|
||||||
source: PropTypes.string,
|
source: PropTypes.string,
|
||||||
username: PropTypes.string,
|
username: PropTypes.string,
|
||||||
limit: PropTypes.number,
|
limit: PropTypes.number,
|
||||||
}).isRequired,
|
}),
|
||||||
googleAnalytics: PropTypes.shape({
|
googleAnalytics: PropTypes.shape({
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
}).isRequired,
|
}),
|
||||||
hotjar: PropTypes.shape({
|
hotjar: PropTypes.shape({
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
snippetVersion: PropTypes.number,
|
snippetVersion: PropTypes.number,
|
||||||
}).isRequired,
|
}),
|
||||||
themeConfig: PropTypes.shape({
|
themeConfig: PropTypes.shape({
|
||||||
default: PropTypes.string.isRequired,
|
default: PropTypes.string.isRequired,
|
||||||
disableSwitch: PropTypes.bool.isRequired,
|
disableSwitch: PropTypes.bool.isRequired,
|
||||||
respectPrefersColorScheme: PropTypes.bool.isRequired,
|
respectPrefersColorScheme: PropTypes.bool.isRequired,
|
||||||
themes: PropTypes.array.isRequired,
|
themes: PropTypes.array.isRequired,
|
||||||
customTheme: PropTypes.object.isRequired,
|
customTheme: PropTypes.object.isRequired,
|
||||||
}).isRequired,
|
}),
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -97,3 +97,86 @@ export const setupHotjar = (hotjarConfig) => {
|
|||||||
hotjar.initialize(hotjarConfig.id, snippetVersion);
|
hotjar.initialize(hotjarConfig.id, snippetVersion);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const constructConfigWithMissingValues = (config) => {
|
||||||
|
if (typeof config.github.sortBy === 'undefined') {
|
||||||
|
Object.assign(config.github, { sortBy: 'stars' });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof config.github.limit === 'undefined') {
|
||||||
|
Object.assign(config.github, { limit: 6 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof config.github.exclude === 'undefined') {
|
||||||
|
Object.assign(config.github, { exclude: { forks: false, projects: [] } });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof config.themeConfig === 'undefined') {
|
||||||
|
const themeConfig = {
|
||||||
|
default: 'corporate',
|
||||||
|
disableSwitch: false,
|
||||||
|
respectPrefersColorScheme: false,
|
||||||
|
themes: [
|
||||||
|
'light',
|
||||||
|
'dark',
|
||||||
|
'cupcake',
|
||||||
|
'bumblebee',
|
||||||
|
'emerald',
|
||||||
|
'corporate',
|
||||||
|
'synthwave',
|
||||||
|
'retro',
|
||||||
|
'cyberpunk',
|
||||||
|
'valentine',
|
||||||
|
'halloween',
|
||||||
|
'garden',
|
||||||
|
'forest',
|
||||||
|
'aqua',
|
||||||
|
'lofi',
|
||||||
|
'pastel',
|
||||||
|
'fantasy',
|
||||||
|
'wireframe',
|
||||||
|
'black',
|
||||||
|
'luxury',
|
||||||
|
'dracula',
|
||||||
|
'cmyk',
|
||||||
|
'autumn',
|
||||||
|
'business',
|
||||||
|
'acid',
|
||||||
|
'lemonade',
|
||||||
|
'night',
|
||||||
|
'coffee',
|
||||||
|
'winter',
|
||||||
|
'procyon',
|
||||||
|
],
|
||||||
|
customTheme: {
|
||||||
|
procyon: {
|
||||||
|
primary: '#fc055b',
|
||||||
|
secondary: '#219aaf',
|
||||||
|
accent: '#e8d03a',
|
||||||
|
neutral: '#2A2730',
|
||||||
|
'base-100': '#E3E3ED',
|
||||||
|
'--rounded-box': '3rem',
|
||||||
|
'--rounded-btn': '3rem',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(config, { themeConfig: themeConfig });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof config.googleAnalytics === 'undefined') {
|
||||||
|
const googleAnalytics = {
|
||||||
|
id: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(config, { googleAnalytics: googleAnalytics });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof config.social === 'undefined') {
|
||||||
|
const social = {};
|
||||||
|
|
||||||
|
Object.assign(config, { social: social });
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user