mirror of
https://github.com/rjNemo/devbook_ts
synced 2026-06-12 05:26:46 +00:00
format social links
This commit is contained in:
parent
37344590b7
commit
1576495408
3 changed files with 32 additions and 9 deletions
|
|
@ -21,6 +21,7 @@ interface IDev extends DevSummary {
|
||||||
bio: string;
|
bio: string;
|
||||||
status: string;
|
status: string;
|
||||||
company: string;
|
company: string;
|
||||||
|
github: string;
|
||||||
links: Links;
|
links: Links;
|
||||||
experiences: Experience[];
|
experiences: Experience[];
|
||||||
educations: Education[];
|
educations: Education[];
|
||||||
|
|
@ -42,6 +43,7 @@ export class Dev implements IDev {
|
||||||
description = '';
|
description = '';
|
||||||
location = '';
|
location = '';
|
||||||
skills: string[] = [];
|
skills: string[] = [];
|
||||||
|
github: string = '';
|
||||||
links: Links = {
|
links: Links = {
|
||||||
website: '',
|
website: '',
|
||||||
instagram: '',
|
instagram: '',
|
||||||
|
|
@ -71,6 +73,7 @@ export const dummyDev: IDev = {
|
||||||
description: 'Developer at Microsoft',
|
description: 'Developer at Microsoft',
|
||||||
location: 'Seattle, WA',
|
location: 'Seattle, WA',
|
||||||
skills: ['HTML', 'CSS', 'JavaScript', 'Python'],
|
skills: ['HTML', 'CSS', 'JavaScript', 'Python'],
|
||||||
|
github: '',
|
||||||
links: {
|
links: {
|
||||||
website: '#',
|
website: '#',
|
||||||
instagram: 'http://insta.com',
|
instagram: 'http://insta.com',
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import useForm from '../hooks';
|
||||||
// Typing
|
// Typing
|
||||||
import Dev from '../models/Dev';
|
import Dev from '../models/Dev';
|
||||||
import User from '../models/User';
|
import User from '../models/User';
|
||||||
import Links from '../types/Links';
|
import Links, {parseLink, getGithubLink} from '../types/Links';
|
||||||
import IAlert, {formAlert} from '../types/Alert';
|
import IAlert, {formAlert} from '../types/Alert';
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
|
|
@ -52,6 +52,7 @@ const EditProfile: FC<IProps> = ({
|
||||||
links,
|
links,
|
||||||
location,
|
location,
|
||||||
bio,
|
bio,
|
||||||
|
github,
|
||||||
}) => {
|
}) => {
|
||||||
const [showLinks, setShowLinks] = useState(false);
|
const [showLinks, setShowLinks] = useState(false);
|
||||||
const [alert, setAlert] = useState<IAlert>(formAlert);
|
const [alert, setAlert] = useState<IAlert>(formAlert);
|
||||||
|
|
@ -63,7 +64,7 @@ const EditProfile: FC<IProps> = ({
|
||||||
bio: bio ?? '',
|
bio: bio ?? '',
|
||||||
skills: skills?.toString() ?? '',
|
skills: skills?.toString() ?? '',
|
||||||
website: links?.website ?? '',
|
website: links?.website ?? '',
|
||||||
github: links?.github ?? '',
|
github: github ?? '',
|
||||||
facebook: links?.facebook ?? '',
|
facebook: links?.facebook ?? '',
|
||||||
linkedin: links?.linkedin ?? '',
|
linkedin: links?.linkedin ?? '',
|
||||||
instagram: links?.instagram ?? '',
|
instagram: links?.instagram ?? '',
|
||||||
|
|
@ -89,13 +90,13 @@ const EditProfile: FC<IProps> = ({
|
||||||
skills,
|
skills,
|
||||||
}: FormData) => {
|
}: FormData) => {
|
||||||
const newLinks: Links = {
|
const newLinks: Links = {
|
||||||
website,
|
website: parseLink(website),
|
||||||
instagram,
|
instagram: parseLink(instagram),
|
||||||
facebook,
|
facebook: parseLink(facebook),
|
||||||
linkedin,
|
linkedin: parseLink(linkedin),
|
||||||
twitter,
|
twitter: parseLink(twitter),
|
||||||
github,
|
github: getGithubLink(github),
|
||||||
youtube,
|
youtube: parseLink(youtube),
|
||||||
};
|
};
|
||||||
const newSkills: string[] = skills?.split(',');
|
const newSkills: string[] = skills?.split(',');
|
||||||
return {
|
return {
|
||||||
|
|
@ -103,6 +104,7 @@ const EditProfile: FC<IProps> = ({
|
||||||
company,
|
company,
|
||||||
location,
|
location,
|
||||||
bio,
|
bio,
|
||||||
|
github,
|
||||||
links: newLinks,
|
links: newLinks,
|
||||||
skills: newSkills,
|
skills: newSkills,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,22 @@ interface Links {
|
||||||
youtube: string;
|
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;
|
export default Links;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue