mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-05-31 20:25:14 -04:00
Set up navigation warning while editing recipe
This commit is contained in:
parent
265313919c
commit
33870dc845
@ -1,5 +1,6 @@
|
|||||||
import { computed, ComputedRef, ref, Ref, useContext } from "@nuxtjs/composition-api";
|
import { computed, ComputedRef, ref, Ref, useContext } from "@nuxtjs/composition-api";
|
||||||
import { UserOut } from "~/lib/api/types/user";
|
import { UserOut } from "~/lib/api/types/user";
|
||||||
|
import { useNavigationWarning } from "~/composables/use-navigation-warning";
|
||||||
|
|
||||||
export enum PageMode {
|
export enum PageMode {
|
||||||
EDIT = "EDIT",
|
EDIT = "EDIT",
|
||||||
@ -65,6 +66,8 @@ function pageRefs(slug: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pageState({ slugRef, pageModeRef, editModeRef, imageKey }: PageRefs): PageState {
|
function pageState({ slugRef, pageModeRef, editModeRef, imageKey }: PageRefs): PageState {
|
||||||
|
const { activateNavigationWarning, deactivateNavigationWarning } = useNavigationWarning();
|
||||||
|
|
||||||
const toggleEditMode = () => {
|
const toggleEditMode = () => {
|
||||||
if (editModeRef.value === EditorMode.FORM) {
|
if (editModeRef.value === EditorMode.FORM) {
|
||||||
editModeRef.value = EditorMode.JSON;
|
editModeRef.value = EditorMode.JSON;
|
||||||
@ -88,8 +91,13 @@ function pageState({ slugRef, pageModeRef, editModeRef, imageKey }: PageRefs): P
|
|||||||
const setMode = (toMode: PageMode) => {
|
const setMode = (toMode: PageMode) => {
|
||||||
const fromMode = pageModeRef.value;
|
const fromMode = pageModeRef.value;
|
||||||
|
|
||||||
if (fromMode === PageMode.EDIT && toMode === PageMode.VIEW) {
|
if (fromMode === PageMode.EDIT) {
|
||||||
setEditMode(EditorMode.FORM);
|
if (toMode === PageMode.VIEW) {
|
||||||
|
setEditMode(EditorMode.FORM);
|
||||||
|
}
|
||||||
|
deactivateNavigationWarning();
|
||||||
|
} else if (toMode === PageMode.EDIT) {
|
||||||
|
activateNavigationWarning();
|
||||||
}
|
}
|
||||||
|
|
||||||
pageModeRef.value = toMode;
|
pageModeRef.value = toMode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user