mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-11-16 00:16:31 +01:00
35 lines
722 B
TypeScript
35 lines
722 B
TypeScript
|
import { inject, onUnmounted, Ref } from 'vue';
|
||
|
import { i18n } from '@/i18n';
|
||
|
import * as os from '@/os';
|
||
|
|
||
|
export function useLeaveGuard(enabled: Ref<boolean>) {
|
||
|
const setLeaveGuard = inject('setLeaveGuard');
|
||
|
|
||
|
if (setLeaveGuard) {
|
||
|
setLeaveGuard(async () => {
|
||
|
if (!enabled.value) return false;
|
||
|
|
||
|
const { canceled } = await os.confirm({
|
||
|
type: 'warning',
|
||
|
text: i18n.locale.leaveConfirm,
|
||
|
});
|
||
|
|
||
|
return canceled;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
function onBeforeLeave(ev: BeforeUnloadEvent) {
|
||
|
if (enabled.value) {
|
||
|
ev.preventDefault();
|
||
|
ev.returnValue = '';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.addEventListener('beforeunload', onBeforeLeave);
|
||
|
onUnmounted(() => {
|
||
|
window.removeEventListener('beforeunload', onBeforeLeave);
|
||
|
});
|
||
|
*/
|
||
|
}
|