From f548044560a271279c1661645aec7246ca41ec0e Mon Sep 17 00:00:00 2001
From: sital002 <93700622+sital002@users.noreply.github.com>
Date: Mon, 10 Jun 2024 23:38:13 +0545
Subject: [PATCH] fix: add repo button in manage repo page (#10385)
* fix: add repo button
* refactored using prettier
---
components/user/UserRepos.js | 47 +++++++++++++++----------------
pages/account/manage/repos.js | 1 +
pages/api/account/manage/repos.js | 14 ++++-----
3 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/components/user/UserRepos.js b/components/user/UserRepos.js
index 04ab5ed2765..b22485eea46 100644
--- a/components/user/UserRepos.js
+++ b/components/user/UserRepos.js
@@ -13,7 +13,6 @@ import ArrowPathIcon from "@heroicons/react/24/outline/ArrowPathIcon";
import Button from "@components/Button";
export default function UserRepos({ manage = false, confirmDelete, repos }) {
-
const [reposList, setReposList] = useState(repos || []);
const [reorder, setReorder] = useState(false);
const [reposListPrevious, setReposListPrevious] = useState(repos || []);
@@ -31,14 +30,12 @@ export default function UserRepos({ manage = false, confirmDelete, repos }) {
setReposListPrevious(updatedRepos);
setReorder(false);
};
- useEffect(()=>{
- setReposList(repos)
- },[repos]);
+ useEffect(() => {
+ setReposList(repos);
+ }, [repos]);
-
const item = (repo) => (
-
-
- {!reorder && manage && (
+
+ {!reorder && manage && (
)}
{reorder && (
-
- )}
-
+
+ )}
+
- {reposList.map((repo) => (
- {manage ? manageDelete(repo) : item(repo)}
- ))}
+ list={reposList}
+ setList={setReposList}
+ disabled={!reorder}
+ tag="ul"
+ ghostClass="border-2"
+ chosenClass="border-dashed"
+ dragClass="border-red-500"
+ className="divide-y divide-primary-low"
+ >
+ {reposList.map((repo) => (
+ {manage ? manageDelete(repo) : item(repo)}
+ ))}
>
);
diff --git a/pages/account/manage/repos.js b/pages/account/manage/repos.js
index 91955a488e2..89daebc0f46 100644
--- a/pages/account/manage/repos.js
+++ b/pages/account/manage/repos.js
@@ -73,6 +73,7 @@ export default function ManageRepos({ BASE_URL, repos }) {
const listRepos = await resRepos.json();
setRepoList(listRepos);
setUrl("");
+ setIsDisabled(false);
return setShowNotification({
show: true,
type: "success",
diff --git a/pages/api/account/manage/repos.js b/pages/api/account/manage/repos.js
index c88becdde55..5d28ff777f2 100644
--- a/pages/api/account/manage/repos.js
+++ b/pages/api/account/manage/repos.js
@@ -8,16 +8,16 @@ import Profile from "@models/Profile";
export default async function handler(req, res) {
const session = await getServerSession(req, res, authOptions);
- if(!["GET","PATCH"].includes(req.method)){
+ if (!["GET", "PATCH"].includes(req.method)) {
return res.status(400).json({ error: "Invalid request: GET required" });
}
const username = session.username;
let data = [];
- if(req.method === "GET"){
+ if (req.method === "GET") {
data = await getReposApi(username);
}
- if(req.method === "PATCH"){
+ if (req.method === "PATCH") {
data = await updateReposOrderApi(username, req.body);
}
@@ -28,9 +28,9 @@ export async function updateReposOrderApi(username, data) {
await connectMongo();
const log = logger.child({ username });
- const repoList = data.map(async (repo, idx) => {
+ const repoList = data.map(async (repo, idx) => {
try {
- return Profile.findOneAndUpdate(
+ return Profile.findOneAndUpdate(
{
username,
"repos._id": repo._id,
@@ -46,9 +46,9 @@ export async function updateReposOrderApi(username, data) {
}
});
- const repos = await Promise.allSettled(repoList).then(() => {
+ const repos = await Promise.allSettled(repoList).then(() => {
return getReposApi(username);
- })
+ });
return JSON.parse(JSON.stringify(repos));
}