mirror of
https://github.com/rjNemo/devbook_ts
synced 2026-06-11 13:06:43 +00:00
update repo array on profile edit
This commit is contained in:
parent
b7f1489281
commit
847af617ca
3 changed files with 11 additions and 7 deletions
|
|
@ -128,7 +128,7 @@ export const dummyDev: IDev = {
|
||||||
name: 'Repo #1',
|
name: 'Repo #1',
|
||||||
description:
|
description:
|
||||||
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit,deserunt.',
|
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit,deserunt.',
|
||||||
link: '#',
|
url: '#',
|
||||||
stars: 42,
|
stars: 42,
|
||||||
watchers: 2,
|
watchers: 2,
|
||||||
forks: 4,
|
forks: 4,
|
||||||
|
|
@ -137,7 +137,7 @@ export const dummyDev: IDev = {
|
||||||
name: 'Repo #2',
|
name: 'Repo #2',
|
||||||
description:
|
description:
|
||||||
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit,deserunt.',
|
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit,deserunt.',
|
||||||
link: '#',
|
url: '#',
|
||||||
stars: 21,
|
stars: 21,
|
||||||
watchers: 1,
|
watchers: 1,
|
||||||
forks: 2,
|
forks: 2,
|
||||||
|
|
@ -146,7 +146,7 @@ export const dummyDev: IDev = {
|
||||||
name: 'Repo #3',
|
name: 'Repo #3',
|
||||||
description:
|
description:
|
||||||
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit,deserunt.',
|
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit,deserunt.',
|
||||||
link: '#',
|
url: '#',
|
||||||
stars: 50,
|
stars: 50,
|
||||||
watchers: 32,
|
watchers: 32,
|
||||||
forks: 12,
|
forks: 12,
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import Alert from '../components/Alert';
|
||||||
import Statuses from '../constants/statuses';
|
import Statuses from '../constants/statuses';
|
||||||
// Form
|
// Form
|
||||||
import useForm from '../hooks';
|
import useForm from '../hooks';
|
||||||
|
import getGithubRepos from '../services/github';
|
||||||
// Typing
|
// Typing
|
||||||
import Dev from '../models/Dev';
|
import Dev from '../models/Dev';
|
||||||
import User from '../models/User';
|
import User from '../models/User';
|
||||||
|
|
@ -75,7 +76,7 @@ const EditProfile: FC<IProps> = ({
|
||||||
const {formData, handleChange} = useForm<FormData>(initFormData);
|
const {formData, handleChange} = useForm<FormData>(initFormData);
|
||||||
|
|
||||||
/** construct profile object from formData */
|
/** construct profile object from formData */
|
||||||
const makeProfile = ({
|
const makeProfile = async ({
|
||||||
status,
|
status,
|
||||||
company,
|
company,
|
||||||
location,
|
location,
|
||||||
|
|
@ -99,6 +100,7 @@ const EditProfile: FC<IProps> = ({
|
||||||
youtube: parseLink(youtube),
|
youtube: parseLink(youtube),
|
||||||
};
|
};
|
||||||
const newSkills: string[] = skills?.split(',');
|
const newSkills: string[] = skills?.split(',');
|
||||||
|
const newRepos = await getGithubRepos(github);
|
||||||
return {
|
return {
|
||||||
status,
|
status,
|
||||||
company,
|
company,
|
||||||
|
|
@ -107,12 +109,13 @@ const EditProfile: FC<IProps> = ({
|
||||||
github,
|
github,
|
||||||
links: newLinks,
|
links: newLinks,
|
||||||
skills: newSkills,
|
skills: newSkills,
|
||||||
|
repos: newRepos,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>): void => {
|
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const updatedDev = makeProfile(formData);
|
const updatedDev = await makeProfile(formData);
|
||||||
try {
|
try {
|
||||||
firebase.updateProfile(updatedDev, {useSet: true, merge: true});
|
firebase.updateProfile(updatedDev, {useSet: true, merge: true});
|
||||||
setAlert({
|
setAlert({
|
||||||
|
|
@ -122,6 +125,7 @@ const EditProfile: FC<IProps> = ({
|
||||||
'Profile successfully updated. You may go back to your dashboard.',
|
'Profile successfully updated. You may go back to your dashboard.',
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
setAlert({...alert, show: true});
|
setAlert({...alert, show: true});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ const getGithubRepos = async (owner: string) => {
|
||||||
const {data: repos} = await octokit.repos.listForAuthenticatedUser({
|
const {data: repos} = await octokit.repos.listForAuthenticatedUser({
|
||||||
owner,
|
owner,
|
||||||
});
|
});
|
||||||
const newRepo: Repo[] = repos.forEach((r: any) => ({
|
const newRepo: Repo[] = repos.map((r: any) => ({
|
||||||
url: r.url,
|
url: r.url,
|
||||||
stars: r.stargazers_count,
|
stars: r.stargazers_count,
|
||||||
forks: r.forks_count,
|
forks: r.forks_count,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue