-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemind.tsx
More file actions
133 lines (120 loc) · 4.36 KB
/
Remind.tsx
File metadata and controls
133 lines (120 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { useState } from 'react';
import { Badge, Card } from '@pinback/design-system/ui';
import CardEditModal from '@shared/components/cardEditModal/CardEditModal';
import OptionsMenuPortal from '@shared/components/sidebar/OptionsMenuPortal';
import { useAnchoredMenu } from '@shared/hooks/useAnchoredMenu';
import { belowOf } from '@shared/utils/anchorPosition';
import { REMIND_MOCK_DATA } from './constants';
import { useGetRemindArticles } from '@pages/remind/apis/queries';
import { formatLocalDateTime } from '@shared/utils/formatDateTime';
import NoReadArticles from '@pages/remind/components/noReadArticles/NoReadArticles';
import NoUnreadArticles from '@pages/remind/components/noUnreadArticles/NoUnreadArticles';
import { usePutArticleReadStatus } from '@shared/apis/queries';
import { useQueryClient } from '@tanstack/react-query';
const Remind = () => {
const [isEditOpen, setIsEditOpen] = useState(false);
const [activeBadge, setActiveBadge] = useState<'read' | 'notRead'>('notRead');
const formattedDate = formatLocalDateTime();
const queryClient = useQueryClient();
const { mutate: updateToReadStatus } = usePutArticleReadStatus();
const { data } = useGetRemindArticles(
formattedDate,
activeBadge === 'read',
1,
10
);
const {
state: menu,
open: openMenu,
close: closeMenu,
style,
containerRef,
} = useAnchoredMenu((anchor) => belowOf(anchor, 8));
const getItemTitle = (id: number | null) =>
id == null ? '' : (REMIND_MOCK_DATA.find((d) => d.id === id)?.title ?? '');
const handleBadgeClick = (badgeType: 'read' | 'notRead') => {
setActiveBadge(badgeType);
};
const EmptyStateComponent =
activeBadge === 'read' ? <NoReadArticles /> : <NoUnreadArticles />;
return (
<div className="flex flex-col py-[5.2rem] pl-[8rem]">
<p className="head3">리마인드</p>
<div className="mt-[3rem] flex gap-[2.4rem]">
<Badge
text="안 읽음"
countNum={data?.unreadArticleCount || 0}
onClick={() => handleBadgeClick('notRead')}
isActive={activeBadge === 'notRead'}
/>
<Badge
text="읽음"
countNum={data?.readArticleCount || 0}
onClick={() => handleBadgeClick('read')}
isActive={activeBadge === 'read'}
/>
</div>
{data?.articles && data.articles.length > 0 ? (
<div className="scrollbar-hide mt-[2.6rem] flex max-w-[104rem] flex-wrap gap-[1.6rem] overflow-y-auto scroll-smooth">
{data.articles.map((article) => (
<Card
key={article.articleId}
type="remind"
title={article.url}
content={article.memo}
timeRemaining={article.remindAt}
category={article.category.categoryName}
{...(activeBadge === 'notRead' && {
onOptionsClick: (e) =>
openMenu(article.category.categoryId, e.currentTarget),
})}
onClick={() => {
window.open(article.url, '_blank');
updateToReadStatus(article.articleId, {
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['remindArticles'],
});
},
onError: (error) => {
console.error(error);
},
});
}}
/>
))}
</div>
) : (
EmptyStateComponent
)}
<OptionsMenuPortal
open={menu.open}
style={style ?? undefined}
containerRef={containerRef}
categoryId={menu.categoryId}
getCategoryName={getItemTitle}
onEdit={() => {
setIsEditOpen(true);
closeMenu();
}}
onDelete={(id) => {
console.log('delete', id);
closeMenu();
}}
onClose={closeMenu}
/>
{isEditOpen && (
<div className="fixed inset-0 z-[1000]" aria-modal="true" role="dialog">
<div
className="absolute inset-0 bg-black/60 backdrop-blur-[2px]"
onClick={() => setIsEditOpen(false)}
/>
<div className="absolute inset-0 flex items-center justify-center p-4">
<CardEditModal onClose={() => setIsEditOpen(false)} />
</div>
</div>
)}
</div>
);
};
export default Remind;