a tool for shared writing and social publishing
at debug/datetime 175 lines 4.9 kB view raw
1import { HomeSmall } from "components/Icons/HomeSmall"; 2import { ActionButton } from "./ActionButton"; 3import { Sidebar } from "./Sidebar"; 4import { useIdentityData } from "components/IdentityProvider"; 5import Link from "next/link"; 6import { DiscoverSmall } from "components/Icons/DiscoverSmall"; 7import { PublicationButtons } from "./Publications"; 8import { Popover } from "components/Popover"; 9import { MenuSmall } from "components/Icons/MenuSmall"; 10import { 11 ReaderReadSmall, 12 ReaderUnreadSmall, 13} from "components/Icons/ReaderSmall"; 14import { 15 NotificationsReadSmall, 16 NotificationsUnreadSmall, 17} from "components/Icons/NotificationSmall"; 18import { SpeedyLink } from "components/SpeedyLink"; 19import { Separator } from "components/Layout"; 20 21export type navPages = "home" | "reader" | "pub" | "discover" | "notifications"; 22 23export const DesktopNavigation = (props: { 24 currentPage: navPages; 25 publication?: string; 26}) => { 27 let { identity } = useIdentityData(); 28 return ( 29 <div className="flex flex-col gap-3"> 30 <Sidebar alwaysOpen> 31 <NavigationOptions 32 currentPage={props.currentPage} 33 publication={props.publication} 34 /> 35 </Sidebar> 36 {identity?.atp_did && ( 37 <Sidebar alwaysOpen> 38 <NotificationButton current={props.currentPage === "notifications"} /> 39 </Sidebar> 40 )} 41 </div> 42 ); 43}; 44 45export const MobileNavigation = (props: { 46 currentPage: navPages; 47 publication?: string; 48}) => { 49 let { identity } = useIdentityData(); 50 let thisPublication = identity?.publications?.find( 51 (pub) => pub.uri === props.publication, 52 ); 53 return ( 54 <div className="flex gap-1 "> 55 <Popover 56 onOpenAutoFocus={(e) => e.preventDefault()} 57 asChild 58 className="px-2! !max-w-[256px]" 59 trigger={ 60 <div className="shrink-0 p-1 text-accent-contrast h-full flex gap-2 font-bold items-center"> 61 <MenuSmall /> 62 </div> 63 } 64 > 65 <NavigationOptions 66 currentPage={props.currentPage} 67 publication={props.publication} 68 isMobile 69 /> 70 </Popover> 71 {identity?.atp_did && ( 72 <> 73 <Separator /> 74 <NotificationButton /> 75 </> 76 )} 77 </div> 78 ); 79}; 80 81const NavigationOptions = (props: { 82 currentPage: navPages; 83 publication?: string; 84 isMobile?: boolean; 85}) => { 86 let { identity } = useIdentityData(); 87 let thisPublication = identity?.publications?.find( 88 (pub) => pub.uri === props.publication, 89 ); 90 return ( 91 <> 92 <HomeButton current={props.currentPage === "home"} /> 93 <ReaderButton 94 current={props.currentPage === "reader"} 95 subs={ 96 identity?.publication_subscriptions?.length !== 0 && 97 identity?.publication_subscriptions?.length !== undefined 98 } 99 /> 100 <DiscoverButton current={props.currentPage === "discover"} /> 101 102 <hr className="border-border-light my-1" /> 103 <PublicationButtons currentPubUri={thisPublication?.uri} /> 104 </> 105 ); 106}; 107 108const HomeButton = (props: { current?: boolean }) => { 109 return ( 110 <SpeedyLink href={"/home"} className="hover:!no-underline"> 111 <ActionButton 112 nav 113 icon={<HomeSmall />} 114 label="Home" 115 className={props.current ? "bg-bg-page! border-border-light!" : ""} 116 /> 117 </SpeedyLink> 118 ); 119}; 120 121const ReaderButton = (props: { current?: boolean; subs: boolean }) => { 122 let readerUnreads = false; 123 124 if (!props.subs) return; 125 return ( 126 <SpeedyLink href={"/reader"} className="hover:no-underline!"> 127 <ActionButton 128 nav 129 icon={readerUnreads ? <ReaderUnreadSmall /> : <ReaderReadSmall />} 130 label="Reader" 131 className={` 132 ${readerUnreads && "text-accent-contrast!"} 133 ${props.current && "border-accent-contrast!"} 134 `} 135 /> 136 </SpeedyLink> 137 ); 138}; 139 140const DiscoverButton = (props: { current?: boolean }) => { 141 return ( 142 <Link href={"/discover"} className="hover:no-underline!"> 143 <ActionButton 144 nav 145 icon={<DiscoverSmall />} 146 label="Discover" 147 subtext="" 148 className={props.current ? "bg-bg-page! border-border-light!" : ""} 149 /> 150 </Link> 151 ); 152}; 153 154export function NotificationButton(props: { current?: boolean }) { 155 let { identity } = useIdentityData(); 156 let unreads = identity?.notifications[0]?.count; 157 158 return ( 159 <SpeedyLink href={"/notifications"} className="hover:no-underline!"> 160 <ActionButton 161 nav 162 labelOnMobile={false} 163 icon={ 164 unreads ? ( 165 <NotificationsUnreadSmall className="text-accent-contrast" /> 166 ) : ( 167 <NotificationsReadSmall /> 168 ) 169 } 170 label="Notifications" 171 className={`${props.current ? "bg-bg-page! border-border-light!" : ""} ${unreads ? "text-accent-contrast!" : ""}`} 172 /> 173 </SpeedyLink> 174 ); 175}