BlueSky & more on desktop
lazurite.stormlightlabs.org/
tauri
rust
typescript
bluesky
appview
atproto
solid
1import { buildThreadOverlayRoute, getThreadOverlayUri, TIMELINE_ROUTE } from "$/lib/feeds";
2import { buildPostRoute, decodePostRouteUri, isThreadDrawerPath, POST_ROUTE } from "$/lib/post-routes";
3import { useLocation, useNavigate } from "@solidjs/router";
4import { createMemo } from "solid-js";
5
6export function useThreadOverlayNavigation() {
7 const location = useLocation();
8 const navigate = useNavigate();
9 const drawerEnabled = createMemo(() => isThreadDrawerPath(location.pathname));
10 const postRouteThreadUri = createMemo(() => {
11 const prefix = `${POST_ROUTE}/`;
12 if (!location.pathname.startsWith(prefix)) {
13 return null;
14 }
15
16 return decodePostRouteUri(location.pathname.slice(prefix.length));
17 });
18
19 const threadUri = createMemo(() => {
20 if (drawerEnabled()) {
21 return getThreadOverlayUri(location.search);
22 }
23
24 return postRouteThreadUri();
25 });
26
27 function openThread(uri: string) {
28 if (drawerEnabled()) {
29 return navigate(buildThreadOverlayRoute(location.pathname, location.search, uri));
30 }
31
32 return navigate(buildPostRoute(uri));
33 }
34
35 function buildThreadHref(uri: string | null) {
36 if (!uri) {
37 return TIMELINE_ROUTE;
38 }
39
40 if (drawerEnabled()) {
41 return buildThreadOverlayRoute(location.pathname, location.search, uri);
42 }
43
44 return buildPostRoute(uri);
45 }
46
47 function closeThread() {
48 if (drawerEnabled() || getThreadOverlayUri(location.search)) {
49 return navigate(buildThreadOverlayRoute(location.pathname, location.search, null));
50 }
51
52 if (globalThis.history.length > 1) {
53 return navigate(-1);
54 }
55
56 return navigate(TIMELINE_ROUTE);
57 }
58
59 return { buildThreadHref, closeThread, drawerEnabled, openThread, threadUri };
60}