Skip to content

Commit

Permalink
FIX :: 치명적인 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm8109jsm committed Sep 6, 2023
1 parent c8eec00 commit 902b907
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
6 changes: 3 additions & 3 deletions components/Board/BoardSection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useCallback } from "react";
import * as S from "./style";
import { AiFillFire } from "react-icons/ai";
import BoardItem from "../BoardItem";
Expand All @@ -15,9 +15,9 @@ function BoardSection({ isYellow }: { isYellow?: true }) {
const getTrendingFunc = getTrendingBoardQuery();
const getRecommendFunc = getRecommendBoardQuery();

const lengthCheckedArray = (array: BoardType[]) => {
const lengthCheckedArray = useCallback((array: BoardType[]) => {
return array.length >= 4 ? array.slice(0, 4) : array;
};
}, []);

if (getRecommendFunc.isLoading || getTrendingFunc.isLoading) {
setIsLoading(true);
Expand Down
17 changes: 10 additions & 7 deletions components/Chat/ChatInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import * as S from "./style";
import { useRouter } from "next/router";
import { useRecoilState } from "recoil";
Expand Down Expand Up @@ -63,12 +63,15 @@ function ChatInput() {
const ingredientListMutation = getIngredientListMutation(materialInput);
const seasoningListMutation = getSeasoningListMutation(materialInput);

const search = (e: React.ChangeEvent<HTMLInputElement>) => {
setMaterialInput(e.target.value);
materialStatus === "INGREDIENT"
? ingredientListMutation.mutate()
: seasoningListMutation.mutate();
};
const search = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
setMaterialInput(e.target.value);
materialStatus === "INGREDIENT"
? ingredientListMutation.mutate()
: seasoningListMutation.mutate();
},
[materialInput],
);

return (
<S.ChatInput>
Expand Down
6 changes: 5 additions & 1 deletion utils/apis/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export const getLoginQuery = (code: string, router: NextRouter) => {
const setIsNeedLogin = useSetRecoilState(isNeedLoginState);
return useQuery("login", () => getLogin(code), {
enabled: router.isReady,
onSuccess: () => {
onSuccess: (data) => {
setIsNeedLogin(false);
const { accessToken, refreshToken } = data;
localStorage.setItem("accessToken", accessToken);
localStorage.setItem("refreshToken", refreshToken);
window.history.go(-2);
},
});
};
Expand Down
9 changes: 8 additions & 1 deletion utils/apis/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { getAccessToken } from "@/functions/getAccessToken";
import { instance } from "../instance";
import { useMutation, useQuery } from "react-query";
import { NextRouter, useRouter } from "next/router";
import { useSetRecoilState } from "recoil";
import { useRecoilState, useSetRecoilState } from "recoil";
import { isLoadingState } from "@/atoms/Etc/isLoading";
import { MaterialType, RecipeQuestionType } from "@/types/Chat/ChatList";
import { SelectedRecipeState } from "@/atoms/Chat/SelectedRecipe";
import { updateChatRoomMutation } from "./chat";
import { toast } from "react-toastify";
import { AxiosError } from "axios";
import { MaterialListState } from "@/atoms/Chat/MaterialList";

export const getRecommend = async (
materials: {
Expand All @@ -29,11 +30,17 @@ export const getRecommendMutation = (
},
id: string,
) => {
const [materialList, setMaterialList] = useRecoilState(MaterialListState);
const router = useRouter();
const setIsLoading = useSetRecoilState(isLoadingState);
return useMutation(() => getRecommend(materials, id), {
onSettled: () => {
setIsLoading(false);
router.reload();
setMaterialList({
INGREDIENT: [],
SEASONING: [],
});
},
});
};
Expand Down

0 comments on commit 902b907

Please sign in to comment.