From 36cc4f1ef745a027540050ad668db3bcdc08d4b2 Mon Sep 17 00:00:00 2001 From: Brandon Eng Date: Tue, 16 Jan 2024 22:41:46 +0700 Subject: Ability to archive groups when they’re settled up (#45) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Settled up icon on group card * remove logs * archived groups * remove settled up * remove more settled up * recent-group-list-card * sortGroups * archiveGroup * unarchiveGroup * clean up * more clean up * Prettier, fix TS errors, add titles --------- Co-authored-by: Sebastien Castiel --- src/app/groups/recent-group-list-card.tsx | 185 ++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 src/app/groups/recent-group-list-card.tsx (limited to 'src/app/groups/recent-group-list-card.tsx') diff --git a/src/app/groups/recent-group-list-card.tsx b/src/app/groups/recent-group-list-card.tsx new file mode 100644 index 0000000..7809566 --- /dev/null +++ b/src/app/groups/recent-group-list-card.tsx @@ -0,0 +1,185 @@ +'use client' +import { RecentGroupsState } from '@/app/groups/recent-group-list' +import { + RecentGroup, + archiveGroup, + deleteRecentGroup, + getArchivedGroups, + getStarredGroups, + saveRecentGroup, + starGroup, + unarchiveGroup, + unstarGroup, +} from '@/app/groups/recent-groups-helpers' +import { Button } from '@/components/ui/button' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '@/components/ui/dropdown-menu' +import { Skeleton } from '@/components/ui/skeleton' +import { ToastAction } from '@/components/ui/toast' +import { useToast } from '@/components/ui/use-toast' +import { StarFilledIcon } from '@radix-ui/react-icons' +import { Calendar, MoreHorizontal, Star, Users } from 'lucide-react' +import Link from 'next/link' +import { useRouter } from 'next/navigation' +import { SetStateAction } from 'react' + +export function RecentGroupListCard({ + group, + state, + setState, +}: { + group: RecentGroup + state: RecentGroupsState + setState: (state: SetStateAction) => void +}) { + const router = useRouter() + const toast = useToast() + + const details = + state.status === 'complete' + ? state.groupsDetails.find((d) => d.id === group.id) + : null + + if (state.status === 'pending') return null + + const refreshGroupsFromStorage = () => + setState({ + ...state, + starredGroups: getStarredGroups(), + archivedGroups: getArchivedGroups(), + }) + + const isStarred = state.starredGroups.includes(group.id) + const isArchived = state.archivedGroups.includes(group.id) + + return ( +
  • + + + + + + + { + event.stopPropagation() + deleteRecentGroup(group) + setState({ + ...state, + groups: state.groups.filter((g) => g.id !== group.id), + }) + toast.toast({ + title: 'Group has been removed', + description: + 'The group was removed from your recent groups list.', + action: ( + { + saveRecentGroup(group) + setState({ + ...state, + groups: state.groups, + }) + }} + > + Undo + + ), + }) + }} + > + Remove from recent groups + + { + event.stopPropagation() + if (isArchived) { + unarchiveGroup(group.id) + } else { + archiveGroup(group.id) + unstarGroup(group.id) + } + refreshGroupsFromStorage() + }} + > + {isArchived ? <>Unarchive group : <>Archive group} + + + + + +
    + {details ? ( +
    +
    + + {details._count.participants} +
    +
    + + + {new Date(details.createdAt).toLocaleDateString('en-US', { + dateStyle: 'medium', + })} + +
    +
    + ) : ( +
    + + +
    + )} +
    + + + +
  • + ) +} -- cgit v1.3