mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 18:53:17 -05:00 
			
		
		
		
	Set up navigation warning while editing recipe
This commit is contained in:
		@@ -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,9 +91,14 @@ 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) {
 | 
				
			||||||
 | 
					      if (toMode === PageMode.VIEW) {
 | 
				
			||||||
        setEditMode(EditorMode.FORM);
 | 
					        setEditMode(EditorMode.FORM);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      deactivateNavigationWarning();
 | 
				
			||||||
 | 
					    } else if (toMode === PageMode.EDIT) {
 | 
				
			||||||
 | 
					      activateNavigationWarning();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pageModeRef.value = toMode;
 | 
					    pageModeRef.value = toMode;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user