core&ui: fix sidebar preview (#491)

Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
undefinedandpanda authored and GitHub committed 2023-01-18 18:32:04 +08:00
1 parent feb3b5cecb
commit feb5180476
19 files changed
+152 -244

No files matched your search

+7 -1
View File
@@ -11,6 +11,7 @@ function onBeforeUnload(e) {
interface UploadOptions {
type?: string;
pjax?: boolean;
sidebar?: boolean;
singleFileUploadCallback?: (file: File) => any;
}
export default async function uploadFiles(endpoint = '', files: File[] | FileList = [], options: UploadOptions = {}) {
@@ -65,7 +66,12 @@ export default async function uploadFiles(endpoint = '', files: File[] | FileLis
}
window.removeEventListener('beforeunload', onBeforeUnload);
Notification.success(i18n('File uploaded successfully.'));
if (options.pjax) await pjax.request({ push: false });
if (options.pjax) {
let params = '';
if (options.type) params += `?testdata=${options.type === 'testdata'}&additional_file=${options.type === 'additional_file'}`;
if (options.sidebar) params += `${params ? '&' : '?'}sidebar=true`;
await pjax.request({ push: false, url: `${endpoint}${params || ''}` });
}
} catch (e) {
console.error(e);
Notification.error(i18n('File upload failed: {0}', e.toString()));