Skip to content

Commit f3398e4

Browse files
Drive/account UX: custom dropdowns, right-click no longer selects, palette file search
- Replace native <select> (account: quick-code/api-token/webhook folders & scope; admin: role) with a themed Select component — the native option list rendered dark-on-dark/unreadable. - Right-click opens the context menu for the clicked item WITHOUT changing the selection. - Ctrl/Cmd+K: excludes Zero-Knowledge spaces/folders and vault files entirely, and gains a global file search (new GET /files/search for normal files) merged in as you type.
1 parent d9978f1 commit f3398e4

7 files changed

Lines changed: 206 additions & 64 deletions

File tree

‎apps/api/src/routes/files.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ export const fileRoutes: FastifyPluginAsync = async (app) => {
2424
return { files: files.map(toPublicFile) };
2525
});
2626

27+
// GET /files/search?q= — find the user's NORMAL files by name (vault files are encrypted and
28+
// never searchable server-side). Powers the Ctrl/⌘+K palette's global file lookup.
29+
app.get('/search', async (req) => {
30+
const { q, limit } = req.query as { q?: string; limit?: string };
31+
const term = (q ?? '').trim();
32+
if (term.length < 1) return { files: [] };
33+
const take = Math.min(Math.max(Number(limit) || 20, 1), 50);
34+
const files = await prisma.fileObject.findMany({
35+
where: {
36+
ownerId: req.user!.id,
37+
encMode: 'SERVER',
38+
deletedAt: null,
39+
name: { contains: term, mode: 'insensitive' },
40+
},
41+
orderBy: { name: 'asc' },
42+
take,
43+
});
44+
return { files: files.map(toPublicFile) };
45+
});
46+
2747
// POST /files?folderId= — streaming, server-side-encrypted upload.
2848
app.post('/', async (req, reply) => {
2949
const { folderId } = req.query as { folderId?: string };

‎apps/web/src/app/(app)/account/page.tsx‎

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { api, API_URL, ApiError } from '@/lib/api';
1111
import { useAuth } from '@/lib/auth';
1212
import { useT } from '@/lib/i18n';
1313
import { prompt, toast } from '@/components/ui/overlays';
14+
import { Select } from '@/components/ui/Select';
1415

1516
interface TwoFaStatus {
1617
enabled: boolean;
@@ -75,6 +76,9 @@ export default function AccountPage() {
7576
void load().catch((e) => setError(String(e)));
7677
}, [load]);
7778

79+
// Normal (non-vault) folders as dropdown options — vaults can't be API/quick/webhook targets.
80+
const folderOptions = folders.filter((f) => !f.isZeroKnowledge).map((f) => ({ value: f.id, label: f.name }));
81+
7882
async function wrap(fn: () => Promise<unknown>) {
7983
setError(null);
8084
try {
@@ -257,20 +261,12 @@ export default function AccountPage() {
257261
value={nc.code}
258262
onChange={(e) => setNc({ ...nc, code: e.target.value.toUpperCase() })}
259263
/>
260-
<select
261-
className="input max-w-[14rem]"
264+
<Select
265+
className="w-[14rem]"
262266
value={nc.targetFolderId}
263-
onChange={(e) => setNc({ ...nc, targetFolderId: e.target.value })}
264-
>
265-
<option value="">{t('account.quickCodeDefaultFolder')}</option>
266-
{folders
267-
.filter((f) => !f.isZeroKnowledge)
268-
.map((f) => (
269-
<option key={f.id} value={f.id}>
270-
{f.name}
271-
</option>
272-
))}
273-
</select>
267+
onChange={(v) => setNc({ ...nc, targetFolderId: v })}
268+
options={[{ value: '', label: t('account.quickCodeDefaultFolder') }, ...folderOptions]}
269+
/>
274270
<input
275271
className="input max-w-[9rem]"
276272
type="number"
@@ -343,16 +339,12 @@ export default function AccountPage() {
343339
value={nw.secret}
344340
onChange={(e) => setNw({ ...nw, secret: e.target.value })}
345341
/>
346-
<select className="input max-w-[13rem]" value={nw.folderId} onChange={(e) => setNw({ ...nw, folderId: e.target.value })}>
347-
<option value="">{t('account.webhookAnyFolder')}</option>
348-
{folders
349-
.filter((f) => !f.isZeroKnowledge)
350-
.map((f) => (
351-
<option key={f.id} value={f.id}>
352-
{f.name}
353-
</option>
354-
))}
355-
</select>
342+
<Select
343+
className="w-[13rem]"
344+
value={nw.folderId}
345+
onChange={(v) => setNw({ ...nw, folderId: v })}
346+
options={[{ value: '', label: t('account.webhookAnyFolder') }, ...folderOptions]}
347+
/>
356348
<button
357349
className="btn-primary"
358350
disabled={!nw.url.trim()}
@@ -430,29 +422,22 @@ export default function AccountPage() {
430422
value={nt.name}
431423
onChange={(e) => setNt({ ...nt, name: e.target.value })}
432424
/>
433-
<select
434-
className="input max-w-[11rem]"
425+
<Select
426+
className="w-[12rem]"
435427
value={nt.scopes.join(',')}
436-
onChange={(e) => setNt({ ...nt, scopes: e.target.value.split(',') as ('read' | 'write')[] })}
437-
>
438-
<option value="write">{t('account.apiScopeWrite')}</option>
439-
<option value="read">{t('account.apiScopeRead')}</option>
440-
<option value="read,write">{t('account.apiScopeBoth')}</option>
441-
</select>
442-
<select
443-
className="input max-w-[13rem]"
428+
onChange={(v) => setNt({ ...nt, scopes: v.split(',') as ('read' | 'write')[] })}
429+
options={[
430+
{ value: 'write', label: t('account.apiScopeWrite') },
431+
{ value: 'read', label: t('account.apiScopeRead') },
432+
{ value: 'read,write', label: t('account.apiScopeBoth') },
433+
]}
434+
/>
435+
<Select
436+
className="w-[13rem]"
444437
value={nt.folderId}
445-
onChange={(e) => setNt({ ...nt, folderId: e.target.value })}
446-
>
447-
<option value="">{t('account.apiTokenAnyFolder')}</option>
448-
{folders
449-
.filter((f) => !f.isZeroKnowledge)
450-
.map((f) => (
451-
<option key={f.id} value={f.id}>
452-
{f.name}
453-
</option>
454-
))}
455-
</select>
438+
onChange={(v) => setNt({ ...nt, folderId: v })}
439+
options={[{ value: '', label: t('account.apiTokenAnyFolder') }, ...folderOptions]}
440+
/>
456441
<input
457442
className="input max-w-[8rem]"
458443
type="number"

‎apps/web/src/app/(app)/admin/page.tsx‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { api, ApiError } from '@/lib/api';
77
import { useAuth } from '@/lib/auth';
88
import { useT } from '@/lib/i18n';
99
import { confirm, prompt } from '@/components/ui/overlays';
10+
import { Select } from '@/components/ui/Select';
1011
import { UpdatePanel } from './UpdatePanel';
1112

1213
interface Stats {
@@ -188,14 +189,15 @@ export default function AdminPage() {
188189
value={nu.password}
189190
onChange={(e) => setNu({ ...nu, password: e.target.value })}
190191
/>
191-
<select
192-
className="input max-w-[8rem]"
192+
<Select
193+
className="w-[9rem]"
193194
value={nu.role}
194-
onChange={(e) => setNu({ ...nu, role: e.target.value })}
195-
>
196-
<option value="USER">{t('admin.roleUser')}</option>
197-
<option value="ADMIN">{t('admin.roleAdmin')}</option>
198-
</select>
195+
onChange={(v) => setNu({ ...nu, role: v })}
196+
options={[
197+
{ value: 'USER', label: t('admin.roleUser') },
198+
{ value: 'ADMIN', label: t('admin.roleAdmin') },
199+
]}
200+
/>
199201
<button
200202
className="btn-primary"
201203
onClick={() =>

‎apps/web/src/app/(app)/drive/page.tsx‎

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,12 +1116,12 @@ export default function EspacesPage() {
11161116
pressSelect(e.key);
11171117
return;
11181118
}
1119+
// Right-click on something inside a multi-selection → bulk menu; otherwise act on the
1120+
// clicked entry WITHOUT changing the current selection (the menu targets it directly).
11191121
if (selected.has(e.key) && selected.size > 1) {
11201122
openCtx(ev, bulkMenuItems());
11211123
return;
11221124
}
1123-
setSelected(new Set([e.key]));
1124-
setAnchorKey(e.key);
11251125
openCtx(ev, entryMenuItems(e));
11261126
}
11271127

@@ -1236,19 +1236,43 @@ export default function EspacesPage() {
12361236
}
12371237
paletteItems.push({ id: 'cmd-help', kind: 'command', label: t('drive.cmdHelp'), icon: Keyboard, run: () => { close(); setHelpOpen(true); } });
12381238
if (activeSpaceId) paletteItems.push({ id: 'cmd-spaces', kind: 'command', label: t('drive.cmdGoSpaces'), icon: Home, run: () => { close(); leaveSpace(); } });
1239+
// Zero-Knowledge spaces/folders and their files are intentionally excluded: their names are
1240+
// encrypted and opening them needs the vault passphrase, so the palette never points into them.
12391241
for (const f of allFolders) {
1242+
if (f.isZeroKnowledge) continue;
12401243
paletteItems.push({
12411244
id: `f-${f.id}`,
12421245
kind: 'folder',
12431246
label: f.name,
1244-
sub: f.parentId === null ? (f.isZeroKnowledge ? t('drive.secured') : t('drive.normalSpace')) : undefined,
1245-
icon: f.isZeroKnowledge ? FolderLock : Folder,
1247+
sub: f.parentId === null ? t('drive.normalSpace') : undefined,
1248+
icon: Folder,
12461249
run: () => { close(); jumpToFolder(f); },
12471250
});
12481251
}
1249-
for (const e of entries) {
1250-
if (e.kind === 'file') paletteItems.push({ id: `x-${e.file.id}`, kind: 'file', label: e.file.name, icon: fileVisual(e.file.name, e.file.mimeType).Icon, run: () => { close(); openFile(e.file); } });
1251-
else if (e.kind === 'zk') paletteItems.push({ id: `x-${e.zk.id}`, kind: 'file', label: e.name, icon: Lock, run: () => { close(); void openZk(e.zk); } });
1252+
if (!isZk) {
1253+
for (const e of entries) {
1254+
if (e.kind === 'file') paletteItems.push({ id: `x-${e.file.id}`, kind: 'file', label: e.file.name, icon: fileVisual(e.file.name, e.file.mimeType).Icon, run: () => { close(); openFile(e.file); } });
1255+
}
1256+
}
1257+
1258+
// Global file lookup for the palette — normal (non-vault) files only, across the account.
1259+
async function searchFiles(query: string): Promise<PaletteItem[]> {
1260+
try {
1261+
const res = await api.get<{ files: PublicFile[] }>(`/files/search?q=${encodeURIComponent(query)}`);
1262+
return res.files.map((f) => ({
1263+
id: `search-${f.id}`,
1264+
kind: 'file' as const,
1265+
label: f.name,
1266+
sub: t('drive.searchInFiles'),
1267+
icon: fileVisual(f.name, f.mimeType).Icon,
1268+
run: () => {
1269+
setPaletteOpen(false);
1270+
openFile(f);
1271+
},
1272+
}));
1273+
} catch {
1274+
return [];
1275+
}
12521276
}
12531277

12541278
function toggleSort(key: SortKey) {
@@ -1310,7 +1334,7 @@ export default function EspacesPage() {
13101334
))}
13111335
</div>
13121336
)}
1313-
{paletteOpen && <CommandPalette items={paletteItems} onClose={() => setPaletteOpen(false)} />}
1337+
{paletteOpen && <CommandPalette items={paletteItems} onSearch={searchFiles} onClose={() => setPaletteOpen(false)} />}
13141338
{helpOpen && <ShortcutsHelp onClose={() => setHelpOpen(false)} />}
13151339
{viewing && <FileViewer source={viewing} onClose={() => setViewing(null)} />}
13161340
</div>
@@ -1529,7 +1553,7 @@ export default function EspacesPage() {
15291553
onRestored={reloadCurrent}
15301554
/>
15311555
)}
1532-
{paletteOpen && <CommandPalette items={paletteItems} onClose={() => setPaletteOpen(false)} />}
1556+
{paletteOpen && <CommandPalette items={paletteItems} onSearch={searchFiles} onClose={() => setPaletteOpen(false)} />}
15331557
{helpOpen && <ShortcutsHelp onClose={() => setHelpOpen(false)} />}
15341558
{viewing && <FileViewer source={viewing} onClose={() => setViewing(null)} />}
15351559
{ctxMenu && <ContextMenu x={ctxMenu.x} y={ctxMenu.y} items={ctxMenu.items} onClose={() => setCtxMenu(null)} />}

‎apps/web/src/components/drive/CommandPalette.tsx‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,54 @@ function fuzzyScore(query: string, text: string): number {
3333
return qi === q.length ? 100 - text.length : -1;
3434
}
3535

36-
export function CommandPalette({ items, onClose }: { items: PaletteItem[]; onClose: () => void }) {
36+
export function CommandPalette({
37+
items,
38+
onClose,
39+
onSearch,
40+
}: {
41+
items: PaletteItem[];
42+
onClose: () => void;
43+
/** Optional async lookup (e.g. global file search) merged in as the user types. */
44+
onSearch?: (query: string) => Promise<PaletteItem[]>;
45+
}) {
3746
const { t } = useT();
3847
const [query, setQuery] = useState('');
3948
const [active, setActive] = useState(0);
49+
const [remote, setRemote] = useState<PaletteItem[]>([]);
4050
const listRef = useRef<HTMLDivElement>(null);
4151

4252
const results = useMemo(() => {
4353
if (!query.trim()) return items.slice(0, 12);
44-
return items
54+
const local = items
4555
.map((it) => ({ it, score: Math.max(fuzzyScore(query, it.label), it.sub ? fuzzyScore(query, it.sub) : -1) }))
4656
.filter((r) => r.score >= 0)
4757
.sort((a, b) => b.score - a.score)
48-
.slice(0, 20)
4958
.map((r) => r.it);
50-
}, [items, query]);
59+
// Append async (server) results, skipping anything already shown.
60+
const seen = new Set(local.map((it) => it.id));
61+
return [...local, ...remote.filter((it) => !seen.has(it.id))].slice(0, 25);
62+
}, [items, query, remote]);
5163

5264
useEffect(() => setActive(0), [query]);
5365

66+
// Debounced async search (global file lookup).
67+
useEffect(() => {
68+
if (!onSearch || !query.trim()) {
69+
setRemote([]);
70+
return;
71+
}
72+
let cancelled = false;
73+
const handle = setTimeout(() => {
74+
void onSearch(query).then((r) => {
75+
if (!cancelled) setRemote(r);
76+
});
77+
}, 180);
78+
return () => {
79+
cancelled = true;
80+
clearTimeout(handle);
81+
};
82+
}, [query, onSearch]);
83+
5484
function onKeyDown(e: React.KeyboardEvent) {
5585
if (e.key === 'ArrowDown') {
5686
e.preventDefault();
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use client';
2+
3+
/**
4+
* Styled dropdown replacing the native <select>, whose option list renders unstyled (and often
5+
* dark-on-dark / unreadable) across browsers. Same dark theme as the rest of the app; closes on
6+
* outside-click or Escape. Drop-in: pass value/onChange/options.
7+
*/
8+
import { useEffect, useRef, useState } from 'react';
9+
import { ChevronDown, Check } from 'lucide-react';
10+
11+
export interface SelectOption {
12+
value: string;
13+
label: string;
14+
}
15+
16+
export function Select({
17+
value,
18+
onChange,
19+
options,
20+
placeholder,
21+
className,
22+
}: {
23+
value: string;
24+
onChange: (value: string) => void;
25+
options: SelectOption[];
26+
placeholder?: string;
27+
className?: string;
28+
}) {
29+
const [open, setOpen] = useState(false);
30+
const ref = useRef<HTMLDivElement>(null);
31+
const current = options.find((o) => o.value === value);
32+
33+
useEffect(() => {
34+
if (!open) return;
35+
const onDoc = (e: MouseEvent) => {
36+
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
37+
};
38+
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && setOpen(false);
39+
document.addEventListener('mousedown', onDoc);
40+
document.addEventListener('keydown', onKey);
41+
return () => {
42+
document.removeEventListener('mousedown', onDoc);
43+
document.removeEventListener('keydown', onKey);
44+
};
45+
}, [open]);
46+
47+
return (
48+
<div ref={ref} className={`relative ${className ?? ''}`}>
49+
<button
50+
type="button"
51+
onClick={() => setOpen((o) => !o)}
52+
className="flex w-full items-center justify-between gap-2 rounded-lg border border-white/10 bg-white/[0.03] px-3 py-2.5 text-left text-sm text-zinc-100 transition hover:border-white/20 focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/25"
53+
>
54+
<span className={`truncate ${current ? '' : 'text-zinc-500'}`}>{current?.label ?? placeholder ?? ''}</span>
55+
<ChevronDown size={15} className={`shrink-0 text-zinc-400 transition ${open ? 'rotate-180' : ''}`} />
56+
</button>
57+
{open && (
58+
<div className="absolute left-0 right-0 z-40 mt-1 max-h-64 overflow-auto rounded-lg border border-white/10 bg-[#15151d] py-1 shadow-2xl ring-1 ring-black/40">
59+
{options.map((o) => (
60+
<button
61+
key={o.value}
62+
type="button"
63+
onClick={() => {
64+
onChange(o.value);
65+
setOpen(false);
66+
}}
67+
className={`flex w-full items-center justify-between gap-2 px-3 py-2 text-left text-sm transition hover:bg-white/[0.06] ${
68+
o.value === value ? 'text-violet-200' : 'text-zinc-200'
69+
}`}
70+
>
71+
<span className="truncate">{o.label}</span>
72+
{o.value === value && <Check size={14} className="shrink-0 text-violet-300" />}
73+
</button>
74+
))}
75+
</div>
76+
)}
77+
</div>
78+
);
79+
}

0 commit comments

Comments
 (0)