From afc8f194ed37631e9b3f7d3964484481d403fe37 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Wed, 1 Jan 2025 22:02:33 +0700 Subject: [PATCH] feat: show more and less --- .../src/components/launches/calendar.tsx | 139 ++++++++++++------ 1 file changed, 98 insertions(+), 41 deletions(-) diff --git a/apps/frontend/src/components/launches/calendar.tsx b/apps/frontend/src/components/launches/calendar.tsx index 5cbbdf7f2..e7f171e29 100644 --- a/apps/frontend/src/components/launches/calendar.tsx +++ b/apps/frontend/src/components/launches/calendar.tsx @@ -298,6 +298,22 @@ export const CalendarColumn: FC<{ }); }, [posts, display, getDate]); + const [showAll, setShowAll] = useState(false); + const showAllFunc = useCallback(() => { + setShowAll(true); + }, []); + + const showLessFunc = useCallback(() => { + setShowAll(false); + }, []); + + const list = useMemo(() => { + if (showAll) { + return postList; + } + return postList.slice(0, 3); + }, [postList, showAll]); + const canBeTrending = useMemo(() => { return !!trendings.find((trend) => { return dayjs @@ -404,42 +420,56 @@ export const CalendarColumn: FC<{ ); const editPost = useCallback( - (post: Post & { integration: Integration }, isDuplicate?: boolean) => async () => { - if (user?.orgId === post.submittedForOrganizationId) { - return previewPublication(post); - } - const data = await (await fetch(`/posts/${post.id}`)).json(); - const date = !isDuplicate ? null : (await (await fetch('/posts/find-slot')).json()).date; - const publishDate = dayjs.utc(date || data.posts[0].publishDate).local(); - - const ExistingData = !isDuplicate ? ExistingDataContextProvider : Fragment; - - modal.openModal({ - closeOnClickOutside: false, - closeOnEscape: false, - withCloseButton: false, - classNames: { - modal: 'w-[100%] max-w-[1400px] bg-transparent text-textColor', - }, - children: ( - - ({ ...p }))} - reopenModal={editPost(post)} - mutate={reloadCalendarView} - integrations={isDuplicate ? integrations : integrations - .slice(0) - .filter((f) => f.id === data.integration) - .map((p) => ({ ...p, picture: data.integrationPicture }))} - date={publishDate} - /> - - ), - size: '80%', - title: ``, - }); - }, + (post: Post & { integration: Integration }, isDuplicate?: boolean) => + async () => { + if (user?.orgId === post.submittedForOrganizationId) { + return previewPublication(post); + } + const data = await (await fetch(`/posts/${post.id}`)).json(); + const date = !isDuplicate + ? null + : (await (await fetch('/posts/find-slot')).json()).date; + const publishDate = dayjs + .utc(date || data.posts[0].publishDate) + .local(); + + const ExistingData = !isDuplicate + ? ExistingDataContextProvider + : Fragment; + + modal.openModal({ + closeOnClickOutside: false, + closeOnEscape: false, + withCloseButton: false, + classNames: { + modal: 'w-[100%] max-w-[1400px] bg-transparent text-textColor', + }, + children: ( + + ({ ...p }))} + reopenModal={editPost(post)} + mutate={reloadCalendarView} + integrations={ + isDuplicate + ? integrations + : integrations + .slice(0) + .filter((f) => f.id === data.integration) + .map((p) => ({ + ...p, + picture: data.integrationPicture, + })) + } + date={publishDate} + /> + + ), + size: '80%', + title: ``, + }); + }, [integrations] ); @@ -497,7 +527,7 @@ export const CalendarColumn: FC<{ canBeTrending && 'bg-customColor24' )} > - {postList.map((post) => ( + {list.map((post) => (
))} + {!showAll && postList.length > 3 && ( +
+ + Show more ({postList.length - 3}) +
+ )} + {showAll && postList.length > 3 && ( +
+ - Show less +
+ )} {(display === 'day' ? !isBeforeNow && postList.length === 0 @@ -602,7 +648,8 @@ const CalendarItem: FC<{ display: 'day' | 'week' | 'month'; post: Post & { integration: Integration }; }> = (props) => { - const { editPost, duplicatePost, post, date, isBeforeNow, state, display } = props; + const { editPost, duplicatePost, post, date, isBeforeNow, state, display } = + props; const preview = useCallback(() => { window.open(`/p/` + post.id + '?share=true', '_blank'); @@ -626,15 +673,25 @@ const CalendarItem: FC<{ style={{ opacity }} >
-
Duplicate
-
Preview
+
+ Duplicate +
+
+ Preview +