@hanzo/app 0.3.79 → 0.3.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Recents.js +4 -7
- package/dist/lib/destination.d.ts +5 -0
- package/dist/lib/destination.js +25 -1
- package/dist/recent.d.ts +6 -0
- package/dist/recent.js +14 -0
- package/package.json +1 -1
- package/dist/ProjectsTree.d.ts +0 -39
- package/dist/ProjectsTree.js +0 -179
package/dist/Recents.js
CHANGED
|
@@ -17,8 +17,7 @@ import { SidebarItem, StatusDot } from '@hanzo/ui/chat';
|
|
|
17
17
|
import { useKept } from './kept.js';
|
|
18
18
|
import { app } from './lib/host.js';
|
|
19
19
|
import { site } from './where.js';
|
|
20
|
-
import { ago, arrange, chats, MENUS, PINNED, PLAIN, runs, SINCE, UNFILED, UNTITLED, UNTITLED_RUN, viewOf } from './recent.js';
|
|
21
|
-
import { hasUnreadUpdate, ProjectsTree, useChatProjects } from './ProjectsTree.js';
|
|
20
|
+
import { ago, arrange, chats, hasUnreadUpdate, MENUS, PINNED, PLAIN, runs, SINCE, UNFILED, UNTITLED, UNTITLED_RUN, viewOf } from './recent.js';
|
|
22
21
|
import { ConversationMenu, ThreadRow, useThreadList } from './thread.js';
|
|
23
22
|
/** The menu's items: each section a heading and its options (recent.ts's phrases, drawn through `t`), the one in force checked. */
|
|
24
23
|
function items(mode, view, set, t) {
|
|
@@ -61,7 +60,6 @@ function Chats({ thread, view, keep, onOpen, onNew, }) {
|
|
|
61
60
|
const store = useThreadList(view.status === 'archived', thread);
|
|
62
61
|
const rows = useMemo(() => chats(store.threads), [store.threads]);
|
|
63
62
|
const byId = useMemo(() => new Map(store.threads.map((t) => [t.id, t])), [store.threads]);
|
|
64
|
-
const projects = useChatProjects(rows);
|
|
65
63
|
const [seenAt, setSeenAt] = useKept('hanzo.chat.seen.v1', {});
|
|
66
64
|
const seenRef = useRef(seenAt);
|
|
67
65
|
seenRef.current = seenAt;
|
|
@@ -101,8 +99,7 @@ function Chats({ thread, view, keep, onOpen, onNew, }) {
|
|
|
101
99
|
}
|
|
102
100
|
return out;
|
|
103
101
|
}, [store.threads, thread, seenAt]);
|
|
104
|
-
|
|
105
|
-
return (_jsx(List, { mode: "chat", rows: unfiledRows, view: view, keep: keep, open: (r) => r.id === thread, reading: store.loading && !store.threads.length, error: store.error, onOpen: onOpen, threads: byId, held: thread, onNew: onNew, unreadIds: unreadIds, projectsNode: view.status === 'archived' ? null : (_jsx(ProjectsTree, { folders: projects.folders, openMap: projects.openMap, byFolder: projects.byFolder, threads: byId, activeId: thread, onToggle: projects.toggleFolder, onCreate: projects.createFolder, onOpen: onOpen, onNew: onNew })) }));
|
|
102
|
+
return (_jsx(List, { mode: "chat", rows: rows, view: view, keep: keep, open: (r) => r.id === thread, reading: store.loading && !store.threads.length, error: store.error, onOpen: onOpen, threads: byId, held: thread, onNew: onNew, unreadIds: unreadIds }));
|
|
106
103
|
}
|
|
107
104
|
/** Dev's Recents: the org's coding runs alone. */
|
|
108
105
|
function Runs({ host, view, keep, onOpen }) {
|
|
@@ -186,7 +183,7 @@ function Runs({ host, view, keep, onOpen }) {
|
|
|
186
183
|
}), [host]);
|
|
187
184
|
return (_jsx(List, { mode: "dev", rows: rows, view: view, keep: keep, open: (row) => row.id === run, reading: store.loading && !store.value.length, error: store.error, onOpen: onOpen, threads: byId, held: run, onNew: () => host.go(''), customActions: devActions, hrefOf: (id) => new URL(site(app(id)), window.location.href).href }));
|
|
188
185
|
}
|
|
189
|
-
function List({ mode, rows, view, keep, open, reading, error, onOpen, threads, held = null, onNew, customActions, hrefOf, unreadIds,
|
|
186
|
+
function List({ mode, rows, view, keep, open, reading, error, onOpen, threads, held = null, onNew, customActions, hrefOf, unreadIds, }) {
|
|
190
187
|
const { t } = useI18n();
|
|
191
188
|
const label = useId();
|
|
192
189
|
const [collapsedGroups, setCollapsedGroups] = useState({});
|
|
@@ -241,5 +238,5 @@ function List({ mode, rows, view, keep, open, reading, error, onOpen, threads, h
|
|
|
241
238
|
: pinned
|
|
242
239
|
? null
|
|
243
240
|
: note;
|
|
244
|
-
return (_jsx(YStack, { "data-slot": "recents", flex: 1, minH: 0, children: _jsxs(ScrollView, { flex: 1, showsVerticalScrollIndicator: false, ...{ overscrollBehavior: 'contain' }, children: [error ? _jsx(Note, { children: error.message }) : null,
|
|
241
|
+
return (_jsx(YStack, { "data-slot": "recents", flex: 1, minH: 0, children: _jsxs(ScrollView, { flex: 1, showsVerticalScrollIndicator: false, ...{ overscrollBehavior: 'contain' }, children: [error ? _jsx(Note, { children: error.message }) : null, _jsxs(YStack, { role: "list", "aria-labelledby": label, gap: 1, children: [pinned ? (_jsxs(YStack, { role: "listitem", gap: 1, children: [heading(t(PINNED)), menus(_jsx(YStack, { role: "list", "aria-label": t(PINNED), gap: 1, children: pinned.rows.map(row) }), !loose.length)] })) : null, _jsxs(YStack, { role: "listitem", gap: 1, children: [heading(t('Recents'), label, true), menus(rest, true)] })] })] }) }));
|
|
245
242
|
}
|
|
@@ -80,6 +80,11 @@ export declare function onward(search: string): string | undefined;
|
|
|
80
80
|
* lists its callback), and hanzo.ai opened with no app's authorize request in
|
|
81
81
|
* its address, where a session would land on the site rather than in the app.
|
|
82
82
|
* hanzo.app starts its own request and comes back to hanzo.ai's page with it.
|
|
83
|
+
*
|
|
84
|
+
* Except a sign-in that goes on to hanzo.ai's checkout (`paying`): the session
|
|
85
|
+
* has to land on the site, since the checkout is the site's, so hanzo.ai signs
|
|
86
|
+
* that one in itself.
|
|
87
|
+
*
|
|
83
88
|
* Anywhere else, do nothing and report false so the caller signs in here.
|
|
84
89
|
*/
|
|
85
90
|
export declare function handoff(address: string): boolean;
|
package/dist/lib/destination.js
CHANGED
|
@@ -161,12 +161,36 @@ export function onward(search) {
|
|
|
161
161
|
const next = new URLSearchParams(search).get("next");
|
|
162
162
|
return next && safe(next, "") === next ? next : undefined;
|
|
163
163
|
}
|
|
164
|
+
/** hanzo.ai's checkout: hanzo-inc/pay mounted at hanzo.ai/pay (lib/pay `BILLING_URL`), and every path under it. */
|
|
165
|
+
const CHECKOUT = /^\/pay(?:\/|$)/;
|
|
166
|
+
/**
|
|
167
|
+
* Whether the sign-in at `address` goes on to hanzo.ai's checkout: its `next`
|
|
168
|
+
* (or `redirect`, which the sign-in page reads too) is a path on this site
|
|
169
|
+
* (`safe`) under /pay. pay sends a buyer with no session there exactly so
|
|
170
|
+
* (hanzo-inc/pay lib/auth `login`, `/login?next=/pay/…`).
|
|
171
|
+
*
|
|
172
|
+
* The checkout is served on hanzo.ai alone and reads the session hanzo.ai's
|
|
173
|
+
* origin keeps. hanzo.app answers /pay by sending it to hanzo.ai/pay, so a
|
|
174
|
+
* session made on hanzo.app never reaches the checkout, which finds none and
|
|
175
|
+
* sends the buyer to sign in again: hanzo.ai/pay, hanzo.ai/login, hanzo.app/login,
|
|
176
|
+
* hanzo.app/pay, hanzo.ai/pay, without end ("Add funds", 2026-11-13).
|
|
177
|
+
*/
|
|
178
|
+
function paying(address) {
|
|
179
|
+
const q = new URLSearchParams(address.split("#")[0].split("?")[1] ?? "");
|
|
180
|
+
const to = safe(q.get("next") || q.get("redirect"), "");
|
|
181
|
+
return to !== "" && CHECKOUT.test(new URL(to, HERE).pathname);
|
|
182
|
+
}
|
|
164
183
|
/**
|
|
165
184
|
* Send this sign-in to `address` on hanzo.app, the app's host, and report that
|
|
166
185
|
* it left, from a host that cannot start one for itself: a `guest` (no client
|
|
167
186
|
* lists its callback), and hanzo.ai opened with no app's authorize request in
|
|
168
187
|
* its address, where a session would land on the site rather than in the app.
|
|
169
188
|
* hanzo.app starts its own request and comes back to hanzo.ai's page with it.
|
|
189
|
+
*
|
|
190
|
+
* Except a sign-in that goes on to hanzo.ai's checkout (`paying`): the session
|
|
191
|
+
* has to land on the site, since the checkout is the site's, so hanzo.ai signs
|
|
192
|
+
* that one in itself.
|
|
193
|
+
*
|
|
170
194
|
* Anywhere else, do nothing and report false so the caller signs in here.
|
|
171
195
|
*/
|
|
172
196
|
export function handoff(address) {
|
|
@@ -174,7 +198,7 @@ export function handoff(address) {
|
|
|
174
198
|
return false;
|
|
175
199
|
const host = window.location.hostname;
|
|
176
200
|
const asked = new URLSearchParams(address.split("#")[0].split("?")[1] ?? "").has("client_id");
|
|
177
|
-
if (!guest(host) && !(signs(host) && !asked))
|
|
201
|
+
if (!guest(host) && !(signs(host) && !asked && !paying(address)))
|
|
178
202
|
return false;
|
|
179
203
|
window.location.assign(HOST + address);
|
|
180
204
|
return true;
|
package/dist/recent.d.ts
CHANGED
|
@@ -48,6 +48,12 @@ export declare function chats(threads: {
|
|
|
48
48
|
pinned?: boolean;
|
|
49
49
|
archived?: boolean;
|
|
50
50
|
}[]): Recent[];
|
|
51
|
+
/**
|
|
52
|
+
* Whether a conversation moved on since its reader last saw it (`seenAt`, its
|
|
53
|
+
* time per id): never the one the pane holds, nor one this browser has not
|
|
54
|
+
* seen yet.
|
|
55
|
+
*/
|
|
56
|
+
export declare function hasUnreadUpdate(rowId: string, updatedAt: string | number | undefined, activeId: string | null, seenAt: Record<string, number>): boolean;
|
|
51
57
|
/** Dev's runs as rows. */
|
|
52
58
|
export declare function runs(sessions: {
|
|
53
59
|
id: string;
|
package/dist/recent.js
CHANGED
|
@@ -74,6 +74,20 @@ export function chats(threads) {
|
|
|
74
74
|
...(t.pinned ? { pinned: true } : {}),
|
|
75
75
|
}));
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether a conversation moved on since its reader last saw it (`seenAt`, its
|
|
79
|
+
* time per id): never the one the pane holds, nor one this browser has not
|
|
80
|
+
* seen yet.
|
|
81
|
+
*/
|
|
82
|
+
export function hasUnreadUpdate(rowId, updatedAt, activeId, seenAt) {
|
|
83
|
+
if (!updatedAt || rowId === activeId)
|
|
84
|
+
return false;
|
|
85
|
+
const stamp = typeof updatedAt === 'number' ? updatedAt : Date.parse(updatedAt);
|
|
86
|
+
if (!Number.isFinite(stamp) || stamp <= 0)
|
|
87
|
+
return false;
|
|
88
|
+
const seen = seenAt[rowId];
|
|
89
|
+
return typeof seen === 'number' && stamp > seen;
|
|
90
|
+
}
|
|
77
91
|
/** Dev's runs as rows. */
|
|
78
92
|
export function runs(sessions) {
|
|
79
93
|
return sessions.map((r) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.81",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/dist/ProjectsTree.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Thread } from '@hanzo/ai';
|
|
2
|
-
import { type Recent } from './recent.js';
|
|
3
|
-
export interface ProjectFolder {
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
7
|
-
export interface StoredChatProjects {
|
|
8
|
-
folders: ProjectFolder[];
|
|
9
|
-
open: Record<string, boolean>;
|
|
10
|
-
assigned: Record<string, string>;
|
|
11
|
-
}
|
|
12
|
-
export declare const EMPTY_CHAT_PROJECTS: StoredChatProjects;
|
|
13
|
-
export declare function normalizeProjectSlug(raw: string): string;
|
|
14
|
-
export declare function readStoredChatProjects(raw: unknown): StoredChatProjects;
|
|
15
|
-
export declare function mergeProjectFolders(remote: ProjectFolder[], local: ProjectFolder[]): ProjectFolder[];
|
|
16
|
-
export declare function groupThreadsByProject(rows: Recent[], folders: ProjectFolder[], assigned: Record<string, string>): {
|
|
17
|
-
byFolder: Map<string, Recent[]>;
|
|
18
|
-
filedIds: Set<string>;
|
|
19
|
-
};
|
|
20
|
-
export declare function hasUnreadUpdate(rowId: string, updatedAt: string | number | undefined, activeId: string | null, seenAt: Record<string, number>): boolean;
|
|
21
|
-
export declare function useChatProjects(rows: Recent[]): {
|
|
22
|
-
folders: ProjectFolder[];
|
|
23
|
-
openMap: Record<string, boolean>;
|
|
24
|
-
byFolder: Map<string, Recent[]>;
|
|
25
|
-
filedIds: Set<string>;
|
|
26
|
-
toggleFolder: (id: string) => void;
|
|
27
|
-
createFolder: (name: string) => void;
|
|
28
|
-
};
|
|
29
|
-
export declare function ProjectsTree({ folders, openMap, byFolder, threads, activeId, onToggle, onCreate, onOpen, onNew, }: {
|
|
30
|
-
folders: ProjectFolder[];
|
|
31
|
-
openMap: Record<string, boolean>;
|
|
32
|
-
byFolder: Map<string, Recent[]>;
|
|
33
|
-
threads: Map<string, Thread>;
|
|
34
|
-
activeId: string | null;
|
|
35
|
-
onToggle: (id: string) => void;
|
|
36
|
-
onCreate: (name: string) => void;
|
|
37
|
-
onOpen: (row: Recent) => void;
|
|
38
|
-
onNew: () => void;
|
|
39
|
-
}): import("react").JSX.Element;
|
package/dist/ProjectsTree.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
4
|
-
import { useI18n } from '@hanzo/i18n/react';
|
|
5
|
-
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
6
|
-
import { Folder, FolderOpen, Plus } from 'lucide-react';
|
|
7
|
-
import { Button, Dialog, DialogContent, DialogTitle, Input } from '@hanzo/ui';
|
|
8
|
-
import { SidebarItem } from '@hanzo/ui/chat';
|
|
9
|
-
import { useKept } from './kept.js';
|
|
10
|
-
import { api } from './lib/api.js';
|
|
11
|
-
import { list } from './lib/list.js';
|
|
12
|
-
import { scope } from './lib/session.js';
|
|
13
|
-
import { UNTITLED } from './recent.js';
|
|
14
|
-
import { ConversationMenu, ThreadRow } from './thread.js';
|
|
15
|
-
export const EMPTY_CHAT_PROJECTS = {
|
|
16
|
-
folders: [],
|
|
17
|
-
open: {},
|
|
18
|
-
assigned: {},
|
|
19
|
-
};
|
|
20
|
-
export function normalizeProjectSlug(raw) {
|
|
21
|
-
return raw
|
|
22
|
-
.trim()
|
|
23
|
-
.toLowerCase()
|
|
24
|
-
.replace(/^[^/]+\//, '')
|
|
25
|
-
.replace(/[^a-z0-9._-]+/g, '-')
|
|
26
|
-
.replace(/^-+|-+$/g, '');
|
|
27
|
-
}
|
|
28
|
-
export function readStoredChatProjects(raw) {
|
|
29
|
-
if (!raw || typeof raw !== 'object')
|
|
30
|
-
return EMPTY_CHAT_PROJECTS;
|
|
31
|
-
const obj = raw;
|
|
32
|
-
const folders = Array.isArray(obj.folders)
|
|
33
|
-
? obj.folders.filter((f) => Boolean(f && typeof f === 'object' && typeof f.id === 'string' && f.id && typeof f.name === 'string' && f.name.trim()))
|
|
34
|
-
: [];
|
|
35
|
-
const open = obj.open && typeof obj.open === 'object' ? obj.open : {};
|
|
36
|
-
const assigned = obj.assigned && typeof obj.assigned === 'object' ? obj.assigned : {};
|
|
37
|
-
return { folders, open, assigned };
|
|
38
|
-
}
|
|
39
|
-
export function mergeProjectFolders(remote, local) {
|
|
40
|
-
const seen = new Set();
|
|
41
|
-
const out = [];
|
|
42
|
-
for (const item of [...local, ...remote]) {
|
|
43
|
-
const key = normalizeProjectSlug(item.id || item.name);
|
|
44
|
-
if (!key || seen.has(key))
|
|
45
|
-
continue;
|
|
46
|
-
seen.add(key);
|
|
47
|
-
out.push({ id: key, name: item.name.trim() });
|
|
48
|
-
}
|
|
49
|
-
return out;
|
|
50
|
-
}
|
|
51
|
-
export function groupThreadsByProject(rows, folders, assigned) {
|
|
52
|
-
const byFolder = new Map();
|
|
53
|
-
const byKey = new Map();
|
|
54
|
-
for (const folder of folders) {
|
|
55
|
-
byFolder.set(folder.id, []);
|
|
56
|
-
byKey.set(normalizeProjectSlug(folder.id), folder.id);
|
|
57
|
-
byKey.set(normalizeProjectSlug(folder.name), folder.id);
|
|
58
|
-
}
|
|
59
|
-
const filedIds = new Set();
|
|
60
|
-
for (const row of rows) {
|
|
61
|
-
const explicit = assigned[row.id] ? normalizeProjectSlug(assigned[row.id]) : '';
|
|
62
|
-
const implicit = row.project ? normalizeProjectSlug(row.project) : '';
|
|
63
|
-
const target = (explicit && byKey.get(explicit)) || (implicit && byKey.get(implicit)) || null;
|
|
64
|
-
if (!target)
|
|
65
|
-
continue;
|
|
66
|
-
byFolder.get(target)?.push(row);
|
|
67
|
-
filedIds.add(row.id);
|
|
68
|
-
}
|
|
69
|
-
return { byFolder, filedIds };
|
|
70
|
-
}
|
|
71
|
-
export function hasUnreadUpdate(rowId, updatedAt, activeId, seenAt) {
|
|
72
|
-
if (!updatedAt || rowId === activeId)
|
|
73
|
-
return false;
|
|
74
|
-
const stamp = typeof updatedAt === 'number' ? updatedAt : Date.parse(updatedAt);
|
|
75
|
-
if (!Number.isFinite(stamp) || stamp <= 0)
|
|
76
|
-
return false;
|
|
77
|
-
const seen = seenAt[rowId];
|
|
78
|
-
return typeof seen === 'number' && stamp > seen;
|
|
79
|
-
}
|
|
80
|
-
function useRemoteProjectFolders() {
|
|
81
|
-
const [remote, setRemote] = useState([]);
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
const stop = new AbortController();
|
|
84
|
-
const headers = scope();
|
|
85
|
-
Promise.all([
|
|
86
|
-
fetch(`${api()}/v1/git/repos`, { headers, signal: stop.signal })
|
|
87
|
-
.then((r) => (r.ok ? r.json() : null))
|
|
88
|
-
.catch(() => null),
|
|
89
|
-
fetch(`${api()}/v1/project`, { headers, signal: stop.signal })
|
|
90
|
-
.then((r) => (r.ok ? r.json() : null))
|
|
91
|
-
.catch(() => null),
|
|
92
|
-
]).then(([reposBody, projectsBody]) => {
|
|
93
|
-
if (stop.signal.aborted)
|
|
94
|
-
return;
|
|
95
|
-
const repoRows = list(Array.isArray(reposBody) ? reposBody : reposBody?.data ?? reposBody?.repos);
|
|
96
|
-
const projRows = list(Array.isArray(projectsBody) ? projectsBody : projectsBody?.data ?? projectsBody?.projects);
|
|
97
|
-
const collected = [];
|
|
98
|
-
for (const r of [...repoRows, ...projRows]) {
|
|
99
|
-
const name = (r?.name || r?.slug || '').trim();
|
|
100
|
-
const id = normalizeProjectSlug(r?.slug || name);
|
|
101
|
-
if (id && name)
|
|
102
|
-
collected.push({ id, name });
|
|
103
|
-
}
|
|
104
|
-
setRemote(collected);
|
|
105
|
-
});
|
|
106
|
-
return () => stop.abort();
|
|
107
|
-
}, []);
|
|
108
|
-
return remote;
|
|
109
|
-
}
|
|
110
|
-
export function useChatProjects(rows) {
|
|
111
|
-
const [raw, save] = useKept('hanzo.chat.projects.v1', EMPTY_CHAT_PROJECTS);
|
|
112
|
-
const stored = useMemo(() => readStoredChatProjects(raw), [raw]);
|
|
113
|
-
const remote = useRemoteProjectFolders();
|
|
114
|
-
const folders = useMemo(() => mergeProjectFolders(remote, stored.folders), [remote, stored.folders]);
|
|
115
|
-
const grouped = useMemo(() => groupThreadsByProject(rows, folders, stored.assigned), [rows, folders, stored.assigned]);
|
|
116
|
-
const toggleFolder = (id) => {
|
|
117
|
-
save({
|
|
118
|
-
...stored,
|
|
119
|
-
open: { ...stored.open, [id]: !stored.open[id] },
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
const createFolder = (name) => {
|
|
123
|
-
const trimmed = name.trim();
|
|
124
|
-
const id = normalizeProjectSlug(trimmed);
|
|
125
|
-
if (!id || !trimmed)
|
|
126
|
-
return;
|
|
127
|
-
const exists = stored.folders.some((f) => normalizeProjectSlug(f.id) === id);
|
|
128
|
-
save({
|
|
129
|
-
...stored,
|
|
130
|
-
folders: exists ? stored.folders : [...stored.folders, { id, name: trimmed }],
|
|
131
|
-
open: { ...stored.open, [id]: true },
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
return {
|
|
135
|
-
folders,
|
|
136
|
-
openMap: stored.open,
|
|
137
|
-
byFolder: grouped.byFolder,
|
|
138
|
-
filedIds: grouped.filedIds,
|
|
139
|
-
toggleFolder,
|
|
140
|
-
createFolder,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
export function ProjectsTree({ folders, openMap, byFolder, threads, activeId, onToggle, onCreate, onOpen, onNew, }) {
|
|
144
|
-
const { t } = useI18n();
|
|
145
|
-
const [creating, setCreating] = useState(false);
|
|
146
|
-
const [draft, setDraft] = useState('');
|
|
147
|
-
const submit = () => {
|
|
148
|
-
const next = draft.trim();
|
|
149
|
-
if (!next)
|
|
150
|
-
return;
|
|
151
|
-
onCreate(next);
|
|
152
|
-
setDraft('');
|
|
153
|
-
setCreating(false);
|
|
154
|
-
};
|
|
155
|
-
return (_jsxs(YStack, { "data-slot": "chat-projects", gap: 1, pt: "$2", children: [_jsxs(XStack, { group: true, items: "center", justify: "space-between", height: 26, paddingInlineStart: "$2", paddingInlineEnd: "$1", shrink: 0, children: [_jsx(SizableText, { fontSize: 11.5, lineHeight: 16, fontWeight: "500", color: "var(--muted-foreground)", children: t('Projects') }), _jsx(XStack, { render: "button", "data-slot": "chat-project-add", "aria-label": t('New project'), ...{ title: t('New project') }, width: 22, height: 22, rounded: "$2", items: "center", justify: "center", cursor: "pointer", opacity: folders.length === 0 ? 0.72 : 0, "$group-hover": { opacity: 1 }, focusStyle: { opacity: 1 }, $touchable: { opacity: 1 }, hoverStyle: { bg: '$hover', opacity: 1 }, onPress: () => setCreating(true), children: _jsx(Plus, { size: 13, color: "var(--muted-foreground)", "aria-hidden": true }) })] }), folders.length > 0 ? (_jsx(ConversationMenu, { threads: threads, active: activeId, onGone: onNew, primary: false, children: _jsx(YStack, { role: "list", "aria-label": t('Projects'), gap: 1, children: folders.map((folder) => {
|
|
156
|
-
const expanded = Boolean(openMap[folder.id]);
|
|
157
|
-
const children = byFolder.get(folder.id) ?? [];
|
|
158
|
-
return (_jsxs(YStack, { role: "listitem", gap: 1, children: [_jsx(SidebarItem, { "data-slot": "project-folder", "data-project-id": folder.id, "aria-expanded": expanded, rounded: 8, minH: 28, py: 0, px: "$2", $touchable: { minH: 40 }, icon: _jsx(XStack, { width: 18, height: 18, items: "center", justify: "center", shrink: 0, children: expanded ? (_jsx(FolderOpen, { size: 15, strokeWidth: 1.75, color: "var(--muted-foreground)", "aria-hidden": true })) : (_jsx(Folder, { size: 15, strokeWidth: 1.75, color: "var(--muted-foreground)", "aria-hidden": true })) }), onPress: () => onToggle(folder.id), onKeyDown: (e) => {
|
|
159
|
-
if (e.key !== 'Enter' && e.key !== ' ')
|
|
160
|
-
return;
|
|
161
|
-
e.preventDefault?.();
|
|
162
|
-
onToggle(folder.id);
|
|
163
|
-
}, children: _jsx(SizableText, { fontSize: 13, lineHeight: 18, color: "var(--foreground)", numberOfLines: 1, display: "block", children: folder.name }) }), expanded ? (children.length > 0 ? (_jsx(YStack, { role: "list", "aria-label": folder.name, gap: 1, children: children.map((child) => {
|
|
164
|
-
const threadObj = threads.get(child.id);
|
|
165
|
-
const isOpen = child.id === activeId;
|
|
166
|
-
const labelText = child.title === UNTITLED ? t(UNTITLED) : child.title;
|
|
167
|
-
const item = (_jsx(SidebarItem, { "data-slot": "project-thread", active: isOpen, rounded: 8, minH: 27, py: 0, paddingInlineStart: 28, paddingInlineEnd: "$6", $touchable: { minH: 40, paddingInlineEnd: 48 }, onPress: () => onOpen(child), onKeyDown: (e) => {
|
|
168
|
-
if (e.key !== 'Enter' && e.key !== ' ')
|
|
169
|
-
return;
|
|
170
|
-
e.preventDefault?.();
|
|
171
|
-
onOpen(child);
|
|
172
|
-
}, children: _jsx(SizableText, { fontSize: 13, lineHeight: 18, color: isOpen ? 'var(--text-primary)' : 'var(--text-secondary)', numberOfLines: 1, display: "block", children: labelText }) }));
|
|
173
|
-
return threadObj ? (_jsx(ThreadRow, { t: threadObj, active: isOpen, children: item }, child.id)) : (_jsx(YStack, { role: "listitem", children: item }, child.id));
|
|
174
|
-
}) })) : (_jsx(XStack, { height: 25, items: "center", paddingInlineStart: 28, paddingInlineEnd: "$2", "data-slot": "project-empty", children: _jsx(SizableText, { fontSize: 12.5, lineHeight: 17, color: "var(--text-tertiary)", numberOfLines: 1, children: t('No chats') }) }))) : null] }, folder.id));
|
|
175
|
-
}) }) })) : null, _jsx(Dialog, { open: creating, onOpenChange: setCreating, children: _jsxs(DialogContent, { maxW: 400, rounded: "$6", gap: "$3", children: [_jsx(DialogTitle, { children: t('New project') }), _jsx(Input, { autoFocus: true, value: draft, onChangeText: setDraft, placeholder: t('Project name'), "aria-label": t('Project name'), maxLength: 64, onKeyDown: (e) => {
|
|
176
|
-
if (e.key === 'Enter' && !e.nativeEvent?.isComposing && e.keyCode !== 229)
|
|
177
|
-
submit();
|
|
178
|
-
} }), _jsxs(XStack, { gap: "$2", justify: "flex-end", children: [_jsx(Button, { size: "sm", variant: "outline", rounded: 999, onPress: () => setCreating(false), children: t('Cancel') }), _jsx(Button, { size: "sm", rounded: 999, disabled: !draft.trim(), onPress: submit, children: t('Create') })] })] }) })] }));
|
|
179
|
-
}
|