Add drag/drop handler for .txt files in App.tsx
This commit is contained in:
20
src/App.tsx
20
src/App.tsx
@@ -77,6 +77,26 @@ export default function App() {
|
|||||||
const bodyRef = useRef(body);
|
const bodyRef = useRef(body);
|
||||||
const historySnapshotRef = useRef<HistorySnapshot | null>(null);
|
const historySnapshotRef = useRef<HistorySnapshot | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let unlisten: (() => void) | null = null;
|
||||||
|
getCurrentWindow()
|
||||||
|
.onDragDropEvent(async (event) => {
|
||||||
|
if (event.payload.type !== "drop") return;
|
||||||
|
const [path] = event.payload.paths ?? [];
|
||||||
|
if (!path || !path.toLowerCase().endsWith(".txt")) return;
|
||||||
|
await createTextFromFile(path);
|
||||||
|
})
|
||||||
|
.then((cleanup) => {
|
||||||
|
unlisten = cleanup;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Failed to register drag/drop handler", error);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
if (unlisten) unlisten();
|
||||||
|
};
|
||||||
|
}, [createTextFromFile]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
bodyRef.current = body;
|
bodyRef.current = body;
|
||||||
}, [body]);
|
}, [body]);
|
||||||
|
|||||||
Reference in New Issue
Block a user