Skip to content

Commit e9731ef

Browse files
committed
fix: collection bug
1 parent a18b992 commit e9731ef

File tree

16 files changed

+835
-659
lines changed

16 files changed

+835
-659
lines changed

public/locales/en/profile.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"title": "Profile",
33
"page_prev": "Previous",
44
"page_next": "Next",
5-
"read_button": "View",
65
"tabs": {
76
"dynamic": "Dynamic",
87
"favorite": "Favorites",

public/locales/zh/profile.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"title": "个人主页",
33
"page_prev": "上一页",
44
"page_next": "下一页",
5-
"read_button": "查看",
65
"tabs": {
76
"dynamic": "动态",
87
"favorite": "收藏",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { MouseEventHandler, ReactNode } from 'react';
2+
3+
interface ActionButtonProps {
4+
icon: ReactNode;
5+
text: ReactNode;
6+
className?: string;
7+
onClick: MouseEventHandler<HTMLSpanElement>;
8+
}
9+
10+
const ActionButton: React.FC<ActionButtonProps> = ({
11+
icon,
12+
text,
13+
className = '',
14+
onClick,
15+
}) => (
16+
<span
17+
className={`inline-flex items-center hover:text-blue-400 ${className}`}
18+
onClick={onClick}
19+
>
20+
{icon}
21+
{text}
22+
</span>
23+
);
24+
25+
export default ActionButton;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { AiFillDelete, AiFillEdit } from 'react-icons/ai';
2+
3+
import BasicDialog from '../BasicDialog';
4+
5+
import { Favorite } from '@/types/repository';
6+
7+
interface DeleteCollectionModalProps {
8+
visible: boolean;
9+
onClose: () => void;
10+
onConfirm: () => void;
11+
t: (key: string) => string;
12+
}
13+
14+
export const DeleteCollectionMoal: React.FC<DeleteCollectionModalProps> = ({
15+
visible,
16+
onClose,
17+
onConfirm,
18+
t,
19+
}) => {
20+
return (
21+
<BasicDialog
22+
className='w-5/6 max-w-xs rounded-md p-6'
23+
visible={visible}
24+
maskClosable={false}
25+
hideClose={true}
26+
onClose={onClose}
27+
>
28+
<div className='text-center'>
29+
<div>{t('favorite.dialog.del_title')}</div>
30+
<div className='my-2 text-sm text-gray-500'>
31+
{t('favorite.dialog.del_desc')}
32+
</div>
33+
</div>
34+
<div className='mt-4 text-center'>
35+
<button
36+
type='button'
37+
onClick={onClose}
38+
className='inline-flex items-center justify-center gap-2 rounded-md border-2 border-gray-200 py-1 px-4 text-sm font-semibold text-blue-500 transition-all hover:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:border-gray-700 dark:hover:border-blue-500'
39+
>
40+
{t('favorite.button.cancel')}
41+
</button>
42+
<button
43+
type='button'
44+
onClick={onConfirm}
45+
className='ml-4 inline-flex items-center justify-center gap-2 rounded-md border border-transparent bg-blue-500 py-1 px-4 text-sm font-semibold text-white transition-all hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800'
46+
>
47+
{t('favorite.button.confirm')}
48+
</button>
49+
</div>
50+
</BasicDialog>
51+
);
52+
};
53+
54+
interface MobileActionModalProps {
55+
visible: boolean;
56+
curItem: Favorite;
57+
onClose: () => void;
58+
onActionClick: (action: 'edit' | 'delete', item: Favorite) => void;
59+
t: (key: string) => string;
60+
}
61+
62+
export const MobileActionModal: React.FC<MobileActionModalProps> = ({
63+
visible,
64+
curItem,
65+
onClose,
66+
onActionClick,
67+
t,
68+
}) => {
69+
return (
70+
<BasicDialog
71+
className='w-4/6 max-w-xs rounded-md p-4'
72+
visible={visible}
73+
maskClosable={true}
74+
hideClose={true}
75+
onClose={onClose}
76+
>
77+
<div>
78+
<div
79+
className='flex cursor-pointer items-center border-b border-gray-100 pb-2 hover:text-blue-500'
80+
onClick={() => onActionClick('edit', curItem)}
81+
>
82+
<AiFillEdit className='mr-2' />
83+
{t('favorite.button.edit')}
84+
</div>
85+
<div
86+
className='flex cursor-pointer items-center pt-2 hover:text-red-500'
87+
onClick={() => onActionClick('delete', curItem)}
88+
>
89+
<AiFillDelete className='mr-2' />
90+
{t('favorite.button.delete')}
91+
</div>
92+
</div>
93+
</BasicDialog>
94+
);
95+
};

src/components/respository/Info.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import { numFormat } from '@/utils/util';
3131

3232
import MoreInfo from './MoreInfo';
3333
import Button from '../buttons/Button';
34-
import AddCollection from '../collection/AddCollection';
3534
import BasicDialog from '../dialog/BasicDialog';
35+
import AddCollection from '../dialog/collection/AddCollection';
3636
import Dropdown, { option } from '../dropdown/Dropdown';
3737
import { CustomLink, NoPrefetchLink } from '../links/CustomLink';
3838
import Message from '../message';
@@ -146,6 +146,18 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
146146
}
147147
};
148148

149+
const handleOptions = async () => {
150+
const res = await getFavoriteOptions();
151+
if (res.success) {
152+
setFavoriteOptions(
153+
res.data?.map((item: { fid: any; name: any }) => ({
154+
key: item.fid,
155+
value: item.name,
156+
})) || [{ key: '', value: t('favorite.default') }]
157+
);
158+
}
159+
};
160+
149161
const handleCollect = async () => {
150162
if (!isLogin) return login();
151163

@@ -157,16 +169,8 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
157169
Message.success(t('favorite.cancel'));
158170
}
159171
} else {
160-
const res = await getFavoriteOptions();
161-
if (res.success) {
162-
setFavoriteOptions(
163-
res.data?.map((item: { fid: any; name: any }) => ({
164-
key: item.fid,
165-
value: item.name,
166-
})) || [{ key: '', value: t('favorite.default') }]
167-
);
168-
setOpenModal(true);
169-
}
172+
handleOptions();
173+
setOpenModal(true);
170174
}
171175
};
172176

@@ -526,7 +530,7 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
526530
</div>
527531
{/* footer */}
528532
<div className='flex justify-between'>
529-
<AddCollection onFinish={getFavoriteOptions} />
533+
<AddCollection onFinish={handleOptions} />
530534
<Button
531535
className='py-0 px-3'
532536
variant='gradient'

0 commit comments

Comments
 (0)