Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

thread-row-layout.ts

30 lines962 Bytes

1import { useAtomValue } from "@effect/atom-react";
2import {
3 MOBILE_DEFAULT_STORED_LAYOUT,
4 resolveSidebarRowLayout,
5 withoutSidebarRowItem,
6} from "@t3tools/client-runtime/thread-row-layout";
7import { AsyncResult } from "effect/reactivity";
8import { useMemo } from "react";
9​
10import { mobilePreferencesAtom } from "../../state/preferences";
11​
12const EMPTY_LAYOUT = {};
13​
14/** The thread list card layout saved on this device, resolved against mobile's defaults. */
15export function useThreadRowLayout() {
16 const stored = useAtomValue(mobilePreferencesAtom, (preferences) =>
17 AsyncResult.isSuccess(preferences)
18 ? (preferences.value.threadRowLayout ?? EMPTY_LAYOUT)
19 : EMPTY_LAYOUT,
20 );
21 // The thread list does not track terminals, so the item never takes a line here.
22 return useMemo(
23 () =>
24 withoutSidebarRowItem(
25 resolveSidebarRowLayout(stored, MOBILE_DEFAULT_STORED_LAYOUT),
26 "terminals",
27 ),
28 [stored],
29 );