Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
deipanema committed Oct 18, 2024
1 parent 422f4f0 commit 7d3b9a1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
20 changes: 17 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
version: 2.1
orbs:
cypress: cypress-io/cypress@3
# "cypress-io/cypress@3" installs the latest published
# version "s.x.y" of the orb. We recommend you then use
# the strict explicit version "cypress-io/[email protected]"
# to lock the version and prevent unexpected CI changes
cypress: cypress-io/[email protected]

jobs:
cypress-run:
executor:
name: cypress/default
node-version: "20.6.0"
steps:
- cypress/install
- cypress/run-tests:
cypress-command: "npx wait-on@latest http://localhost:3000 && npx cypress run"
start-command: "npm run build && npm run start"

workflows:
build:
jobs:
- "cypress/run":
start-command: "npm run start"
- cypress-run
30 changes: 24 additions & 6 deletions src/app/dashboard/components/Todos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import Image from "next/image";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query"; // useQueryClient 추가

import useModal from "@/hook/useModal";
import CreateNewTodo from "@/components/CreateNewTodo";
import { getNotes } from "@/api/noteAPI";
import useTodoStore, { TodoType } from "@/store/todoStore";
import { deleteTodo } from "@/api/todoAPI";
import { TodoType } from "@/store/todoStore";
import { deleteTodo, updateTodo } from "@/api/todoAPI";

import NoteViewer from "./NoteViewer";

Expand Down Expand Up @@ -65,16 +66,33 @@ export default function Todos({ todo, isGoal = false, isInGoalSection = false }:
const { Modal, openModal, closeModal } = useModal();
const [isNoteOpen, setIsNoteOpen] = useState(false);
const [noteContent, setNoteContent] = useState<NoteType>();
const { updateTodo } = useTodoStore();

const toggleTodoStatus = async (updatedTodo: TodoType) => {
const queryClient = useQueryClient();

const updateTodoMutation = useMutation({
mutationFn: (updatedTodo: TodoType) => updateTodo(todo.id, updatedTodo),
onSuccess: () => {
// 할 일 목록 쿼리 무효화
queryClient.invalidateQueries({ queryKey: ["todos", todo.goal.id] });
},
});

const toggleTodoStatus = async () => {
try {
updateTodo(todo.id, updatedTodo);
await updateTodoMutation.mutateAsync({ ...todo, done: !todo.done });
} catch (error) {
console.error("할 일 상태 변경 중 오류 발생:", error);
}
};

// const toggleTodoStatus = async (updatedTodo: TodoType) => {
// try {
// updateTodo(todo.id, updatedTodo);
// } catch (error) {
// console.error("할 일 상태 변경 중 오류 발생:", error);
// }
// };

const fetchNoteContent = async () => {
if (todo.noteId) {
const response = await getNotes(todo.noteId);
Expand Down Expand Up @@ -123,7 +141,7 @@ export default function Todos({ todo, isGoal = false, isInGoalSection = false }:
width={todo.done === true ? 18 : 24}
height={todo.done === true ? 18 : 24}
alt="checkbox-icon"
onClick={() => toggleTodoStatus({ ...todo, done: !todo.done })}
onClick={() => toggleTodoStatus}
/>

<span className={`text-sm ${todo.done ? "line-through" : ""}`}>{todo.title}</span>
Expand Down

0 comments on commit 7d3b9a1

Please sign in to comment.