-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 문제 검색은 무조건 자격증을 선택하여야 함 - 검색 페이지 입장 시 ID = 1인 자격증을 즉시 설정
- Loading branch information
Showing
21 changed files
with
383 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { mainfetch } from "./mainFetch"; | ||
|
||
const handleBookmarkModule = async <T>( | ||
targetProblem: Problem | ProblemViewType | BookMarkProblem | ProblemDetailType, | ||
isProcessing: boolean, | ||
setIsProcessing: React.Dispatch<React.SetStateAction<boolean>>, | ||
callbackArray?: React.Dispatch<React.SetStateAction<T[]>>, | ||
callbackObject?: React.Dispatch<React.SetStateAction<T>> | ||
) => { | ||
if (isProcessing) return; | ||
|
||
setIsProcessing(true); | ||
if (callbackArray) { | ||
callbackArray((problems: any) => { | ||
return problems.map((problem: any) => | ||
problem.problemId === targetProblem.problemId | ||
? { ...problem, isBookmark: !targetProblem.isBookmark } | ||
: problem | ||
); | ||
}); | ||
} else if (callbackObject) { | ||
callbackObject((targetProblem: any) => { | ||
return { ...targetProblem, isBookmark: !targetProblem.isBookmark }; | ||
}); | ||
} | ||
try { | ||
const method = targetProblem.isBookmark ? "DELETE" : "POST"; | ||
const endpoint = "/bookmarks"; | ||
|
||
const res = await mainfetch( | ||
endpoint, | ||
{ | ||
method, | ||
body: { | ||
problemId: targetProblem.problemId, | ||
}, | ||
}, | ||
true | ||
); | ||
|
||
if (!res.ok) { | ||
if (callbackArray) { | ||
callbackArray((problems: any) => { | ||
const handledProblems = problems.map((problem: any) => | ||
problem.problemId === targetProblem.problemId | ||
? { ...problem, isBookmark: targetProblem.isBookmark } | ||
: problem | ||
); | ||
return handledProblems; | ||
}); | ||
} else if (callbackObject) { | ||
callbackObject((targetProblem: any) => { | ||
return { ...targetProblem, isBookmark: targetProblem.isBookmark }; | ||
}); | ||
} | ||
} | ||
} catch (error) { | ||
} finally { | ||
setIsProcessing(false); // 처리 완료 | ||
} | ||
}; | ||
|
||
export default handleBookmarkModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.