Skip to content
This repository was archived by the owner on Sep 26, 2024. It is now read-only.

Commit c817a98

Browse files
authored
feat: replace placeholder avatars with contributor avatars (#28)
* feat: replace avatar fixtures with contributor avatars fixes #21 * test: add tests for getAvatar * style: adddress linting issues
1 parent f737de3 commit c817a98

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

src/components/PostGrid.jsx

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import av1 from "./placeholders/av01.jpg";
33
import av2 from "./placeholders/av02.jpg";
44
import cover2 from "./placeholders/cover2.jpg";
55
import humanizeNumber from "../lib/humanizeNumber";
6+
import getAvatar from "../lib/getAvatar";
67

78
function PostGrid({ data }) {
8-
const [repoOwner, repoName]= data.repo_name.split("/");
9+
const [repoOwner, repoName] = data.repo_name.split("/");
910

1011
const repoLink = `https://github.com/${data.repo_name}`;
1112
const handleClick = () => {
@@ -17,10 +18,22 @@ function PostGrid({ data }) {
1718
{/* Avator Container */}
1819
<div className=" w-full flex mb-3 ">
1920
<div className="bg-blue-400 w-10 h-10 overflow-hidden rounded-full mr-3 ">
20-
<img className="object-cover" src={av1} alt="Avatar 01" width={500} height={500} />
21+
<img
22+
className="object-cover"
23+
src={getAvatar(data?.contributors[0])}
24+
alt="Avatar 01"
25+
width={500}
26+
height={500}
27+
/>
2128
</div>
2229
<div className="bg-blue-400 w-10 h-10 overflow-hidden rounded-full mr-3 ">
23-
<img className="object-cover" src={av2} alt="Avatar 02" width={500} height={500} />
30+
<img
31+
className="object-cover"
32+
src={getAvatar(data?.contributors[1])}
33+
alt="Avatar 02"
34+
width={500}
35+
height={500}
36+
/>
2437
</div>
2538
</div>
2639
{/* Title */}
@@ -29,7 +42,8 @@ function PostGrid({ data }) {
2942
</div>
3043
{/* Description */}
3144
<div className=" text-lightGrey text-sm mb-2 ">
32-
<h3> {data.description} </h3> </div>
45+
<h3> {data.description} </h3>{" "}
46+
</div>
3347
{/* Cover photo */}
3448
<div className="w-full bg-blue-400 h-28 overflow-hidden rounded-md mb-2 ">
3549
<img className="object-cover" src={cover2} alt="Avatar 02" width={1000} height={1000} />

src/components/PostList.jsx

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from "react";
2-
import av1 from "./placeholders/av01.jpg";
3-
import av2 from "./placeholders/av02.jpg";
42
import cover1 from "./placeholders/cover1.jpg";
53
import cover2 from "./placeholders/cover2.jpg";
64
import humanizeNumber from "../lib/humanizeNumber";
5+
import getAvatar from "../lib/getAvatar";
76

87
function PostList({ data }) {
9-
const [repoOwner, repoName]= data.repo_name.split("/");
8+
const [repoOwner, repoName] = data.repo_name.split("/");
109

1110
const repoLink = `https://github.com/${data.repo_name}`;
1211
const handleClick = () => {
@@ -21,11 +20,23 @@ function PostList({ data }) {
2120
<div className=" flex flex-col ">
2221
{/* Avatar */}
2322
<div className="bg-blue-400 w-10 h-10 overflow-hidden rounded-full mb-2 ">
24-
<img className="object-cover" src={av1} alt="Avatar 01" width={500} height={500} />
23+
<img
24+
className="object-cover"
25+
src={getAvatar(data?.contributors[0])}
26+
alt="Avatar 01"
27+
width={500}
28+
height={500}
29+
/>
2530
</div>
2631
{/* Avatar */}
2732
<div className="bg-blue-400 w-10 h-10 overflow-hidden rounded-full ">
28-
<img className="object-cover" src={av2} alt="Avatar 02" width={500} height={500} />
33+
<img
34+
className="object-cover"
35+
src={getAvatar(data?.contributors[1])}
36+
alt="Avatar 02"
37+
width={500}
38+
height={500}
39+
/>
2940
</div>
3041
</div>
3142

src/lib/getAvatar.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default function getAvatar(username) {
2+
// if for some reason a username isn't present just use github's avatar
3+
if (!username) return 'https://github.com/github.png?size=460';
4+
return `https://github.com/${username}.png?size=460`;
5+
}

src/lib/getAvatar.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import getAvatar from './getAvatar';
2+
3+
describe('Test: getAvatar()', () => {
4+
test('Passing nulfrost should return return the correct URL', () => {
5+
const expected = 'https://github.com/nulfrost.png?size=460';
6+
const actual = getAvatar('nulfrost');
7+
expect(expected).toBe(actual);
8+
});
9+
test('Passing nothing should return the github avatar', () => {
10+
const expected = 'https://github.com/github.png?size=460';
11+
const actual = getAvatar();
12+
expect(expected).toBe(actual);
13+
});
14+
});

0 commit comments

Comments
 (0)