Skip to content

Commit

Permalink
feat : 중복 문제 등록 불가
Browse files Browse the repository at this point in the history
  • Loading branch information
glowisn committed Dec 7, 2023
1 parent 372c6ed commit 7b6a103
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/src/components/RoomSettingModal/RandomProblem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function RandomProblem({
level: problem.level,
tag: problem.tags.map((tag:Tag) => tag.name),
}));

if (problemList.length + newProblems.length > 4) {
alert('문제는 최대 4개까지만 등록할 수 있습니다.');
return;
Expand Down
12 changes: 10 additions & 2 deletions client/src/components/RoomSettingModal/RoomSettingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,21 @@ export default function RoomSettingModal({
};

const settingComplete = () => {
const numberList = problemList.map((problem)=>problem.boj_problem_id);
const duplicated = numberList.some(
(item) => numberList.indexOf(item) !== numberList.lastIndexOf(item),
);
if (duplicated) {
alert('중복된 문제가 있습니다.');
return;
}
setProblems(problemList);
closeModal();
};

return (
<div
className="bg-bg/80 absolute left-0 top-0 z-50 flex h-full w-full items-center justify-center"
className="absolute left-0 top-0 z-50 flex h-full w-full items-center justify-center bg-bg/80"
style={{ backdropFilter: 'blur(10px)' }}
ref={modalOverlayRef}
onClick={modalOutsideClick}>
Expand All @@ -72,7 +80,7 @@ export default function RoomSettingModal({
</div>

{isRandom ? (
<RandomProblem
<RandomProblem
problemList={problemList}
setProblemList={setProblemList}
/>
Expand Down
1 change: 1 addition & 0 deletions client/src/components/RoomSettingModal/SelectProblem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function SelectProblem({
// response have no tag attribute, leave blank
tag: [],
};

if (problemList.length + 1 > 4) {
alert('문제는 최대 4개까지만 등록할 수 있습니다.');
return;
Expand Down

0 comments on commit 7b6a103

Please sign in to comment.