/// // dont forget to run this // npx @tanstack/router-cli generate import type { QueryClient } from "@tanstack/react-query"; import { createRootRouteWithContext, Link, Outlet, Scripts, useLocation, useNavigate, } from "@tanstack/react-router"; import { TanStackRouterDevtools } from "@tanstack/react-router-devtools"; import { type SVGProps,useState } from "react"; import * as React from "react"; import { DefaultCatchBoundary } from "~/components/DefaultCatchBoundary"; import Login from "~/components/Login"; import { NotFound } from "~/components/NotFound"; import { UnifiedAuthProvider, useAuth } from "~/providers/UnifiedAuthProvider"; import { seo } from "~/utils/seo"; export const Route = createRootRouteWithContext<{ queryClient: QueryClient; }>()({ head: () => ({ meta: [ { charSet: "utf-8", }, { name: "viewport", content: "width=device-width, initial-scale=1", }, ...seo({ title: "Red Dwarf", description: `Distributed Bluesky Client`, }), ], links: [ { rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png", }, { rel: "icon", type: "image/png", sizes: "32x32", href: "/redstar.png?whatwg", }, { rel: "icon", type: "image/png", sizes: "16x16", href: "/redstar.png?whatwg", }, { rel: "manifest", href: "/site.webmanifest", color: "#fffff" }, { rel: "icon", href: "/favicon.ico" }, ], }), errorComponent: import.meta.env.DEV ? undefined : (props) => ( ), notFoundComponent: () => , component: RootComponent, }); function RootComponent() { return ( ); } function RootDocument({ children }: { children: React.ReactNode }) { const location = useLocation(); const navigate = useNavigate(); const { agent } = useAuth(); const authed = !!agent?.did; const isHome = location.pathname === "/"; const isNotifications = location.pathname.startsWith("/notifications"); const isProfile = agent && ((location.pathname === (`/profile/${agent?.did}`)) || (location.pathname === (`/profile/${encodeURIComponent(agent?.did??"")}`))); const [postOpen, setPostOpen] = useState(false); const [postText, setPostText] = useState(""); const [posting, setPosting] = useState(false); const [postSuccess, setPostSuccess] = useState(false); const [postError, setPostError] = useState(null); async function handlePost() { if (!agent) return; setPosting(true); setPostError(null); try { await agent.com.atproto.repo.createRecord({ collection: "app.bsky.feed.post", repo: agent.assertDid, record: { $type: "app.bsky.feed.post", text: postText, createdAt: new Date().toISOString(), }, }); setPostSuccess(true); setPostText(""); setTimeout(() => { setPostSuccess(false); setPostOpen(false); }, 1500); } catch (e: any) { setPostError(e?.message || "Failed to post"); } finally { setPosting(false); } } return ( <> {postOpen && ( !posting && setPostOpen(false)} disabled={posting} aria-label="Close" > × Create Post {postSuccess ? ( ✓ Posted! ) : ( <> setPostText(e.target.value)} disabled={posting} autoFocus /> {postError && ( {postError} )} {posting ? "Posting..." : "Post"} > )} )} Red Dwarf{" "} {/* lite */} {isHome ? ( ) : ( )} Home {isNotifications ? ( ) : ( )} Notifications {location.pathname.startsWith("/feeds") ? ( ) : ( )} Feeds {location.pathname.startsWith("/search") ? ( ) : ( )} Search { if (authed && agent && agent.assertDid) { //window.location.href = `/profile/${agent.assertDid}`; navigate({ to: "/profile/$did", params: { did: agent.assertDid }, }) } }} type="button" > Profile {location.pathname.startsWith("/settings") ? ( ) : ( )} Settings setPostOpen(true)} type="button" > Post git repo made by @whey.party powered by{" "} microcosm.blue setPostOpen(true)} type="button" aria-label="Create Post" > Red Dwarf{" "} {/* lite */} {children} {isHome ? ( ) : ( )} Home {location.pathname.startsWith("/search") ? ( ) : ( )} Search {isNotifications ? ( ) : ( )} Notifications { if (authed && agent && agent.assertDid) { //window.location.href = `/profile/${agent.assertDid}`; navigate({ to: "/profile/$did", params: { did: agent.assertDid }, }) } }} type="button" > Profile {location.pathname.startsWith("/settings") ? ( ) : ( )} Settings > ); } export function TablerHashtag(props: SVGProps) { return ( ); } export function TablerHashtagFilled(props: SVGProps) { return ( ); } export function TablerEdit(props: SVGProps) { return ( ); } export function TablerHome(props: SVGProps) { return ( ); } export function TablerHomeFilled(props: SVGProps) { return ( ); } export function TablerBell(props: SVGProps) { return ( ); } export function TablerBellFilled(props: SVGProps) { return ( ); } export function TablerUserCircle(props: SVGProps) { return ( ); } export function TablerSearch(props: SVGProps) { return ( ); } export function TablerSearchFilled(props: SVGProps) { return ( ); } export function IonSettings(props: SVGProps) { return ( ); } export function IonSettingsSharp(props: SVGProps) { return ( ); }