a tool for shared writing and social publishing
at feature/footnotes 61 lines 1.8 kB view raw
1import { Avatar } from "components/Avatar"; 2import { ActionButton } from "./ActionButton"; 3import { useIdentityData } from "components/IdentityProvider"; 4import { AccountSmall } from "components/Icons/AccountSmall"; 5import { useRecordFromDid } from "src/utils/useRecordFromDid"; 6import { Menu, MenuItem } from "components/Menu"; 7import { useIsMobile } from "src/hooks/isMobile"; 8import { LogoutSmall } from "components/Icons/LogoutSmall"; 9import { mutate } from "swr"; 10import { SpeedyLink } from "components/SpeedyLink"; 11 12export const ProfileButton = () => { 13 let { identity } = useIdentityData(); 14 let { data: record } = useRecordFromDid(identity?.atp_did); 15 let isMobile = useIsMobile(); 16 17 return ( 18 <Menu 19 asChild 20 side={isMobile ? "top" : "right"} 21 align={isMobile ? "center" : "start"} 22 trigger={ 23 <ActionButton 24 nav 25 labelOnMobile={false} 26 icon={ 27 record ? ( 28 <Avatar 29 src={record.avatar} 30 displayName={record.displayName || record.handle} 31 /> 32 ) : ( 33 <AccountSmall /> 34 ) 35 } 36 label={record ? record.displayName || record.handle : "Account"} 37 className={`w-full`} 38 /> 39 } 40 > 41 {record && ( 42 <> 43 <SpeedyLink className="no-underline!" href={`/p/${record.handle}`}> 44 <MenuItem onSelect={() => {}}>View Profile</MenuItem> 45 </SpeedyLink> 46 47 <hr className="border-border-light border-dashed" /> 48 </> 49 )} 50 <MenuItem 51 onSelect={async () => { 52 await fetch("/api/auth/logout"); 53 mutate("identity", null); 54 }} 55 > 56 <LogoutSmall /> 57 Log Out 58 </MenuItem> 59 </Menu> 60 ); 61};