summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/use-leave-guard.ts
blob: 5f7e56e8a95727513ce791e0581498fada4863d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import { Ref } from 'vue';

export function useLeaveGuard(enabled: Ref<boolean>) {
	/* TODO
	const setLeaveGuard = inject('setLeaveGuard');

	if (setLeaveGuard) {
		setLeaveGuard(async () => {
			if (!enabled.value) return false;

			const { canceled } = await os.confirm({
				type: 'warning',
				text: i18n.ts.leaveConfirm,
			});

			return canceled;
		});
	} else {
		onBeforeRouteLeave(async (to, from) => {
			if (!enabled.value) return true;

			const { canceled } = await os.confirm({
				type: 'warning',
				text: i18n.ts.leaveConfirm,
			});

			return !canceled;
		});
	}
	*/

	/*
	function onBeforeLeave(ev: BeforeUnloadEvent) {
		if (enabled.value) {
			ev.preventDefault();
			ev.returnValue = '';
		}
	}

	window.addEventListener('beforeunload', onBeforeLeave);
	onUnmounted(() => {
		window.removeEventListener('beforeunload', onBeforeLeave);
	});
	*/
}