Skip to content

Commit 5332a2f

Browse files
feat(composer): add paperclip attach button for file picker
1 parent 0a2823b commit 5332a2f

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

  • crates/tauri-app/frontend/src/components/composer

crates/tauri-app/frontend/src/components/composer/Composer.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ export function Composer() {
164164
onKeyDown={handleKeyDown}
165165
rows={1}
166166
/>
167+
<input
168+
type="file"
169+
multiple
170+
id="attach-file-input"
171+
style="display:none;"
172+
onChange={(e) => {
173+
const files = e.currentTarget.files;
174+
if (!files) return;
175+
for (const file of Array.from(files)) {
176+
const reader = new FileReader();
177+
reader.onload = () => {
178+
const content = reader.result as string;
179+
const ext = file.name.split(".").pop() || "";
180+
const lang = { ts: "typescript", tsx: "tsx", js: "javascript", jsx: "jsx", py: "python", rs: "rust", go: "go", css: "css", html: "html", json: "json", md: "markdown" }[ext] || "";
181+
setStore("attachments", (prev) => [...prev, {
182+
id: crypto.randomUUID(),
183+
type: "file" as const,
184+
name: file.name,
185+
content,
186+
language: lang,
187+
}]);
188+
};
189+
reader.readAsText(file);
190+
}
191+
e.currentTarget.value = "";
192+
}}
193+
/>
194+
<button
195+
class="attach-btn"
196+
onClick={() => document.getElementById("attach-file-input")?.click()}
197+
title="Attach files"
198+
>
199+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
200+
<path d="M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"/>
201+
</svg>
202+
</button>
167203
<button
168204
class="send-btn"
169205
classList={{ stop: isGenerating() }}
@@ -297,6 +333,18 @@ if (!document.getElementById("composer-styles")) {
297333
max-height: 120px;
298334
font-family: var(--font-body);
299335
}
336+
.attach-btn {
337+
width: 32px;
338+
height: 32px;
339+
border-radius: 50%;
340+
display: flex;
341+
align-items: center;
342+
justify-content: center;
343+
color: var(--text-tertiary);
344+
flex-shrink: 0;
345+
transition: color 0.12s, background 0.12s;
346+
}
347+
.attach-btn:hover { color: var(--text-secondary); background: var(--bg-accent); }
300348
.send-btn {
301349
width: 32px;
302350
height: 32px;

0 commit comments

Comments
 (0)