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