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