Skip to content

Commit

Permalink
Merge pull request #1633 from appwrite/confirm-leaving-page
Browse files Browse the repository at this point in the history
Confirm leaving page if file upload in progress
  • Loading branch information
ItzNotABug authored Jan 27, 2025
2 parents 1ddd635 + 734c818 commit 1064fc4
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,8 +91,31 @@
$: maxFileSize = isCloud
? humanFileSize(sizeToBytes(getServiceLimit('fileSize'), 'MB', 1000))
: null;
let isUploading = false;
const beforeunload = (event: BeforeUnloadEvent) => {
// legacy browser **may** support showing a custom message.
const message = 'An upload is in progress. Are you sure you want to leave?';
if (isUploading) {
event.preventDefault();
event.returnValue = message;
return message;
}
};
onMount(() => {
return uploader.subscribe(() => {
isUploading = $uploader.files.some(
(file) => !file.completed && file.progress < 100 && !file.failed
);
});
});
</script>

<svelte:window on:beforeunload={beforeunload} />

<Container>
<ContainerHeader title="Files" serviceId="storage" isFlex={false} total={usedStorage}>
<svelte:fragment let:isButtonDisabled>
Expand Down

0 comments on commit 1064fc4

Please sign in to comment.