Fix attachment previews and comment permissions
This commit is contained in:
parent
1cccb852a5
commit
e491becbc4
4 changed files with 62 additions and 11 deletions
|
|
@ -31,18 +31,19 @@ export function Dropzone({
|
|||
|
||||
const startUpload = useCallback(async (files: FileList | File[]) => {
|
||||
const list = Array.from(files).slice(0, maxFiles);
|
||||
const url = await generateUrl({});
|
||||
const uploaded: Uploaded[] = [];
|
||||
for (const file of list) {
|
||||
if (file.size > maxSize) continue;
|
||||
const url = await generateUrl({});
|
||||
const id = `${file.name}-${file.size}-${Date.now()}`;
|
||||
const localPreview = file.type.startsWith("image/") ? URL.createObjectURL(file) : undefined;
|
||||
setItems((prev) => [...prev, { id, name: file.name, progress: 0, status: "uploading" }]);
|
||||
await new Promise<void>((resolve) => {
|
||||
const form = new FormData();
|
||||
form.append("file", file);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", url);
|
||||
if (file.type) {
|
||||
xhr.setRequestHeader("Content-Type", file.type);
|
||||
}
|
||||
xhr.upload.onprogress = (e) => {
|
||||
if (!e.lengthComputable) return;
|
||||
const progress = Math.round((e.loaded / e.total) * 100);
|
||||
|
|
@ -66,7 +67,7 @@ export function Dropzone({
|
|||
setItems((prev) => prev.map((it) => (it.id === id ? { ...it, status: "error" } : it)));
|
||||
resolve();
|
||||
};
|
||||
xhr.send(form);
|
||||
xhr.send(file);
|
||||
});
|
||||
}
|
||||
if (uploaded.length) onUploaded?.(uploaded);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue