({ displayProjectName }: { displayProjectName: boolean })
| 26 | import { useSession, signOut } from "next-auth/react"; |
| 27 | |
| 28 | export default function ProjectMenu({ displayProjectName }: { displayProjectName: boolean }) { |
| 29 | const router = useRouter(); |
| 30 | const utils = api.useContext(); |
| 31 | |
| 32 | const projectList = useProjectList().data; |
| 33 | |
| 34 | const selectedProject = useSelectedProject().data; |
| 35 | |
| 36 | const popover = useDisclosure(); |
| 37 | |
| 38 | const updateMutation = api.users.updateLastViewedProject.useMutation(); |
| 39 | const [updateLastViewedProject] = useHandledAsyncCallback( |
| 40 | async (projectId: string) => { |
| 41 | await updateMutation.mutateAsync({ projectId }); |
| 42 | }, |
| 43 | [updateMutation], |
| 44 | ); |
| 45 | |
| 46 | const createMutation = api.projects.create.useMutation(); |
| 47 | const [createProject, isLoading] = useHandledAsyncCallback(async () => { |
| 48 | const newProj = await createMutation.mutateAsync({ name: "Untitled Project" }); |
| 49 | await utils.projects.list.invalidate(); |
| 50 | await router.push({ |
| 51 | pathname: "/p/[projectSlug]/settings", |
| 52 | query: { projectSlug: newProj.slug }, |
| 53 | }); |
| 54 | popover.onClose(); |
| 55 | }, [createMutation, router]); |
| 56 | |
| 57 | const user = useSession().data; |
| 58 | |
| 59 | const profileImage = user?.user.image ? ( |
| 60 | <Image src={user.user.image} alt="profile picture" boxSize={6} borderRadius="50%" /> |
| 61 | ) : ( |
| 62 | <Icon as={BsPersonCircle} boxSize={6} /> |
| 63 | ); |
| 64 | |
| 65 | return ( |
| 66 | <VStack w="full" alignItems="flex-start" spacing={0} py={1}> |
| 67 | <Popover |
| 68 | placement="bottom-end" |
| 69 | isOpen={popover.isOpen} |
| 70 | onOpen={popover.onOpen} |
| 71 | onClose={popover.onClose} |
| 72 | closeOnBlur |
| 73 | > |
| 74 | <PopoverTrigger> |
| 75 | {/* https://github.com/chakra-ui/chakra-ui/issues/7647#issuecomment-1836555897 */} |
| 76 | <NavSidebarOption tabIndex={0}> |
| 77 | <HStack w="full"> |
| 78 | <Flex |
| 79 | p={1} |
| 80 | borderRadius={4} |
| 81 | backgroundColor="orange.100" |
| 82 | minW={{ base: 10, md: 8 }} |
| 83 | minH={{ base: 10, md: 8 }} |
| 84 | m={{ base: 0, md: 1 }} |
| 85 | alignItems="center" |
nothing calls this directly
no test coverage detected