mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-12 08:25:47 +01:00
✨ Add beforeunload hook (#762)
This commit is contained in:
@@ -1,18 +1,20 @@
|
|||||||
|
import { ActionIcon, Button, Group, Text, Title, Tooltip } from '@mantine/core';
|
||||||
|
import { useHotkeys, useWindowEvent } from '@mantine/hooks';
|
||||||
|
import { hideNotification, showNotification } from '@mantine/notifications';
|
||||||
|
import { IconEditCircle, IconEditCircleOff } from '@tabler/icons';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import Consola from 'consola';
|
import Consola from 'consola';
|
||||||
import { ActionIcon, Button, Group, Text, Title, Tooltip } from '@mantine/core';
|
|
||||||
import { IconEditCircle, IconEditCircleOff } from '@tabler/icons';
|
|
||||||
import { getCookie } from 'cookies-next';
|
import { getCookie } from 'cookies-next';
|
||||||
import { Trans, useTranslation } from 'next-i18next';
|
import { Trans, useTranslation } from 'next-i18next';
|
||||||
import { useHotkeys } from '@mantine/hooks';
|
|
||||||
import { hideNotification, showNotification } from '@mantine/notifications';
|
|
||||||
import { useConfigContext } from '../../../../../config/provider';
|
import { useConfigContext } from '../../../../../config/provider';
|
||||||
import { useScreenSmallerThan } from '../../../../../hooks/useScreenSmallerThan';
|
import { useScreenSmallerThan } from '../../../../../hooks/useScreenSmallerThan';
|
||||||
|
|
||||||
import { useEditModeStore } from '../../../../Dashboard/Views/useEditModeStore';
|
import { useEditModeStore } from '../../../../Dashboard/Views/useEditModeStore';
|
||||||
import { AddElementAction } from '../AddElementAction/AddElementAction';
|
|
||||||
import { useNamedWrapperColumnCount } from '../../../../Dashboard/Wrappers/gridstack/store';
|
import { useNamedWrapperColumnCount } from '../../../../Dashboard/Wrappers/gridstack/store';
|
||||||
import { useCardStyles } from '../../../useCardStyles';
|
import { useCardStyles } from '../../../useCardStyles';
|
||||||
|
import { AddElementAction } from '../AddElementAction/AddElementAction';
|
||||||
|
|
||||||
|
const beforeUnloadEventText = 'Exit the edit mode to save your changes';
|
||||||
|
|
||||||
export const ToggleEditModeAction = () => {
|
export const ToggleEditModeAction = () => {
|
||||||
const { enabled, toggleEditMode } = useEditModeStore();
|
const { enabled, toggleEditMode } = useEditModeStore();
|
||||||
@@ -29,6 +31,16 @@ export const ToggleEditModeAction = () => {
|
|||||||
|
|
||||||
useHotkeys([['ctrl+E', toggleEditMode]]);
|
useHotkeys([['ctrl+E', toggleEditMode]]);
|
||||||
|
|
||||||
|
useWindowEvent('beforeunload', (event: BeforeUnloadEvent) => {
|
||||||
|
if (enabled) {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
event.returnValue = beforeUnloadEventText;
|
||||||
|
return beforeUnloadEventText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
const toggleButtonClicked = () => {
|
const toggleButtonClicked = () => {
|
||||||
toggleEditMode();
|
toggleEditMode();
|
||||||
if (enabled || config === undefined || config?.schemaVersion === undefined) {
|
if (enabled || config === undefined || config?.schemaVersion === undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user