mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
added Feedback page, added braindump backend
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
import { useCreateNote } from "@/hooks/firebase/useCreateNote";
|
||||
import { useDeleteNote } from "@/hooks/firebase/useDeleteNote";
|
||||
import { useGetNotes } from "@/hooks/firebase/useGetNotes";
|
||||
import { useUpdateNote } from "@/hooks/firebase/useUpdateNote";
|
||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
import { createContext, useContext, useState } from "react";
|
||||
import { create } from "react-test-renderer";
|
||||
|
||||
export interface IBrainDump {
|
||||
id: number;
|
||||
@ -8,7 +13,7 @@ export interface IBrainDump {
|
||||
}
|
||||
|
||||
interface IBrainDumpContext {
|
||||
brainDumps: IBrainDump[];
|
||||
brainDumps: IBrainDump[] | undefined;
|
||||
updateBrainDumpItem: (id: number, changes: Partial<IBrainDump>) => void;
|
||||
isAddingBrainDump: boolean;
|
||||
setIsAddingBrainDump: (value: boolean) => void;
|
||||
@ -23,70 +28,43 @@ const BrainDumpContext = createContext<IBrainDumpContext | undefined>(
|
||||
export const BrainDumpProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
const { data: brainDumps } = useGetNotes();
|
||||
const { mutate: deleteNote } = useDeleteNote();
|
||||
const { mutateAsync: createBrainDump } = useCreateNote();
|
||||
const { mutateAsync: updateNoteMutate } = useUpdateNote();
|
||||
|
||||
const [isAddingBrainDump, setIsAddingBrainDump] = useState<boolean>(false);
|
||||
const [brainDumps, setBrainDumps] = useState<IBrainDump[]>([
|
||||
{
|
||||
id: 0,
|
||||
title: "Favorite Weekend Activities",
|
||||
description:
|
||||
"What's something fun we can do together this weekend? Maybe a new game, a picnic?",
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
title: "What’s For Dinner",
|
||||
description:
|
||||
"What’s one meal you’d love to have for dinner this week?",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: "The Best Thing About Today",
|
||||
description:
|
||||
"What was the highlight of your day? Let’s each take a moment to share something!",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: "A Dream Vacation Spot",
|
||||
description:
|
||||
"If we could go anywhere in the world right now, where would it be? Everyone pick one dream destination and tell us why.",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: "Favorite Childhood Memory",
|
||||
description:
|
||||
"What’s a favorite memory from your childhood? Let’s take a trip down memory lane and share some of the moments that made us smile.",
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: "A New Family Tradition",
|
||||
description:
|
||||
"What’s one new tradition we could start as a family? Maybe a weekly movie night, a monthly game day, or a yearly family trip. Share your ideas!",
|
||||
},
|
||||
]);
|
||||
|
||||
const addBrainDump = (BrainDump: IBrainDump) => {
|
||||
setBrainDumps((prevBrainDumps) => [
|
||||
...prevBrainDumps,
|
||||
{
|
||||
...BrainDump,
|
||||
id: prevBrainDumps.length
|
||||
? prevBrainDumps[prevBrainDumps.length - 1].id + 1
|
||||
: 0,
|
||||
},
|
||||
]);
|
||||
createBrainDump(BrainDump);
|
||||
};
|
||||
|
||||
const updateBrainDumpItem = (id: number, changes: Partial<IBrainDump>) => {
|
||||
setBrainDumps((prevBrainDumps) =>
|
||||
prevBrainDumps.map((BrainDump) =>
|
||||
BrainDump.id === id ? { ...BrainDump, ...changes } : BrainDump
|
||||
)
|
||||
updateNoteMutate(
|
||||
{
|
||||
id: id,
|
||||
changes: changes,
|
||||
},
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
console.log("Note updated successfully", data);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Failed to update note:", error);
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const deleteBrainDump = (id: number) => {
|
||||
setBrainDumps((prevBrainDumps) =>
|
||||
prevBrainDumps.filter((BrainDump) => BrainDump.id !== id)
|
||||
);
|
||||
deleteNote(id.toString(), {
|
||||
onSuccess: () => {
|
||||
console.log("Feedback deleted successfully");
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Failed to delete feedback:", error);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
@ -97,7 +75,7 @@ export const BrainDumpProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
isAddingBrainDump,
|
||||
setIsAddingBrainDump,
|
||||
addBrainDump,
|
||||
deleteBrainDump
|
||||
deleteBrainDump,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
87
contexts/FeedbackContext.tsx
Normal file
87
contexts/FeedbackContext.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
import { useCreateFeedback } from "@/hooks/firebase/useCreateFeedback";
|
||||
import { useDeleteFeedback } from "@/hooks/firebase/useDeleteFeedback";
|
||||
import { useGetFeedbacks } from "@/hooks/firebase/useGetFeedbacks";
|
||||
import { useUpdateFeedback } from "@/hooks/firebase/useUpdateFeedback";
|
||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
import { createContext, useContext, useState } from "react";
|
||||
|
||||
export interface IFeedback {
|
||||
id: number;
|
||||
title: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface IFeedbackContext {
|
||||
feedbacks: IFeedback[] | undefined;
|
||||
isAddingFeedback: boolean;
|
||||
setIsAddingFeedback: (value: boolean) => void;
|
||||
addFeedback: (BrainDump: IFeedback) => void;
|
||||
updateFeedback: (id: number, changes: Partial<IFeedback>) => void;
|
||||
deleteFeedback: (id: number) => void;
|
||||
}
|
||||
|
||||
const FeedbackContext = createContext<IFeedbackContext | undefined>(undefined);
|
||||
|
||||
export const FeedbackProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
const {
|
||||
mutateAsync: createFeedback,
|
||||
isLoading: isAdding,
|
||||
isError,
|
||||
} = useCreateFeedback();
|
||||
const { data: feedbacks } = useGetFeedbacks();
|
||||
const { mutate: deleteFeedbackMutate } = useDeleteFeedback();
|
||||
const { mutate: updateFeedbackMutate } = useUpdateFeedback();
|
||||
|
||||
const [isAddingFeedback, setIsAddingFeedback] = useState<boolean>(false);
|
||||
|
||||
const addFeedback = (Feedback: IFeedback) => {
|
||||
createFeedback({ title: Feedback.title, text: Feedback.text });
|
||||
};
|
||||
|
||||
const updateFeedback = (id: number, changes: Partial<IFeedback>) => {
|
||||
updateFeedbackMutate(
|
||||
{
|
||||
id: id,
|
||||
changes: changes,
|
||||
},
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
console.log("Feedback updated successfully", data);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Failed to update feedback:", error);
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const deleteFeedback = (id: number) => {
|
||||
deleteFeedbackMutate(id.toString(), {
|
||||
onSuccess: () => {
|
||||
console.log("Feedback deleted successfully");
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Failed to delete feedback:", error);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<FeedbackContext.Provider
|
||||
value={{
|
||||
feedbacks,
|
||||
isAddingFeedback,
|
||||
setIsAddingFeedback,
|
||||
addFeedback,
|
||||
updateFeedback,
|
||||
deleteFeedback,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</FeedbackContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useFeedbackContext = () => useContext(FeedbackContext)!;
|
||||
Reference in New Issue
Block a user