Skip to content

Commit a1b6511

Browse files
committed
feat: warn user about unsaved changes on reload while syncing
1 parent d96cb92 commit a1b6511

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/app/App.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { computed, nextTick, watch, watchEffect } from 'vue';
1717
import { useI18n } from 'vue-i18n';
1818
import { useRouter } from 'vue-router';
1919
20+
const { status } = useStorage();
2021
const { state } = useSettingsStore();
2122
const { t } = useI18n();
2223
const router = useRouter();
@@ -25,6 +26,8 @@ const media = useMediaQuery();
2526
const app = useAppElement();
2627
const root = useSquircle(computed(() => (['minimized', 'mobile'].includes(media.value) ? 0 : 0.035)));
2728
29+
const preventDefault = (event: Event) => event.preventDefault();
30+
2831
watchEffect(() => {
2932
app.classList.add(state.appearance.theme);
3033
@@ -43,11 +46,17 @@ watch(
4346
4447
watch(
4548
() => state.appearance.animations,
46-
(enabled) => {
47-
app.classList[enabled ? 'remove' : 'add']('reducedMotion');
48-
}
49+
(enabled) => app.classList[enabled ? 'remove' : 'add']('reducedMotion')
4950
);
5051
52+
watch(status, (v) => {
53+
if (v === 'authenticated' || v === 'idle') {
54+
window.removeEventListener('beforeunload', preventDefault);
55+
} else {
56+
window.addEventListener('beforeunload', preventDefault);
57+
}
58+
});
59+
5160
watch(router.currentRoute, (route) => {
5261
if (route) {
5362
document.title = t(`page.${route.name as string}.title`);

0 commit comments

Comments
 (0)