From 847af617ca5e1c0bc3db55b6419d109e25f0a577 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Wed, 20 May 2020 17:51:32 +0200 Subject: [PATCH] update repo array on profile edit --- src/models/Dev.ts | 6 +++--- src/pages/EditProfile.tsx | 10 +++++++--- src/services/github/index.ts | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/models/Dev.ts b/src/models/Dev.ts index 7d3567d..ce546dc 100644 --- a/src/models/Dev.ts +++ b/src/models/Dev.ts @@ -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, diff --git a/src/pages/EditProfile.tsx b/src/pages/EditProfile.tsx index f433c08..3fe5b5e 100644 --- a/src/pages/EditProfile.tsx +++ b/src/pages/EditProfile.tsx @@ -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 = ({ const {formData, handleChange} = useForm(initFormData); /** construct profile object from formData */ - const makeProfile = ({ + const makeProfile = async ({ status, company, location, @@ -99,6 +100,7 @@ const EditProfile: FC = ({ youtube: parseLink(youtube), }; const newSkills: string[] = skills?.split(','); + const newRepos = await getGithubRepos(github); return { status, company, @@ -107,12 +109,13 @@ const EditProfile: FC = ({ github, links: newLinks, skills: newSkills, + repos: newRepos, }; }; - const handleSubmit = (e: React.FormEvent): void => { + const handleSubmit = async (e: React.FormEvent) => { 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 = ({ 'Profile successfully updated. You may go back to your dashboard.', }); } catch (err) { + console.error(err); setAlert({...alert, show: true}); } }; diff --git a/src/services/github/index.ts b/src/services/github/index.ts index 57e731a..98dc454 100644 --- a/src/services/github/index.ts +++ b/src/services/github/index.ts @@ -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,