diff --git a/components/EditableTODOSwitch.tsx b/components/EditableTODOSwitch.tsx
deleted file mode 100644
index c9b4f2e..0000000
--- a/components/EditableTODOSwitch.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import React from "react";
-import { Text } from "react-native";
-
-interface Props {
- is_todo: boolean;
- handleToggle: () => void;
-}
-
-export default function EditableTODOSwitch({ is_todo, handleToggle }: Props) {
- if (is_todo)
- return (
-
- TODO
-
- );
- else
- return (
-
- Shelved
-
- );
-}
diff --git a/screens/recipes/Recipe.tsx b/screens/recipes/Recipe.tsx
index bfb6734..073c0de 100644
--- a/screens/recipes/Recipe.tsx
+++ b/screens/recipes/Recipe.tsx
@@ -1,11 +1,10 @@
-import React from "react";
-import { View, ScrollView, Text } from "react-native";
+import React, { useState } from "react";
+import { View, ScrollView, Text, Switch } from "react-native";
import { useQuery } from "@tanstack/react-query";
import { useUpdateRecipe } from "./useUpdateRecipe";
import { getNugget } from "@/supabase/supabase-queries";
import { gs } from "@/global-styles";
import EditableTextInputWithCancelSave from "@/components/EditableTextInputWithCancelSave";
-import EditableTODOSwitch from "@/components/EditableTODOSwitch";
interface Props {
nugget_id: string;
@@ -22,7 +21,9 @@ export default function Recipe({ nugget_id }: Props) {
queryKey: ["nugget", nugget_id],
});
- const updateNuggetMutation = useUpdateRecipe(Number(nugget_id));
+ const updateRecipeMutation = useUpdateRecipe(Number(nugget_id));
+
+ const [isShelved, setIsShelved] = useState(nugget?.is_todo ?? true);
if (isPending) return Loading recipe...;
if (error)
@@ -31,25 +32,40 @@ export default function Recipe({ nugget_id }: Props) {
Error getting recipe: {error.name}, {error.message}
);
+
+ function handleIsShelvedSwitch(switch_value: boolean) {
+ if (!nugget) return;
+
+ updateRecipeMutation.mutate(
+ { ...nugget, is_todo: !nugget.is_todo },
+ {
+ onSuccess: () => {
+ setIsShelved(switch_value);
+ },
+ onError: (error) => {
+ console.error(error);
+ },
+ }
+ );
+ }
+
return (
Shelved
- {
- updateNuggetMutation.mutate({ ...nugget, is_todo: !nugget.is_todo });
+ {
+ console.log("Swith: ", value);
+ handleIsShelvedSwitch(value);
}}
/>
- Created at
- {nugget.created_at}
- Practice
- {nugget.practice}
Title
- updateNuggetMutation.mutate({ ...nugget, title: text })
+ updateRecipeMutation.mutate({ ...nugget, title: text })
}
/>
@@ -58,7 +74,7 @@ export default function Recipe({ nugget_id }: Props) {
- updateNuggetMutation.mutate({ ...nugget, text: text })
+ updateRecipeMutation.mutate({ ...nugget, text: text })
}
/>
diff --git a/screens/recipes/useUpdateRecipe.tsx b/screens/recipes/useUpdateRecipe.tsx
index 219e4d4..422141a 100644
--- a/screens/recipes/useUpdateRecipe.tsx
+++ b/screens/recipes/useUpdateRecipe.tsx
@@ -11,6 +11,7 @@ export function useUpdateRecipe(nugget_id: number) {
queryKey: ["nugget", nugget_id],
});
queryClient.invalidateQueries({ queryKey: ["nuggets"] });
+ queryClient.invalidateQueries({ queryKey: ["nugget", nugget_id] });
},
});
}