mirror of
https://github.com/usememos/memos.git
synced 2025-01-06 12:26:45 +08:00
feat: enable paste multiple resources (#729)
* feat: enable paste multiple resources * update * update
This commit is contained in:
parent
5d8b8c37a5
commit
4bebbf3e1d
1 changed files with 19 additions and 20 deletions
|
@ -151,35 +151,34 @@ const MemoEditor = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uploadMultiFiles = async (files: FileList) => {
|
||||||
|
const uploadedResourceList: Resource[] = [];
|
||||||
|
for (const file of files) {
|
||||||
|
const resource = await handleUploadResource(file);
|
||||||
|
if (resource) {
|
||||||
|
uploadedResourceList.push(resource);
|
||||||
|
if (editorState.editMemoId) {
|
||||||
|
await upsertMemoResource(editorState.editMemoId, resource.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (uploadedResourceList.length > 0) {
|
||||||
|
const resourceList = editorStateService.getState().resourceList;
|
||||||
|
editorStateService.setResourceList([...resourceList, ...uploadedResourceList]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleDropEvent = async (event: React.DragEvent) => {
|
const handleDropEvent = async (event: React.DragEvent) => {
|
||||||
if (event.dataTransfer && event.dataTransfer.files.length > 0) {
|
if (event.dataTransfer && event.dataTransfer.files.length > 0) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const uploadResourceList: Resource[] = [];
|
await uploadMultiFiles(event.dataTransfer.files);
|
||||||
for (const file of event.dataTransfer.files) {
|
|
||||||
const resource = await handleUploadResource(file);
|
|
||||||
if (resource) {
|
|
||||||
uploadResourceList.push(resource);
|
|
||||||
if (editorState.editMemoId) {
|
|
||||||
await upsertMemoResource(editorState.editMemoId, resource.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (uploadResourceList.length > 0) {
|
|
||||||
const resourceList = editorStateService.getState().resourceList;
|
|
||||||
editorStateService.setResourceList([...resourceList, ...uploadResourceList]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePasteEvent = async (event: React.ClipboardEvent) => {
|
const handlePasteEvent = async (event: React.ClipboardEvent) => {
|
||||||
if (event.clipboardData && event.clipboardData.files.length > 0) {
|
if (event.clipboardData && event.clipboardData.files.length > 0) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const file = event.clipboardData.files[0];
|
await uploadMultiFiles(event.clipboardData.files);
|
||||||
const resource = await handleUploadResource(file);
|
|
||||||
if (resource) {
|
|
||||||
const resourceList = editorStateService.getState().resourceList;
|
|
||||||
editorStateService.setResourceList([...resourceList, resource]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue