From 157649540827d63b920b09a673e0b334002b2bc8 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Sun, 17 May 2020 14:21:53 +0200 Subject: [PATCH] format social links --- src/models/Dev.ts | 3 +++ src/pages/EditProfile.tsx | 20 +++++++++++--------- src/types/Links.ts | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/models/Dev.ts b/src/models/Dev.ts index 21bd66c..84c8805 100644 --- a/src/models/Dev.ts +++ b/src/models/Dev.ts @@ -21,6 +21,7 @@ interface IDev extends DevSummary { bio: string; status: string; company: string; + github: string; links: Links; experiences: Experience[]; educations: Education[]; @@ -42,6 +43,7 @@ export class Dev implements IDev { description = ''; location = ''; skills: string[] = []; + github: string = ''; links: Links = { website: '', instagram: '', @@ -71,6 +73,7 @@ export const dummyDev: IDev = { description: 'Developer at Microsoft', location: 'Seattle, WA', skills: ['HTML', 'CSS', 'JavaScript', 'Python'], + github: '', links: { website: '#', instagram: 'http://insta.com', diff --git a/src/pages/EditProfile.tsx b/src/pages/EditProfile.tsx index a8e5142..f433c08 100644 --- a/src/pages/EditProfile.tsx +++ b/src/pages/EditProfile.tsx @@ -21,7 +21,7 @@ import useForm from '../hooks'; // Typing import Dev from '../models/Dev'; import User from '../models/User'; -import Links from '../types/Links'; +import Links, {parseLink, getGithubLink} from '../types/Links'; import IAlert, {formAlert} from '../types/Alert'; interface FormData { @@ -52,6 +52,7 @@ const EditProfile: FC = ({ links, location, bio, + github, }) => { const [showLinks, setShowLinks] = useState(false); const [alert, setAlert] = useState(formAlert); @@ -63,7 +64,7 @@ const EditProfile: FC = ({ bio: bio ?? '', skills: skills?.toString() ?? '', website: links?.website ?? '', - github: links?.github ?? '', + github: github ?? '', facebook: links?.facebook ?? '', linkedin: links?.linkedin ?? '', instagram: links?.instagram ?? '', @@ -89,13 +90,13 @@ const EditProfile: FC = ({ skills, }: FormData) => { const newLinks: Links = { - website, - instagram, - facebook, - linkedin, - twitter, - github, - youtube, + website: parseLink(website), + instagram: parseLink(instagram), + facebook: parseLink(facebook), + linkedin: parseLink(linkedin), + twitter: parseLink(twitter), + github: getGithubLink(github), + youtube: parseLink(youtube), }; const newSkills: string[] = skills?.split(','); return { @@ -103,6 +104,7 @@ const EditProfile: FC = ({ company, location, bio, + github, links: newLinks, skills: newSkills, }; diff --git a/src/types/Links.ts b/src/types/Links.ts index 0b8fc07..0e9c7fb 100644 --- a/src/types/Links.ts +++ b/src/types/Links.ts @@ -8,4 +8,22 @@ interface Links { youtube: string; } +/** + * ensure link is formatted as http(s)//:... + * @param link URI to process + */ +export const parseLink = (link: string): string => { + if (link.slice(0, 4) === 'http') { + return link; + } else { + return `http://${link}`; + } +}; + +/** + * @param githubUsername + */ +export const getGithubLink = (githubUsername: string) => + `https://github.com/${githubUsername}`; + export default Links;