Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/desktop/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ export function deleteNotebook(notebookId: string): Promise<{ status: string }>
});
}

export function renameNotebook(notebookId: string, title: string): Promise<Notebook> {
return request<Notebook>(`/notebooks/${encodeURIComponent(notebookId)}`, {
method: 'PATCH',
body: JSON.stringify({ title }),
});
}

export function deleteDocument(
notebookId: string,
sourcePath: string,
): Promise<{ status: string; chunks_removed: number }> {
const params = new URLSearchParams({
notebook_id: notebookId,
source_path: sourcePath,
});
return request<{ status: string; chunks_removed: number }>(
`/documents?${params.toString()}`,
{ method: 'DELETE' },
);
}

export async function getDocumentPreviewUrl(notebookId: string, sourcePath: string): Promise<string> {
const apiBase = await getApiBase();
const params = new URLSearchParams({
Expand Down
62 changes: 44 additions & 18 deletions apps/desktop/src/components/documents/DocumentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,63 @@
import type { DocumentInfo } from '../../types';
import './documents.css';

const TYPE_COLORS: Record<string, string> = {
pdf: '#ef4444',
docx: '#3b82f6',
txt: '#6b7280',
md: '#8b5cf6',
pptx: '#f97316',
py: '#22c55e',
};

interface DocumentCardProps {
document: DocumentInfo;
onClick?: () => void;
onContextMenu?: (e: React.MouseEvent) => void;
/** Click handler for the explicit overflow-menu button. Separate from
* onContextMenu so a left-click on the "..." button doesn't also open
* the document preview. */
onMenuClick?: (e: React.MouseEvent) => void;
}

export function DocumentCard({ document, onClick }: DocumentCardProps) {
const FILETYPE_LABEL: Record<string, string> = {
pdf: 'PDF',
docx: 'Word',
md: 'Markdown',
txt: 'Text',
pptx: 'Slides',
py: 'Python',
};

export function DocumentCard({ document, onClick, onContextMenu, onMenuClick }: DocumentCardProps) {
const ext = document.filename.split('.').pop()?.toLowerCase() ?? '';
const color = TYPE_COLORS[ext] ?? '#6b7280';
const label = FILETYPE_LABEL[ext] ?? ext.toUpperCase();

return (
<div className="document-card" onClick={onClick} role="button" tabIndex={0}>
<div className="document-card-icon" style={{ color }}>
{ext.toUpperCase()}
</div>
<div
className="document-card"
onClick={onClick}
onContextMenu={onContextMenu}
role="button"
tabIndex={0}
onKeyDown={(e) => {
if ((e.key === 'Enter' || e.key === ' ') && onClick) {
e.preventDefault();
onClick();
}
}}
>
<div className="document-card-icon">{ext.toUpperCase()}</div>
<div className="document-card-info">
<span className="document-card-name" title={document.filename}>
{document.filename}
</span>
<span className="document-card-meta">
{ext === 'pdf' ? 'PDF' : ext === 'docx' ? 'Word' : ext === 'md' ? 'Markdown' : ext === 'txt' ? 'Text' : ext === 'pptx' ? 'Slides' : ext === 'py' ? 'Python' : ext.toUpperCase()}
</span>
<span className="document-card-meta">{label}</span>
</div>
{onMenuClick && (
<button
type="button"
className="document-card-menu-btn"
aria-label="Document actions"
onClick={(e) => {
e.stopPropagation();
onMenuClick(e);
}}
>
</button>
)}
</div>
);
}
37 changes: 34 additions & 3 deletions apps/desktop/src/components/documents/documents.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* ---- DocumentCard ---- */

.document-card {
position: relative;
display: flex;
align-items: center;
gap: var(--space-3);
padding: var(--space-2) var(--space-3);
border-radius: var(--radius-sm);
border-radius: var(--radius-pill);
cursor: pointer;
transition: background var(--duration-fast) var(--ease-out);
}
Expand All @@ -23,15 +24,17 @@
font-size: 9px;
font-weight: 700;
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
color: var(--color-text-secondary);
min-width: 30px;
height: 22px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--radius-xs);
background: rgba(255, 255, 255, 0.04);
background: var(--color-bg-surface);
border: 1px solid var(--color-border);
letter-spacing: 0.02em;
letter-spacing: 0.04em;
}

.document-card-info {
Expand All @@ -57,6 +60,34 @@
font-variant-numeric: tabular-nums;
}

.document-card-menu-btn {
flex-shrink: 0;
width: 22px;
height: 22px;
padding: 0;
background: transparent;
border: none;
color: var(--color-text-muted);
font-size: 14px;
line-height: 1;
cursor: pointer;
border-radius: var(--radius-pill);
opacity: 0;
transition: opacity var(--duration-fast) var(--ease-out),
color var(--duration-fast) var(--ease-out),
background var(--duration-fast) var(--ease-out);
}

.document-card:hover .document-card-menu-btn,
.document-card-menu-btn:focus-visible {
opacity: 1;
}

.document-card-menu-btn:hover {
color: var(--color-text-primary);
background: var(--color-bg-surface);
}

/* ---- DropZone ---- */

.drop-zone {
Expand Down
18 changes: 11 additions & 7 deletions apps/desktop/src/components/layout/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CommandPalette } from '../ui/CommandPalette';
import { KeyboardShortcutsOverlay } from '../ui/KeyboardShortcuts';
import { ZoteroImportDialog } from '../ui/ZoteroImport';
import type { SourceChunk } from '../../types';
import { humanizeError } from '../../utils/errorMessages';
import './layout.css';

function isWizardComplete(): boolean {
Expand Down Expand Up @@ -135,19 +136,22 @@ export function AppShell() {
const activeNotebook = notebooks.find((nb) => nb.notebook_id === activeNotebookId);

const handleGlobalDrop = useCallback(async (files: FileList) => {
try {
for (const file of Array.from(files)) {
for (const file of Array.from(files)) {
try {
showToast(`Processing ${file.name}...`);
const result = await uploadDocument(file, activeNotebookId || undefined);
if (!activeNotebookId) {
useAppStore.getState().setActiveNotebookId(result.notebook_id);
}
showToast(`${file.name} indexed successfully`, 'success');
showToast(`${file.name} indexed`, 'success');
} catch (err) {
// Per-file failure should be specific — the old behavior aborted the
// whole batch and reported only a generic "Upload failed" with no
// filename.
showToast(humanizeError(err, { action: `upload ${file.name}` }), 'error');
}
await refreshNotebooks();
} catch (err) {
showToast(err instanceof Error ? err.message : 'Upload failed', 'error');
}
await refreshNotebooks();
}, [activeNotebookId, refreshNotebooks]);

const welcomeFileRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -235,7 +239,7 @@ export function AppShell() {
return (
<>
<div className="app-shell">
<Sidebar />
<Sidebar onOpenZotero={() => setZoteroOpen(true)} />
<ChatView
pendingSuggest={pendingSuggest}
onSuggestConsumed={() => setPendingSuggest(null)}
Expand Down
Loading
Loading