mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
update: confirm leaving page on an ongoing upload.
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
import Create from './create-file/create.svelte';
|
||||
import DeleteFile from './deleteFile.svelte';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
export let data;
|
||||
|
||||
@@ -90,6 +91,30 @@
|
||||
$: maxFileSize = isCloud
|
||||
? humanFileSize(sizeToBytes(getServiceLimit('fileSize'), 'MB', 1000))
|
||||
: null;
|
||||
|
||||
let isUploading = false;
|
||||
|
||||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||
if (isUploading) {
|
||||
event.preventDefault();
|
||||
event.returnValue = 'An upload is in progress. Are you sure you want to leave?';
|
||||
}
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
const unsubscribe = uploader.subscribe(() => {
|
||||
isUploading = $uploader.files.some(
|
||||
(file) => (!file.completed || file.progress < 100) && !file.failed
|
||||
);
|
||||
});
|
||||
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
|
||||
Reference in New Issue
Block a user