({ isOpen, setIsOpen }: { isOpen: boolean; setIsOpen: (open: boolean) => void })
| 51 | } |
| 52 | |
| 53 | function Drawer({ isOpen, setIsOpen }: { isOpen: boolean; setIsOpen: (open: boolean) => void }) { |
| 54 | const { t } = useTranslation() |
| 55 | const { logout } = useAuth() |
| 56 | const { colorMode, toggleColorMode } = useColorMode() |
| 57 | const queryClient = useQueryClient() |
| 58 | const currentUser = queryClient.getQueryData<{ email: string }>(['currentUser']) |
| 59 | const flashcardsService = { getCollections } |
| 60 | const navigate = useNavigate() |
| 61 | |
| 62 | const { data, isLoading } = useQuery({ |
| 63 | queryKey: ['collections'], |
| 64 | queryFn: flashcardsService.getCollections, |
| 65 | placeholderData: (prevData) => prevData, |
| 66 | }) |
| 67 | |
| 68 | const collections: Collection[] = data || [] |
| 69 | |
| 70 | const handleNavigate = () => setIsOpen(false) |
| 71 | |
| 72 | const handleLogout = async () => { |
| 73 | logout() |
| 74 | setIsOpen(false) |
| 75 | navigate({ to: '/' }) |
| 76 | } |
| 77 | |
| 78 | return ( |
| 79 | <DrawerRoot open={isOpen} onOpenChange={(e) => setIsOpen(e.open)} placement="end"> |
| 80 | <DrawerBackdrop /> |
| 81 | <DrawerContent rounded="none" maxW="280px" bg="bg.box"> |
| 82 | <DrawerHeader display="flex" justifyContent="center" padding=".5rem"> |
| 83 | <Link to="/collections" onClick={handleNavigate}> |
| 84 | <Image width="3rem" src={Logo} alt="logo" /> |
| 85 | </Link> |
| 86 | </DrawerHeader> |
| 87 | <DrawerBody py={2} px={1}> |
| 88 | <VStack align="stretch"> |
| 89 | {isLoading ? ( |
| 90 | <VStack py={4}> |
| 91 | <Spinner /> |
| 92 | </VStack> |
| 93 | ) : ( |
| 94 | <List.Root> |
| 95 | {collections.map((collection: Collection) => ( |
| 96 | <CollectionListItem |
| 97 | key={collection.id} |
| 98 | collection={collection} |
| 99 | onNavigate={handleNavigate} |
| 100 | /> |
| 101 | ))} |
| 102 | </List.Root> |
| 103 | )} |
| 104 | </VStack> |
| 105 | </DrawerBody> |
| 106 | <DrawerFooter> |
| 107 | <VStack width="100%" gap={2}> |
| 108 | <HStack justifyContent="flex-end" w="100%" alignItems="center"> |
| 109 | {currentUser?.email && ( |
| 110 | <Text fontSize="sm" color="fg.muted" maxWidth="11.5rem" truncate> |
nothing calls this directly
no test coverage detected