mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-27 01:16:23 +02:00
dropping files into the chat add the path
This commit is contained in:
parent
7133dbe1d9
commit
2105f6d6cd
3 changed files with 40 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
import { contextBridge, ipcRenderer, webUtils } from 'electron';
|
||||
import { ipc as ipcShared } from '@x/shared';
|
||||
|
||||
type InvokeChannels = ipcShared.InvokeChannels;
|
||||
|
|
@ -51,4 +51,8 @@ const ipc = {
|
|||
},
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld('ipc', ipc);
|
||||
contextBridge.exposeInMainWorld('ipc', ipc);
|
||||
|
||||
contextBridge.exposeInMainWorld('electronUtils', {
|
||||
getPathForFile: (file: File) => webUtils.getPathForFile(file),
|
||||
});
|
||||
|
|
@ -322,6 +322,37 @@ function ChatInputInner({
|
|||
}
|
||||
}, [handleSubmit])
|
||||
|
||||
useEffect(() => {
|
||||
const onDragOver = (e: DragEvent) => {
|
||||
if (e.dataTransfer?.types?.includes("Files")) {
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
const onDrop = (e: DragEvent) => {
|
||||
if (e.dataTransfer?.types?.includes("Files")) {
|
||||
e.preventDefault()
|
||||
}
|
||||
if (e.dataTransfer?.files && e.dataTransfer.files.length > 0) {
|
||||
const paths = Array.from(e.dataTransfer.files)
|
||||
.map((f) => window.electronUtils?.getPathForFile(f))
|
||||
.filter(Boolean)
|
||||
if (paths.length > 0) {
|
||||
const currentText = controller.textInput.value
|
||||
const pathText = paths.join(' ')
|
||||
controller.textInput.setInput(
|
||||
currentText ? `${currentText} ${pathText}` : pathText
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
document.addEventListener("dragover", onDragOver)
|
||||
document.addEventListener("drop", onDrop)
|
||||
return () => {
|
||||
document.removeEventListener("dragover", onDragOver)
|
||||
document.removeEventListener("drop", onDrop)
|
||||
}
|
||||
}, [controller])
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 bg-background border border-border rounded-3xl shadow-xl px-4 py-2.5">
|
||||
<PromptInputTextarea
|
||||
|
|
|
|||
3
apps/x/apps/renderer/src/global.d.ts
vendored
3
apps/x/apps/renderer/src/global.d.ts
vendored
|
|
@ -33,6 +33,9 @@ declare global {
|
|||
handler: (event: IPCChannels[K]['req']) => void
|
||||
): () => void;
|
||||
};
|
||||
electronUtils: {
|
||||
getPathForFile: (file: File) => string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue