forked from devsonket/devsonket.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeaderContent.js
More file actions
144 lines (128 loc) · 3.79 KB
/
Copy pathHeaderContent.js
File metadata and controls
144 lines (128 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React, { PureComponent } from "react";
import axios from 'axios';
import styled from "@emotion/styled";
import NavBar from "./NavBar";
import SocialShare from "./SocialShare";
import { HeaderIntro } from "./HeaderIntro";
import contributorMap from "../utils/contributorMap";
export const HeaderEl = styled.div`
width: 940px;
margin: 80px auto 0 auto;
@media only screen and (max-width: 940px) {
width: 100%;
}
`;
export const HeaderArea = styled.header`
background-color: #f8f9fa;
.contributor {
list-style: none;
margin-bottom: 15px;
}
.contributor p {
margin-bottom: 10px;
font-weight: 900;
}
.contributor li {
display: inline-block;
position: relative;
margin: 0 5px;
}
.contributor-profile span {
position: absolute;
bottom: 5px;
right: -2px;
font-weight: bold;
background-color: #4caf50;
color: #fff;
font-size: 11px;
width: 15px;
height: 15px;
line-height: 15px;
border-radius: 40px;
}
.contributor-profile img {
width: 40px;
border-radius: 40px;
border: 3px solid #ffc107;
}
`;
class HeaderContent extends PureComponent {
state = {
contributor: ""
}
componentDidMount() {
if(navigator.userAgent !== 'ReactSnap') {
this.getContributor(this.props.id);
}
}
getContributor = async id => {
if (!localStorage.getItem("devCon")) {
localStorage.setItem("devCon", "{}");
}
let contributor;
try {
const getLocalContributor = JSON.parse(localStorage.getItem("devCon"));
const getCurrentId = getLocalContributor[id];
const getCurrentTime = Date.now();
let compareTime = 1000 * 60 * 60;
if (getCurrentId && getCurrentId[1] + compareTime >= getCurrentTime) {
contributor = getCurrentId[0];
} else {
contributor = await axios(
`https://api.github.com/repos/devsonket/devsonket.github.io/commits?path=data/${id}.json`
);
contributor = contributorMap(contributor.data);
let dataForLocalStorage = [contributor, Date.now()];
getLocalContributor[id] = dataForLocalStorage;
localStorage.setItem("devCon", JSON.stringify(getLocalContributor));
}
} catch (e) {
contributor = null;
}
this.setState({contributor});
}
render() {
const { title, description } = this.props;
const { contributor } = this.state;
return (
<HeaderArea>
<NavBar />
<HeaderEl>
<HeaderIntro>
<h1>{title}</h1>
<p>{description}</p>
{contributor && (
<ul className="contributor no-print">
<p>কন্ট্রিবিউটর</p>
{Object.keys(contributor).map(oneContributor => (
<li key={oneContributor}>
<div className="contributor-profile">
<a
rel="noopener noreferrer"
target="_blank"
href={contributor[oneContributor].html_url}
>
<img
alt={contributor[oneContributor].login}
src={contributor[oneContributor].avatar_url}
/>
</a>
<span>{contributor[oneContributor].count}</span>
</div>
</li>
))}
</ul>
)}
<div className="print no-print">
<button className="btn btn-print" onClick={() => window.print()}>
প্রিন্ট করুন
</button>
</div>
<SocialShare title={title} description={description} />
</HeaderIntro>
</HeaderEl>
</HeaderArea>
);
}
}
export default HeaderContent;