Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm leaving page if file upload in progress #1633

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading