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