Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/api/prompt/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const usePromptHook = () => {
promptCategory,
promptMethod,
listPromptAtom,
aiListPromptAtom,
) => {
await sendRequest(promptInstance, "post", ``, {
promptTitle,
Expand All @@ -274,6 +275,7 @@ export const usePromptHook = () => {
promptCategory,
promptMethod,
listPromptAtom,
aiListPromptAtom,
});
//TODO- ㅡ프롬프트 생성 후에, 프롬프트 리스트를 다시 불러오는 것
// await fetchPromptList();
Expand Down
18 changes: 18 additions & 0 deletions src/components/PromptMaking/CombinationArea/SavePromptModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
promptListState,
blockDetailsState,
userHistoryState,
aiListPromptState,
} from "../../../recoil/prompt/promptRecoilState";
import { useRecoilValue } from "recoil";
import RefinedPromptText from "../FinalPromptArea/RefinedPromptText";
Expand Down Expand Up @@ -36,6 +37,7 @@ const SavePromptModal = ({
const [promptCategory, setPromptCategory] = useState(localPromptCategory);
const promptMethod = useRecoilValue(promptMethodState);
const userHistoryValue = useRecoilValue(userHistoryState);
const aiListPromptValue = useRecoilValue(aiListPromptState);

const { savePrompt, userHistory } = usePromptHook();
const { fetchPromptList, patchPromptBlock, patchPromptInfo } =
Expand Down Expand Up @@ -78,17 +80,32 @@ const SavePromptModal = ({
);
} else {
const promptPreview = Object.values(refinedPromptParts).join(" ");
const aiListPromptBlockIds = Object.values(aiListPromptValue).map(
(item) => item.blockId,
);

const listPromptAtom = Object.values(combinations)
.filter(Boolean)
.filter(
(value) => !aiListPromptBlockIds.includes(Number(value)),
)
.map((value, index) => ({ blockId: value }));

const aiListPromptAtom = Object.values(aiListPromptValue).map(
(item) => {
const { blockId, ...rest } = item;
return rest;
},
);

savePrompt(
promptTitle,
promptDescription,
promptPreview,
promptCategory,
promptMethod,
listPromptAtom,
aiListPromptAtom,
);

userHistory(userHistoryValue, promptMethod, promptCategory);
Expand All @@ -106,6 +123,7 @@ const SavePromptModal = ({
promptCategory,
promptMethod,
listPromptAtom,
aiListPromptAtom,
});
// 여기서 일반적으로 이 데이터를 백엔드로 보내거나 상태 관리 시스템에 저장합니다
}
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/promptHook/usePromptMaking.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
activeCategoryState,
activeAiBlocksState,
userHistoryState,
aiListPromptState,
} from "../../recoil/prompt/promptRecoilState";
import { useEffect } from "react";
import { t } from "i18next";
Expand All @@ -17,6 +18,7 @@ export const usePromptMaking = () => {
const [activeBlocks, setActiveBlocks] = useRecoilState(activeBlocksState);
const [activeAiBlocks, setActiveAiBlocks] =
useRecoilState(activeAiBlocksState);
const [aiListPrompt, setAiListPrompt] = useRecoilState(aiListPromptState);
const [userHistory, setUserHistoryState] = useRecoilState(userHistoryState);
const blockDetails = useRecoilValue(blockDetailsState);
const activeCategory = useRecoilValue(activeCategoryState);
Expand Down Expand Up @@ -207,6 +209,13 @@ export const usePromptMaking = () => {
...prev,
[category]: prev[category].filter((id) => id !== blockId),
}));

setAiListPrompt((prev) => ({
...prev,
[category]: blockDetails[blockId],
}));

console.log("aiList", aiListPrompt);
}

handleCombinationChange({
Expand Down
5 changes: 5 additions & 0 deletions src/recoil/prompt/promptRecoilState.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ export const userHistoryState = atom({
default: "",
});

export const aiListPromptState = atom({
key: "aiListPromptState",
default: {},
});

// // 각종 상태 초기화 함수
// export const useResetCategoriesOnTypeChange = () => {
// return useRecoilCallback(({ snapshot, set }) => async () => {
Expand Down
Loading