Skip to content

Commit d8d53a7

Browse files
author
Nevo David
committed
feat: show prs
1 parent f092f7f commit d8d53a7

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

helpers/repository.status.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from 'prop-types';
2-
import { useCallback, useEffect, useState } from 'react';
2+
import { useCallback, useEffect, useMemo, useState } from 'react';
33

44
const statuses = [
55
{
@@ -21,23 +21,35 @@ const statuses = [
2121
];
2222

2323
const RepositoryStatus = (props) => {
24-
const { url } = props;
24+
const { url, displayOnly } = props;
25+
26+
const urlMemo = useMemo(() => {
27+
const regex = /([^\/]+)\/([^\/]+)/;
28+
const match = url.match(regex);
29+
30+
if (match) {
31+
return `/${match[1]}/${match[2]}`;
32+
}
33+
return null;
34+
35+
}, [url]);
36+
2537
const [statusValue, setStatus] = useState('NOT_DETERMINED');
2638
useEffect(() => {
2739
repositories();
2840
}, []);
2941

3042
const repositories = useCallback(async () => {
3143
const { status: newStatus } = await (
32-
await fetch(`/api/repository?id=https://github.com${url}`)
44+
await fetch(`/api/repository?id=https://github.com${urlMemo}`)
3345
).json();
3446
setStatus(newStatus);
3547
}, []);
3648

3749
const changeStatus = useCallback(async (status) => {
3850
await fetch(`/api/change-repository-status`, {
3951
body: JSON.stringify({
40-
url: `https://github.com${url}`,
52+
url: `https://github.com${urlMemo}`,
4153
status,
4254
}),
4355
headers: {
@@ -47,6 +59,10 @@ const RepositoryStatus = (props) => {
4759
});
4860
}, []);
4961

62+
if (displayOnly) {
63+
return statusValue;
64+
}
65+
5066
return (
5167
<select
5268
onChange={(p) => {
@@ -65,6 +81,7 @@ const RepositoryStatus = (props) => {
6581

6682
RepositoryStatus.propTypes = {
6783
url: PropTypes.string,
84+
displayOnly: PropTypes.bool,
6885
};
6986

7087
export default RepositoryStatus;

src/components/pages/teams/hero/hero.jsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ import useModerator from '~/helpers/use.moderator';
1111

1212
const Hero = ({ team }) => {
1313
const { moderator, cleaner } = useModerator();
14-
14+
const [view, setView] = useState('repository');
1515
const [disqualified, setDisqualified] = useState(team.disqualified);
1616
const [pullRequests] = useState(JSON.parse(team?.prs || '[]'));
1717
const changeToRepository = useMemo(
1818
() =>
1919
pullRequests
2020
.map((p) => ({
2121
...p,
22-
url: new URL(p.url).pathname.split('/').slice(0, 3).join('/'),
22+
url:
23+
view === 'repository'
24+
? new URL(p.url).pathname.split('/').slice(0, 3).join('/')
25+
: p.url.split('https://github.com/')[1],
2326
}))
2427
.filter((current, index, all) => {
2528
const firstIndex = all.findIndex((item) => item.url === current.url);
2629
return firstIndex === index;
2730
}),
28-
[pullRequests]
31+
[pullRequests, view]
2932
);
3033

3134
const kick = (id, name) => async () => {
@@ -152,6 +155,31 @@ const Hero = ({ team }) => {
152155
</div>
153156
</div>
154157

158+
{(moderator || cleaner) && (
159+
<button
160+
className="cta-btn-animation relative mt-10 flex h-[60px] max-w-full cursor-pointer items-center justify-center leading-none sm:mt-6"
161+
type="button"
162+
onClick={() => setView(view === 'repository' ? 'prs' : 'repository')}
163+
>
164+
<svg
165+
className="cta-btn-animation-border xs:w-full"
166+
width="268"
167+
height="59"
168+
viewBox="0 0 268 59"
169+
fill="none"
170+
aria-hidden
171+
>
172+
<path d="M1 58V1H251.586L267 16.4142V58H1Z" stroke="white" strokeWidth="2" />
173+
</svg>
174+
175+
<div className="absolute inset-0 flex items-center justify-center space-x-2.5">
176+
<span className="text-lg sm:text-[18px]">
177+
{view === 'repository' ? 'Show PRs' : 'Show Repositories'}
178+
</span>
179+
</div>
180+
</button>
181+
)}
182+
155183
<h2 className="mt-20 font-titles text-48 font-semibold leading-1.125 md:text-42">
156184
Contributed to repositories (TOTAL PR: {pullRequests.length})
157185
</h2>
@@ -188,7 +216,7 @@ const Hero = ({ team }) => {
188216
</span>
189217
)}
190218
<a target="_blank" href={`https://github.com${pr.url}`} rel="noreferrer">
191-
https://github.com{pr.url}
219+
https://github.com{pr.url} {view === 'prs' && pr.username}
192220
</a>
193221
</p>
194222
<p className="font-medium">
@@ -204,7 +232,9 @@ const Hero = ({ team }) => {
204232
</a>
205233
</p>
206234

207-
{(moderator || cleaner) && <RepositoryStatus url={pr.url} />}
235+
{(moderator || cleaner) && (
236+
<RepositoryStatus url={pr.url} displayOnly={view === 'prs'} />
237+
)}
208238
</li>
209239
))}
210240
</ul>

0 commit comments

Comments
 (0)