Skip to content

Commit

Permalink
fix: edit descriptions failed
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronConlon committed Jul 25, 2024
1 parent 696d80e commit 8323979
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 40 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

# GitHub Repository Manager

![GitHub stars](https://img.shields.io/github/stars/AaronConlon/delete-github-repos-in-batches?style=social)
![GitHub forks](https://img.shields.io/github/forks/AaronConlon/delete-github-repos-in-batches?style=social)
![GitHub issues](https://img.shields.io/github/issues/AaronConlon/delete-github-repos-in-batches)
![GitHub license](https://img.shields.io/github/license/AaronConlon/delete-github-repos-in-batches)
![GitHub stars](https://img.shields.io/github/stars/AaronConlon/GitBatch?style=social)
![GitHub forks](https://img.shields.io/github/forks/AaronConlon/GitBatch?style=social)
![GitHub issues](https://img.shields.io/github/issues/AaronConlon/GitBatch)
![GitHub license](https://img.shields.io/github/license/AaronConlon/GitBatch)
![Node.js Version](https://img.shields.io/badge/node-v20.14.0-brightgreen)
![Rush.js](https://img.shields.io/badge/rushjs-✓-blue)
![Next.js](https://img.shields.io/badge/nextjs-✓-black)
Expand Down Expand Up @@ -39,12 +39,12 @@ GitHub Repository Manager 是一个强大的工具,用于批量管理您的 Gi

1. 克隆仓库:
```
git clone https://github.com/AaronConlon/delete-github-repos-in-batches.git
git clone https://github.com/AaronConlon/GitBatch.git
```

2. 进入项目目录:
```
cd delete-github-repos-in-batches
cd GitBatch
```

3. 安装依赖:
Expand Down
28 changes: 28 additions & 0 deletions apps/v-next/components/ConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Button, Modal } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
interface ConfirmModalProps {
children: React.ReactNode;
title: React.ReactNode;
confirmFc: () => void;
loading?: boolean;
}
export default function ConfirmModal({ children, confirmFc, title, loading }: ConfirmModalProps) {
const [opened, { open, close }] = useDisclosure(false);

return (
<>
<Modal opened={opened} onClose={close} title={title} size={'auto'}>
<div className="p-6 w-[300px] text-center">Are you sure?</div>
<div className="mt-4 flex justify-center gap-2 items-center">
<Button variant="outline" size="sm" onClick={close}>
Cancel
</Button>
<Button onClick={confirmFc} size="sm" disabled={loading} loading={loading}>
Confirm
</Button>
</div>
</Modal>
<button onClick={open}>{children}</button>
</>
);
}
11 changes: 4 additions & 7 deletions apps/v-next/components/ContributeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import { useRequest } from 'ahooks';
import { Github } from 'lucide-react';

export default function ContributeInfo() {
const repoInfo = useRequest(
() => GithubAPI.repo.getRepoInfoByName('AaronConlon', 'delete-github-repos-in-batches'),
{
cacheKey: 'repo-info',
manual: true
}
);
const repoInfo = useRequest(() => GithubAPI.repo.getRepoInfoByName('AaronConlon', 'GitBatch'), {
cacheKey: 'repo-info',
manual: true
});

const userInfo = useRequest(() => GithubAPI.user.getUserInfoByName('AaronConlon'), {
cacheKey: 'user-info'
Expand Down
14 changes: 11 additions & 3 deletions apps/v-next/components/query/DescriptionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ interface DeleteModalProps {
accessToken: string;
description?: string;
repoItem: IGithubRepository;
updateDescription: (description: string) => void;
}

export default function DescriptionModal({ description = '', accessToken, repoItem }: DeleteModalProps) {
export default function DescriptionModal({
description,
accessToken,
repoItem,
updateDescription
}: DeleteModalProps) {
const [opened, { open, close }] = useDisclosure(false);
const [value, setValue] = useState('');

useEffect(() => {
setValue(description);
setValue(description ?? '');
}, [description]);

const { run, loading, cancel } = useRequest(
Expand All @@ -32,6 +38,8 @@ export default function DescriptionModal({ description = '', accessToken, repoIt
});
toast.success('Change the repository description successfully');
setValue(value);
updateDescription(value);
close();
},
{
manual: true,
Expand Down Expand Up @@ -65,7 +73,7 @@ export default function DescriptionModal({ description = '', accessToken, repoIt
</Modal>

<div className="cursor-pointer" onClick={open}>
{value}
{description && description.length ? description : '-'}
</div>
</>
);
Expand Down
67 changes: 44 additions & 23 deletions apps/v-next/components/query/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Link from 'next/link';
import { useRouter, useSearchParams } from 'next/navigation';
import { useState } from 'react';
import toast from 'react-hot-toast';
import ConfirmModal from '../ConfirmModal';
import DeleteModal from './DeleteModal';
import DescriptionModal from './DescriptionModal';

Expand Down Expand Up @@ -71,11 +72,31 @@ export default function Query({ accessToken }: IQueryProps) {
{
onSuccess: () => {
setSelectedRows([]);
debugger;
}
}
);

const deleteRepo = useRequest(
async ({ id, owner, name }: { id: number; name: string; owner: IGithubRepository['owner'] }) => {
try {
await GithubAPI.repo.removeRepo({
auth: accessToken,
repo: name,
owner: owner.login
});
toast.success('Delete the repository successfully');
data && mutate(data.filter((i) => i.id !== id));
} catch (error) {
// error info
console.error(error);
toast.error('Failed to delete the repository');
}
},
{
manual: true
}
);

const changeRepoIsPrivate = debounce((repository: IGithubRepository, isPrivate: boolean) => {
try {
if (isPrivate === repository.private) return;
Expand Down Expand Up @@ -296,39 +317,39 @@ export default function Query({ accessToken }: IQueryProps) {
accessToken={accessToken}
description={description}
repoItem={item}
updateDescription={(text: string) => {
data && mutate(data.map((i) => (i.id === id ? { ...i, description: text } : i)));
}}
/>
</Table.Td>
<Table.Td className="hidden md:table-cell">{stargazers_count}</Table.Td>
<Table.Td className="hidden md:table-cell">{forks_count}</Table.Td>
<Table.Td className="hidden md:table-cell text-center">{stargazers_count}</Table.Td>
<Table.Td className="hidden md:table-cell text-center">{forks_count}</Table.Td>
<Table.Td className="hidden md:table-cell">
<button
className="opacity-0 group-hover:opacity-100 text-red-500 pt-1 flex gap-1 items-center"
onClick={async () => {
try {
await GithubAPI.repo.removeRepo({
auth: accessToken,
repo: name,
owner: owner.login
});
toast.success('Delete the repository successfully');
mutate(data.filter((i) => i.id !== id));
} catch (error) {
// error info
console.error(error);
toast.error('Failed to delete the repository');
}
}}
<ConfirmModal
title={
<div>
Delete: <span className="text-red-500 text-sm font-thin px-2">{name}</span>
</div>
}
confirmFc={() =>
deleteRepo.run({
id,
name,
owner
})
}
loading={deleteRepo.loading}
>
<Trash2 size={16} />
</button>
<Trash2 size={16} className="opacity-0 group-hover:opacity-100 text-red-500 mt-2" />
</ConfirmModal>
</Table.Td>
</Table.Tr>
);
})}
</Table.Tbody>
</Table>
) : (
<div className="min-h-[50vh]">
<div className="min-h-[50vh] p-2">
<Skeleton height={24} radius="xl" />
<Skeleton height={24} mt={6} radius="xl" />
<Skeleton height={24} mt={6} width="70%" radius="xl" />
Expand Down
2 changes: 1 addition & 1 deletion packages/consts/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const PROJECT = {
version: '0.0.1',
ogImage:
'https://de4965e.webp.li/blog-images/2024/07/8c71d1b5dc982bf1dbe091d162f2bf46.png',
sourceCode: 'https://github.com/AaronConlon/delete-github-repos-in-batches',
sourceCode: 'https://github.com/AaronConlon/GitBatch',
author: {
name: 'Aaron Conlon',
email: '[email protected]',
Expand Down

0 comments on commit 8323979

Please sign in to comment.