Skip to content

Commit 9c474b8

Browse files
feat: add authors with hyperlinks in all issue items #70 (#76)
* 🏷️ types/author: add author interface * ♻️ refactor/author: add separate Author component * ♻️ refactor: add separate TipOfTheWeek component with author * ♻️ refactor: add author in Tech Talks * 🚨 Fix linting errors * review: add optional chaining & defualt values * 💄 review: move Authors above Tags in Tech Talk * 🚨 fix all lint errors Co-authored-by: Prateek Surana <prateeksurana3255@gmail.com>
1 parent 0a0d1e5 commit 9c474b8

File tree

14 files changed

+143
-53
lines changed

14 files changed

+143
-53
lines changed

components/ArticleItem.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import Text from './common/Text';
33
import Tags from './common/Tags';
44
import { useThemeState } from '../theme/ThemeContext';
55
import Markdown from './Markdown';
6+
import Authors from './Authors';
67

7-
const ArticleItem = ({ article: { title, desc, url, author, tags } }: { article: Article }): JSX.Element => {
8+
const ArticleItem = ({ article }: { article: Article }): JSX.Element => {
89
const theme = useThemeState();
10+
const { title, desc, url, authors, tags } = article;
11+
912
return (
1013
<div className="mt-0 mx-0 py-4" key={url}>
1114
<a href={url} target="_blank" rel="noreferrer">
@@ -16,12 +19,8 @@ const ArticleItem = ({ article: { title, desc, url, author, tags } }: { article:
1619
<Text type="base" additionalStyles="py-2">
1720
<Markdown>{desc}</Markdown>
1821
</Text>
19-
<Text type="small" color="text-gray-600" additionalStyles="py-2">
20-
by <span className="uppercase">{author}</span>
21-
</Text>
22-
<span>
23-
<Tags tags={tags} />
24-
</span>
22+
<Authors authors={authors} />
23+
<Tags tags={tags} />
2524
</div>
2625
);
2726
};

components/Authors.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Author from '../interfaces/author';
2+
import Text from './common/Text';
3+
4+
function Authors({ authors }: { authors: Author[] }): JSX.Element {
5+
return (
6+
<div className="pb-2">
7+
<Text inline type="small" color="text-gray-600" additionalStyles="py-2 pr-1">
8+
by
9+
</Text>
10+
{authors.length
11+
? authors?.map((author, index) => {
12+
const isLastElement = index === authors.length - 1;
13+
return (
14+
<a href={author.website} target="_blank" rel="noreferrer" key={author.id}>
15+
<Text inline additionalStyles="uppercase hover:underline" type="small" color="text-gray-600">
16+
{isLastElement ? author.name : `${author.name}, `}
17+
</Text>
18+
</a>
19+
);
20+
})
21+
: null}
22+
</div>
23+
);
24+
}
25+
26+
export default Authors;

components/TechTalk.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ import Text from './common/Text';
44
import Tags from './common/Tags';
55
import Markdown from './Markdown';
66
import { useThemeState } from '../theme/ThemeContext';
7+
import Authors from './Authors';
78

89
// TODO: Create a loading indicator for this
910
// eslint-disable-next-line react/display-name
1011
const ReactPlayer = dynamic(() => import('react-player/lazy'), { loading: (): JSX.Element => <p>Loading...</p> });
1112

1213
const TechTalk = ({ techTalk }: { techTalk: Talk }): JSX.Element => {
1314
const theme = useThemeState();
15+
const { title, authors, talkURL, desc, tags } = techTalk;
1416

1517
return (
1618
<div className="py-8">
1719
<Text type="h2" additionalStyles="pb-4" color={`text-${theme}-600`}>
18-
{techTalk.title}
20+
{title}
1921
</Text>
20-
<div className="player-wrapper">
22+
<div className="player-wrapper py-3">
2123
<ReactPlayer
2224
className="react-player"
23-
url={techTalk.talkURL}
25+
url={talkURL}
2426
controls={true}
2527
pip={true}
2628
width="100%"
@@ -29,9 +31,10 @@ const TechTalk = ({ techTalk }: { techTalk: Talk }): JSX.Element => {
2931
/>
3032
</div>
3133
<Text additionalStyles="my-4">
32-
<Markdown>{techTalk.desc}</Markdown>
34+
<Markdown>{desc}</Markdown>
3335
</Text>
34-
<Tags tags={techTalk.tags} />
36+
<Authors authors={authors} />
37+
<Tags tags={tags} />
3538
</div>
3639
);
3740
};

components/TipOfTheWeekItem.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Text from './common/Text';
2+
import Markdown from './Markdown';
3+
import Authors from './Authors';
4+
import TipOfTheWeek from '../interfaces/tipOfTheWeek';
5+
import CodeSnippet from './common/CodeSnippet';
6+
7+
const TipOfTheWeekItem = ({ tipOfTheWeek }: { tipOfTheWeek: TipOfTheWeek }): JSX.Element => {
8+
const { snippet, desc, authors } = tipOfTheWeek;
9+
10+
return (
11+
<div className="mt-0 mx-0 py-4">
12+
<Text type="base" additionalStyles="py-4 relative z-10">
13+
<Markdown>{desc}</Markdown>
14+
</Text>
15+
{snippet ? <CodeSnippet snippet={snippet} /> : null}
16+
<Authors authors={authors} />
17+
</div>
18+
);
19+
};
20+
21+
export default TipOfTheWeekItem;

components/ToolItem.tsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@ import Image from 'next/image';
22
import ArticleItem from './ArticleItem';
33
import Tool from '../interfaces/tool';
44

5-
const ToolItem = ({ tool: { title, url, logo, author, desc, tags } }: { tool: Tool }): JSX.Element => (
6-
<div className="flex flex-wrap sm:flex-no-wrap flex-row items-center">
7-
<a
8-
href={url}
9-
className="w-full mr-8 max-w-fc my-4 p-1 transform transition duration-700 hover:scale-105 img-shadow-sm hover:img-shadow-none"
10-
target="_blank"
11-
rel="noreferrer"
12-
aria-label={title}
13-
>
14-
<Image
15-
className="h-32 w-32 inline rounded object-contain p-2 self-center"
16-
width={120}
17-
height={120}
18-
alt={title}
19-
src={logo}
20-
/>
21-
</a>
22-
<ArticleItem article={{ title, url, desc, author, tags }} />
23-
</div>
24-
);
5+
const ToolItem = ({ tool: { title, url, logo, authors, desc, tags } }: { tool: Tool }): JSX.Element => {
6+
const article = { title, url, desc, authors, tags };
7+
8+
return (
9+
<div className="flex flex-wrap sm:flex-no-wrap flex-row items-center">
10+
<a
11+
href={url}
12+
className="w-full mr-8 max-w-fc my-4 p-1 transform transition duration-700 hover:scale-105 img-shadow-sm hover:img-shadow-none"
13+
target="_blank"
14+
rel="noreferrer"
15+
aria-label={title}
16+
>
17+
<Image
18+
className="h-32 w-32 inline rounded object-contain p-2 self-center"
19+
width={120}
20+
height={120}
21+
alt={title}
22+
src={logo}
23+
/>
24+
</a>
25+
<ArticleItem article={article} />
26+
</div>
27+
);
28+
};
2529

2630
export default ToolItem;

components/common/Tags.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Tags({ tags = [] }: { tags?: Array<string> }): JSX.Element {
66
const theme = useThemeState();
77
return (
88
<div className="flex space-x-2 flex-wrap">
9-
{tags.map((tag, index) => (
9+
{tags?.map((tag, index) => (
1010
<Text
1111
type="small"
1212
color={`text-${theme}-600`}

interfaces/article.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import Author from './author';
12
export default interface Article {
23
title: string;
34
url: string;
45
desc: string;
5-
author: string;
6+
authors: Author[];
67
tags: string[];
78
}

interfaces/author.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default interface Author {
2+
id: number;
3+
name: string;
4+
website: string;
5+
}

interfaces/talk.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import Author from './author';
2+
13
export default interface Talk {
2-
talkURL: string;
3-
title: string;
4+
authors: Author[];
45
desc: string;
56
tags: string[];
7+
talkURL: string;
8+
title: string;
69
}

interfaces/tipOfTheWeek.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import Author from './author';
12
import CodeSnippet from './codeSnippet';
23

34
export default interface TipOfTheWeek {
45
snippet?: CodeSnippet;
56
desc: string;
6-
sourceName: string;
7-
sourceURL: string;
7+
authors: Author[];
88
}

0 commit comments

Comments
 (0)