forked from JoelSutherland/GitHub-jQuery-Repo-Widget
/
index.tsx
148 lines (139 loc) · 5.03 KB
/
index.tsx
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
145
146
147
148
import { observable } from 'mobx';
import { WebCellProps, attribute, component, observer } from 'web-cell';
import { Repository, getRepository } from '../service';
import * as style from './index.module.less';
import icon_repo from './repository.png';
import icon_status from './watch-fork.png';
export interface GithubRepositoryProps extends WebCellProps {
owner: string;
repository: string;
}
@component({ tagName: 'github-repository' })
@observer
export class GithubRepository extends HTMLElement {
declare props: GithubRepositoryProps;
@attribute
@observable
accessor owner = 'TechQuery';
@attribute
@observable
accessor repository = 'GitHub-Web-Widget';
@observable
accessor currentRepository = {
owner: {} as Repository['owner'],
name: this.repository,
full_name: `${this.owner}/${this.repository}`,
description: '',
homepage: '',
default_branch: 'master',
pushed_at: '',
has_wiki: true,
watchers: 0,
forks: 0,
html_url: ''
} as Partial<Repository>;
async connectedCallback() {
this.currentRepository = await getRepository(
this.owner,
this.repository
);
}
render() {
const {
owner,
html_url,
full_name,
name,
watchers,
forks,
description,
has_wiki,
homepage,
default_branch,
pushed_at
} = this.currentRepository;
return (
<main className={style['github-box']}>
<div className={style['github-box-title']}>
<h3 className="p-2">
<img className="pe-1" src={icon_repo} />
<a
target="_blank"
href={owner.html_url}
title={`GitHub Homepage of ${owner.login}`}
>
{owner.login}
</a>
<span>/</span>
<a
className="fw-bold"
target="_blank"
href={html_url}
title={`GitHub Homepage of ${full_name}`}
>
{name}
</a>
</h3>
<div className={style['github-stats']}>
<a
className={style['watchers']}
style={{ backgroundImage: `url("${icon_status}")` }}
title="See watchers"
target="_blank"
href={`https://github.com/${full_name}/watchers`}
>
{watchers}
</a>
<a
className={style['forks']}
style={{ backgroundImage: `url("${icon_status}")` }}
title="See forkers"
target="_blank"
href={`https://github.com/${full_name}/forks`}
>
{forks}
</a>
</div>
</div>
<div className={style['github-box-content']}>
<p className="m-0 d-flex justify-content-between">
{description}
{has_wiki && (
<a
target="_blank"
href={`https://github.com/${full_name}#readme`}
>
Read More
</a>
)}
</p>
<p className="m-0 fw-bold">
<a target="_blank" href={homepage}>
{homepage}
</a>
</p>
</div>
<div className={style['github-box-download']}>
<div className={style['updated']}>
Latest commit to the
<strong className="fw-bold text-dark px-1">
{default_branch}
</strong>
branch on
<time dateTime={pushed_at} className="p-1">
{new Date(pushed_at).toLocaleString()}
</time>
</div>
<a
className={style['download']}
title="Get an archive of this repository"
target="_blank"
href={`https://github.com/${full_name}/zipball/${default_branch}`}
>
Download as zip
</a>
</div>
</main>
);
}
}