Skip to content

Commit

Permalink
[FIX] 삭제, 추가 느린 거 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
eunxoo committed Feb 14, 2024
1 parent 34c77e6 commit 4609bfd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="/manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
8 changes: 4 additions & 4 deletions src/pages/recruit/DocumentItemsEditPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const DocumentItemsEditPage = () => {
<S.Title>공통 문항</S.Title>
</S.RowDiv>
<QuestionContainer>
{questions[0].map((question, index) => (
{questions[0]?.map((question, index) => (
<QuestionInput
key={index}
placeholder="문항 질문을 작성해주세요 ..."
Expand All @@ -126,7 +126,7 @@ const DocumentItemsEditPage = () => {
<S.Title>기획 · 디자인 트랙 문항</S.Title>
</S.RowDiv>
<QuestionContainer>
{questions[1].map((question, index) => (
{questions[1]?.map((question, index) => (
<QuestionInput
key={index}
placeholder="문항 질문을 작성해주세요 ..."
Expand All @@ -141,7 +141,7 @@ const DocumentItemsEditPage = () => {
<S.Title>프론트엔드 트랙 문항</S.Title>
</S.RowDiv>
<QuestionContainer>
{questions[2].map((question, index) => (
{questions[2]?.map((question, index) => (
<QuestionInput
key={index}
placeholder="문항 질문을 작성해주세요 ..."
Expand All @@ -156,7 +156,7 @@ const DocumentItemsEditPage = () => {
<S.Title>백엔드 트랙 문항</S.Title>
</S.RowDiv>
<QuestionContainer>
{questions[3].map((question, index) => (
{questions[3]?.map((question, index) => (
<QuestionInput
key={index}
placeholder="문항 질문을 작성해주세요 ..."
Expand Down
29 changes: 16 additions & 13 deletions src/pages/recruit/DocumentItemsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@ const DocumentItemsPage = () => {
fe: "",
be: "",
});
const [updateFlag, setUpdateFlag] = useState(false);

useEffect(() => {
const fetchQuestions = async () => {
try {
const data = await apiModule.fetchQuestions();
setQuestions(data);
} catch (err) {
console.error("error:", err);
}
};
const fetchDataAndUpdateQuestions = async () => {
try {
const data = await apiModule.fetchQuestions();
setUpdateFlag(false);
setQuestions(data);
} catch (err) {
console.error("error:", err);
}
};

fetchQuestions();
}, []);
useEffect(() => {
fetchDataAndUpdateQuestions();
}, [updateFlag]);

const handleChange = (event, track) => {
setInputContents({
Expand All @@ -152,7 +154,6 @@ const DocumentItemsPage = () => {
if (window.confirm("작성한 문항을 추가하시겠습니까?")) {
handleSubmit(track, idx);
alert("문항이 추가되었습니다.");
window.location.reload();
}
};

Expand All @@ -165,6 +166,8 @@ const DocumentItemsPage = () => {
content: inputContents[track],
maxLength: 600,
});
setUpdateFlag(true);
setInputContents({ ...inputContents, [track]: "" });
} catch (error) {
console.error("error", error);
}
Expand All @@ -174,13 +177,13 @@ const DocumentItemsPage = () => {
if (window.confirm("문항을 삭제하시겠습니까?")) {
handleDelete(id);
alert("문항이 삭제되었습니다.");
window.location.reload();
}
};

const handleDelete = async (id) => {
try {
await apiModule.deleteQuestion(id);
setUpdateFlag(true);
} catch (error) {
console.error("error", error);
}
Expand Down

0 comments on commit 4609bfd

Please sign in to comment.