generated from Real-Dev-Squad/website-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from Real-Dev-Squad/develop
Merge develop in main
- Loading branch information
Showing
10 changed files
with
198 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/components/PullRequestList/PullRequestList.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.center_text { | ||
font-size: 1.5em; | ||
text-align: center; | ||
} | ||
|
||
.pagination { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.pagination_btn { | ||
margin: 1rem; | ||
padding: 1rem; | ||
font-size: 1.5em; | ||
cursor: pointer; | ||
border: none; | ||
background-color: #bfbfbf; | ||
border-radius: 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { FC, useState, useEffect } from 'react'; | ||
import Head from '@/components/head'; | ||
import Layout from '@/components/Layout'; | ||
import PullRequest from '@/components/pullRequests'; | ||
import CardShimmer from '@/components/Loaders/cardShimmer'; | ||
import axios from 'axios'; | ||
import styles from './PullRequestList.module.scss'; | ||
|
||
type pullRequestType = { | ||
title: string; | ||
username: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
url: string; | ||
}; | ||
|
||
type PullRequestListProps = { | ||
prType: string; | ||
}; | ||
|
||
const PullRequestList: FC<PullRequestListProps> = ({ prType }) => { | ||
const [pullRequests, setPullRequests] = useState<pullRequestType[]>([]); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState(''); | ||
const [page, setPage] = useState(1); | ||
|
||
const prUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/pullrequests/${prType}?page=${page}`; | ||
|
||
const fetchPRs = async () => { | ||
try { | ||
setLoading(true); | ||
const response = await axios.get(prUrl); | ||
setPullRequests(response.data.pullRequests); | ||
|
||
if (!response.data.pullRequests.length) { | ||
setError(`No more ${prType} PRs...`); | ||
} else { | ||
setError(''); | ||
} | ||
} catch (err) { | ||
setPullRequests([]); | ||
setError('Error fetching pull requests!'); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const handlePrev = () => { | ||
setPage(page > 1 ? page - 1 : 1); | ||
}; | ||
|
||
const handleNext = () => { | ||
setPage(pullRequests.length ? page + 1 : page); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchPRs(); | ||
}, [page]); | ||
|
||
const getPRs = () => pullRequests.map((pullRequest: pullRequestType) => { | ||
const { | ||
title, username, createdAt, updatedAt, url: link, | ||
} = pullRequest; | ||
return ( | ||
<PullRequest | ||
key={link} | ||
title={title} | ||
username={username} | ||
createdAt={createdAt} | ||
updatedAt={updatedAt} | ||
url={link} | ||
/> | ||
); | ||
}); | ||
|
||
return ( | ||
<Layout> | ||
<Head title="PRs" /> | ||
|
||
<div className="container"> | ||
{loading | ||
? [...Array(10)].map((e: number) => <CardShimmer key={e} />) | ||
: getPRs()} | ||
</div> | ||
{error ? <p className={styles.center_text}>{error}</p> : ''} | ||
|
||
<div className={styles.pagination}> | ||
<button | ||
className={styles.pagination_btn} | ||
type="button" | ||
onClick={handlePrev} | ||
disabled={page <= 1} | ||
> | ||
Prev | ||
</button> | ||
|
||
<button | ||
className={styles.pagination_btn} | ||
type="button" | ||
onClick={handleNext} | ||
disabled={pullRequests.length === 0} | ||
> | ||
Next | ||
</button> | ||
</div> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default PullRequestList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,57 @@ | ||
import { FC } from 'react'; | ||
import { FC, useState, useEffect } from 'react'; | ||
import Head from '@/components/head'; | ||
import Layout from '@/components/Layout'; | ||
import Card from '@/components/tasks/card'; | ||
import useFetch from '@/hooks/useFetch'; | ||
import classNames from '@/styles/tasks.module.scss'; | ||
import { task } from '@/components/constants/types'; | ||
|
||
const Mine: FC = () => ( | ||
<Layout> | ||
<Head title="Mine" /> | ||
</Layout> | ||
); | ||
const TASKS_URL = `${process.env.NEXT_PUBLIC_BASE_URL}/task/self`; | ||
|
||
function CardList(tasks: task[]) { | ||
return tasks.map( | ||
(item: task) => <Card content={item} key={item.id} />, | ||
); | ||
} | ||
|
||
const Mine: FC = () => { | ||
const [tasks, setTasks] = useState<task[]>([]); | ||
const { | ||
response, | ||
error, | ||
isLoading, | ||
} = useFetch(TASKS_URL); | ||
|
||
useEffect(() => { | ||
if ('tasks' in response) { setTasks(response.tasks); } | ||
}, [isLoading, response]); | ||
return ( | ||
<Layout> | ||
<Head title="Mine" /> | ||
<div className={classNames.container}> | ||
{ | ||
!!error | ||
&& <p>Something went wrong, please contact admin!</p> | ||
} | ||
{ | ||
isLoading | ||
? ( | ||
<p>Loading...</p> | ||
) : ( | ||
<> | ||
{ | ||
tasks.length > 0 | ||
? ( | ||
<div> | ||
{CardList(tasks)} | ||
</div> | ||
) : (!error && 'No Tasks Found') | ||
} | ||
</> | ||
) | ||
} | ||
</div> | ||
</Layout> | ||
); | ||
}; | ||
export default Mine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,6 @@ | ||
import { FC, useState, useEffect } from 'react'; | ||
import Head from '@/components/head'; | ||
import Layout from '@/components/Layout'; | ||
import PullRequest from '@/components/pullRequests'; | ||
import fetch from '@/helperFunctions/fetch'; | ||
import CardShimmer from '@/components/Loaders/cardShimmer'; | ||
import { FC } from 'react'; | ||
import PullRequestList from '@/components/PullRequestList'; | ||
|
||
type pullRequestType = { | ||
title: string; | ||
username: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
url: string; | ||
}; | ||
|
||
const openPRs: FC = () => { | ||
const [pullRequests, setPullRequests] = useState<pullRequestType[]>([]); | ||
const [loading, setLoading] = useState(false); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
setLoading(true); | ||
const response = await fetch({ | ||
url: `${process.env.NEXT_PUBLIC_BASE_URL}/pullrequests/open`, | ||
}); | ||
setPullRequests(response.data.pullRequests); | ||
setLoading(false); | ||
})(); | ||
}, []); | ||
|
||
const getPRs = () => pullRequests.map((pullRequest: pullRequestType) => { | ||
const { | ||
title, username, createdAt, updatedAt, url: link, | ||
} = pullRequest; | ||
return ( | ||
<> | ||
<PullRequest | ||
key={link} | ||
title={title} | ||
username={username} | ||
createdAt={createdAt} | ||
updatedAt={updatedAt} | ||
url={link} | ||
/> | ||
</> | ||
); | ||
}); | ||
|
||
return ( | ||
<Layout> | ||
<Head title="Open PRs" /> | ||
|
||
<div className="container"> | ||
{ | ||
loading ? ( | ||
<> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
<CardShimmer /> | ||
</> | ||
) : ( | ||
getPRs()) | ||
} | ||
|
||
</div> | ||
</Layout> | ||
); | ||
}; | ||
const openPRs: FC = () => <PullRequestList prType="open" />; | ||
|
||
export default openPRs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,6 @@ | ||
import { FC, useState, useEffect } from 'react'; | ||
import Head from '@/components/head'; | ||
import Section from '@/components/pullRequests/section'; | ||
import Layout from '@/components/Layout'; | ||
import fetch from '@/helperFunctions/fetch'; | ||
import { FC } from 'react'; | ||
import PullRequestList from '@/components/PullRequestList'; | ||
|
||
const stalePR: FC = () => { | ||
const [pullRequests, setPullRequests] = useState<[]>([]); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const res = await fetch({ | ||
url: `${process.env.NEXT_PUBLIC_BASE_URL}/pullrequests/stale`, | ||
}); | ||
setPullRequests(res.data.pullRequests); | ||
})(); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<Layout> | ||
<Head title="Stale PRs" /> | ||
<div className="container"> | ||
<Section heading="Stale PRs" content={pullRequests} /> | ||
</div> | ||
</Layout> | ||
</div> | ||
); | ||
}; | ||
const stalePR: FC = () => <PullRequestList prType="stale" />; | ||
|
||
export default stalePR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters