Files
t3code/apps/mobile/src/features/threads/thread-navigation-groups.ts
T
Julius Marmingeandcodex 80d2b26d94 Add split-view mobile workspace layout
- Enable adaptive sidebar navigation on wide mobile windows
- Keep compact single-pane behavior on phones
- Extract and test shared thread grouping and layout logic

Co-authored-by: codex <[email protected]>
2026-06-26 17:08:18 -07:00

64 lines
1.9 KiB
TypeScript

import type {
EnvironmentProject,
EnvironmentThreadShell,
} from "@t3tools/client-runtime/state/shell";
import * as Arr from "effect/Array";
import * as Order from "effect/Order";
import { groupProjectsByRepository } from "../../lib/repositoryGroups";
export interface ThreadNavigationGroup {
readonly key: string;
readonly title: string;
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
}
const threadActivityOrder = Order.mapInput(
Order.Struct({
activityAt: Order.flip(Order.Number),
title: Order.String,
}),
(thread: EnvironmentThreadShell) => ({
activityAt: new Date(thread.updatedAt ?? thread.createdAt).getTime(),
title: thread.title,
}),
);
export function buildThreadNavigationGroups(input: {
readonly projects: ReadonlyArray<EnvironmentProject>;
readonly threads: ReadonlyArray<EnvironmentThreadShell>;
readonly searchQuery?: string;
}): ReadonlyArray<ThreadNavigationGroup> {
const query = input.searchQuery?.trim().toLocaleLowerCase() ?? "";
return groupProjectsByRepository(input).flatMap((group) => {
const threads = Arr.sort(
group.projects.flatMap((projectGroup) => projectGroup.threads),
threadActivityOrder,
);
const title = group.projects[0]?.project.title ?? group.title;
const groupMatches =
query.length === 0 ||
title.toLocaleLowerCase().includes(query) ||
group.title.toLocaleLowerCase().includes(query) ||
group.projects.some((projectGroup) =>
projectGroup.project.title.toLocaleLowerCase().includes(query),
);
const matchingThreads = groupMatches
? threads
: threads.filter((thread) => thread.title.toLocaleLowerCase().includes(query));
if (query.length > 0 && matchingThreads.length === 0) {
return [];
}
return [
{
key: group.key,
title,
threads: matchingThreads,
},
];
});
}