Skip to content

Commit

Permalink
feat : organize uploadimage
Browse files Browse the repository at this point in the history
  • Loading branch information
bicco2 committed Aug 3, 2022
1 parent 1cc0d3f commit 270ed79
Showing 1 changed file with 3 additions and 41 deletions.
44 changes: 3 additions & 41 deletions frontend/src/components/mainpage/UploadImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function UploadImage() {
const [urlImg, setUrlImg] = useState("");
const [respondImg, setRespondImg] = useState(null);
const [loading, setLoading] = useState(false);
const [task_id, setTask_id] = useState("");
const [checked, setChecked] = useState(false);

const navigate = useNavigate();
Expand Down Expand Up @@ -92,43 +91,26 @@ function UploadImage() {
}
)
.then((res) => {
setTask_id(res.data.task_id); //set
console.log("uploadimage taskid :::", res.data.task_id);
task_id = res.data.task_id;
setChecked(true);
})
.catch((error) => {
console.log("An error occurred:", error.response);
// navigate(`/errorpage`);
navigate(`/errorpage`);
});
console.log("제발 나와라 좀 ", task_id);

console.log("제대로 set됐는지 먼저 체크하자 ", checked);

//-----------------------------------------------------------------

//-----------------------------------------------------------------
if (task_id !== "") {
const getAnswer = () => {
console.log("두번쨰 api로 들어왔니?ㄴ");
Api.get(`/trash/users/${userIdtoRedux}/results/tasks/${task_id}`, {
headers: {
Authorization: `${what.value}`,
},
})
.then((res) => {
console.log("then 으로 안오나? ");
dispatch(save_ID(res.data.image_id));
console.log(res);
console.log("반복 - 한요한");

// if (res.data.ai_result == "false") {
// clearInterval(timer);
// console.log("204 error");
// //navi헤애힘 error
// }
// if (!res.data.challenge) {
if (res.status === 200) {
//제대로 들어갔을 때
console.log("successsuccesssuccesssuccess");
navigate(`/howtopage`, {
state: {
Expand All @@ -140,22 +122,10 @@ function UploadImage() {
}
})
.catch((error) => {
console.log("An error occurred: 여기는 두번째 api", error);
// 분류 안됐을때
clearInterval(timer);

navigate("/errorpage");
// clearInterval(timer);
});

// var refreshId = setInterval(function() {
// var properID = CheckReload();
// if (properID > 0) {

// clearInterval(refreshId);
// }
// }, 10000);

//if end
};

const timer = setInterval(getAnswer, 2000);
Expand Down Expand Up @@ -183,14 +153,6 @@ function UploadImage() {
</div>
);

// function doSetTimeout(i: any) {
// setTimeout(function () {
// alert(i);
// }, 100);
// }

// for (var i = 1; i <= 2; ++i) doSetTimeout(i);

return (
<Box>
<form>
Expand Down

0 comments on commit 270ed79

Please sign in to comment.