Skip to content

Commit

Permalink
Merge pull request #89 from Qfeed-Dev/feature/#35
Browse files Browse the repository at this point in the history
[Feat] 질문 선택지 예외처리 및 Next Image 도입
  • Loading branch information
hamo-o authored Sep 28, 2023
2 parents 8abd06f + 9525adc commit b8e2632
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 195 deletions.
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const nextConfig = {
},
compiler: {
styledComponents: true
},
images: {
domains: ["qfeed-s3.s3.ap-northeast-2.amazonaws.com"]
}
};

Expand Down
66 changes: 39 additions & 27 deletions src/app/(padding)/add-question/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import usePersonalQMutation from "src/hooks/questions/usePersonalQMutation";
import NavigationTopBack from "src/components/navigations/NavigationTopBack";
import Photo from "src/components/common/Photo";
import usePhotoMutation from "src/hooks/file/usePhotoMutation";
import ButtonFillXSmall from "src/components/buttons/button-fill-xsmall";
import { validArray } from "src/hooks/common/useCheckValidation";
import InputFill from "src/components/inputs/input-fill";

export default function Page() {
const router = useRouter();
Expand All @@ -25,6 +28,7 @@ export default function Page() {
const [image, setImage] = useState("");
const [question, setQuestion] = useState("");
const [values, setValues] = useState<string[]>([""]);
const [message, setMessage] = useState<boolean>(false);

const handleQuestion = (e: any) => {
setQuestion(e.target.value);
Expand All @@ -36,6 +40,7 @@ export default function Page() {
else newValues.push(values[i]);
}
setValues(newValues);
setMessage(false);
};

const clickAddValue = () => {
Expand All @@ -53,21 +58,26 @@ export default function Page() {
const photo = usePhotoMutation();

const clickUpload = async () => {
const url = file
? await photo.mutateAsync({
appName: "question",
file: file
})
: "";
createPersonalQ.mutate({
Qtype: "personal",
title: question,
choiceList: values,
backgroundImage: url ? url.presignedUrl : url,
isBlind: false
});

router.push(Route.HOME());
const isValid = validArray(values);
if (isValid) {
const url = file
? await photo.mutateAsync({
appName: "question",
file: file
})
: "";
createPersonalQ.mutate({
Qtype: "personal",
title: question,
choiceList: values,
backgroundImage: url ? url.presignedUrl : url,
isBlind: false
});

router.push(Route.HOME());
} else {
setMessage(true);
}
};

return time2 ? (
Expand Down Expand Up @@ -154,18 +164,11 @@ export default function Page() {
<NavigationTopBack
title="질문 올리기"
rightIcon={
<UploadButton onClick={clickUpload}>
<Text
typo="Subtitle1b"
color="light_qblack"
style={{
marginTop: 5,
textAlign: "center"
}}
>
올리기
</Text>
</UploadButton>
<ButtonFillXSmall
text="올리기"
state="default"
onClick={clickUpload}
/>
}
transparent={Boolean(image)}
/>
Expand Down Expand Up @@ -196,6 +199,15 @@ export default function Page() {
/>
);
})}
{message && (
<Text
typo="Caption1r"
color="light_qwhite"
style={{ width: "100%" }}
>
모든 선택지를 입력하세요!
</Text>
)}
{values.length < 6 ? (
<PlusButton onClick={clickAddValue}>
<div style={{ margin: "auto", display: "flex" }}>
Expand Down
1 change: 0 additions & 1 deletion src/components/BottomSheet/children/Friend.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";
import Loading from "src/components/common/Loading";
import Text from "src/components/common/Text";
import Image from "src/components/Image";
import Spacing from "src/components/Spacing";
import Textarea from "src/components/Textarea";
import useFriendQuery from "src/hooks/account/useFriendQuery";
Expand Down
2 changes: 1 addition & 1 deletion src/components/GridWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const QuestionGrid = ({
key={idx}
idx={data.id}
colorIdx={idx + colorStart}
data={data}
feed={data}
detail={detail}
/>
))}
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/common/useCheckValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ export const validBirth = (birthday: string) => {
}
return true;
};

// 배열 유효성 검사
export const validArray = (array: Array<string>) => {
for (const item of array) {
if (!item || item == "") {
return false;
}
}
return true;
};
4 changes: 0 additions & 4 deletions src/pages-edit/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import Flex from "src/components/common/Flex";
import Text from "src/components/common/Text";

import BottomNavigation from "src/components/BottomNavigation";
import Filter from "./components/Filter";
import Spacing from "src/components/Spacing";
import { colors } from "styles/theme";
import { Route } from "src/constants/Route";
import Icon from "src/components/Icon";

import { globalValue } from "src/constants/globalValue";

import { useUserQuery } from "src/hooks/account/useUserQuery";
import { useGetQuestions } from "src/hooks/questions/useGetQuestions";

Expand Down
130 changes: 55 additions & 75 deletions src/pages-edit/home/components/MakeOfficial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,94 +24,74 @@ interface Time {

const MakeOfficial = (props: QuestionProps) => {
const router = useRouter();
const cursor = useQsetCursorQuery();
const QSet = useQsetCursorQuery();
const newQSet = useQsetMutation();

const [endTime, setEndTime] = useState<number | typeof NaN>(NaN);
const [time, setTime] = useState<Time | undefined>(undefined);

const createNewQSet = () => {
if (!cursor.isLoading && cursor.questionCursor) {
const qSetCount = cursor.questionCursor?.length;
if (qSetCount) {
if (cursor.questionCursor[0].isDone) {
setEndTime(Date.parse(cursor.questionCursor[0].endAt));
}
} else {
newQSet.mutate();
}
}
};

const getTime = () => {
const date = new Date();
const times = new Date(
endTime + 24 * 60 * 60 * 1000 + 15 * 60 * 60 * 1000 - +date
);

if (times.getDate() <= 1 || times.getFullYear() < 1970) {
if (!cursor.isLoading && cursor.questionCursor) {
const qSetCount = cursor.questionCursor?.length;
qSetCount < 2 && newQSet.mutate();
setEndTime(NaN);
return;
}
}

const hours = String(times.getHours()).padStart(2, "0");
const minutes = String(times.getMinutes()).padStart(2, "0");
const seconds = String(times.getSeconds()).padStart(2, "0");
setTime({ hour: hours, min: minutes, sec: seconds });
};

useEffect(() => {
if (!isNaN(endTime)) {
const interval = setInterval(getTime, 1000);
return () => clearInterval(interval);
} else {
createNewQSet();
}
}, [endTime, cursor.isLoading]);

return cursor.isLoading ? (
// const [time, setTime] = useState<Time | undefined>(undefined);

// const createNewQSet = async () => {
// const qSetCount = QSet.questionCursor?.length;
// if (
// (qSetCount === 1 &&
// QSet.questionCursor &&
// QSet.questionCursor[0].isDone) ||
// !qSetCount
// ) {
// const nQSet = await newQSet.mutateAsync();
// setEndTime(Date.parse(nQSet.questionCursor[0].endAt));
// }
// };

// const getTime = () => {
// const date = new Date();
// const times = new Date(
// endTime + 24 * 60 * 60 * 1000 + 15 * 60 * 60 * 1000 - +date
// );

// if (times.getDate() <= 1 || times.getFullYear() < 1970) {
// if (!QSet.isLoading && QSet.questionCursor) {
// const qSetCount = QSet.questionCursor?.length;
// qSetCount < 2 && newQSet.mutate();
// setEndTime(NaN);
// return;
// }
// }

// const hours = String(times.getHours()).padStart(2, "0");
// const minutes = String(times.getMinutes()).padStart(2, "0");
// const seconds = String(times.getSeconds()).padStart(2, "0");
// setTime({ hour: hours, min: minutes, sec: seconds });
// };

// useEffect(() => {
// if (!isNaN(endTime)) {
// // const interval = setInterval(getTime, 1000);
// // return () => clearInterval(interval);
// } else {
// if (!QSet.isLoading) createNewQSet();
// }
// }, [endTime, QSet]);

return QSet.isLoading ? (
<Loading />
) : (
<BasicQuestionWrapper
onClick={props.onClick}
color={colors.primary_qgreen}
>
{cursor.questionCursor?.length && (
{QSet.questionCursor?.length && (
<BasicQuestionInner>
{cursor.questionCursor[0].isDone ? (
{QSet.questionCursor[0].isDone ? (
<>
<Text typo="Caption1r" color="light_qblack">
다음 질문까지
</Text>
<Text typo="Headline2b" color="light_qblack">
{/* <Text typo="Headline2b" color="light_qblack">
{time
? `${time.hour}:${time.min}:${time.sec}`
: "00:00:00"}
</Text>
{/* <BottomButton>
<Text
typo="Caption1b"
color="light_qblack"
style={{
padding: "6px 16px",
display: "flex",
borderRadius: 5,
backgroundColor: colors.light_qwhite
}}
>
<span style={{ marginRight: 8 }}>
친구 초대하고 바로 받기
</span>
<Icon
icon="RightArrow"
color="light_qblack"
/>
</Text>
</BottomButton> */}
</Text> */}
<ImageWrapper>
<Icon
icon="AngelImage2"
Expand All @@ -123,12 +103,12 @@ const MakeOfficial = (props: QuestionProps) => {
) : (
<>
<Text typo="Headline2b" color="light_qblack">
{cursor.questionCursor[0].currentQ}
{QSet.questionCursor[0].currentQ}
</Text>
<Text typo="Caption1r" color="light_qblack">
아직{" "}
{cursor.questionCursor[0].QsetLength -
cursor.questionCursor[0].cursor +
아직
{QSet.questionCursor[0].QsetLength -
QSet.questionCursor[0].cursor +
1}
문제 남았어요!
</Text>
Expand Down
Loading

0 comments on commit b8e2632

Please sign in to comment.