Commit 56d0596c authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

아코디언 트랜지션 시간 짧게 변경 및 키 지정 및 answers 없을 때 버그 고침

parent 2b2a0917
...@@ -3,28 +3,18 @@ import { baseImageUrl } from "../apis"; ...@@ -3,28 +3,18 @@ import { baseImageUrl } from "../apis";
import { BasicQuestionType } from "../types"; import { BasicQuestionType } from "../types";
type AccordionProps = { type AccordionProps = {
question: any; question: BasicQuestionType;
}; };
const Accordion = ({ question }: AccordionProps) => { const Accordion = ({ question }: AccordionProps) => {
const [isOpened, setOpened] = useState<boolean>(false); const [isOpened, setOpened] = useState<boolean>(false);
const [height, setHeight] = useState<string>("0px"); const [height, setHeight] = useState<string>("0px");
const contentElement = useRef<HTMLDivElement>(null); const contentElement = useRef<HTMLDivElement>(null);
// useEffect(() => {
// if (question.type === "file") {
// getFiles();
// }
// }, []);
// async function getFiles() {
// try {
// } catch (error) {}
// }
const HandleOpening = () => { const HandleOpening = () => {
setOpened(!isOpened); setOpened(!isOpened);
setHeight(!isOpened ? `${contentElement.current?.scrollHeight}px` : "0px"); setHeight(!isOpened ? `${contentElement.current?.scrollHeight}px` : "0px");
}; };
return ( return (
<div className="p-1"> <div className="p-1">
<div onClick={HandleOpening}> <div onClick={HandleOpening}>
...@@ -39,9 +29,10 @@ const Accordion = ({ question }: AccordionProps) => { ...@@ -39,9 +29,10 @@ const Accordion = ({ question }: AccordionProps) => {
<div <div
ref={contentElement} ref={contentElement}
style={{ height: height }} style={{ height: height }}
className="bg-gray-100 overflow-hidden transition-all duration-700" className="bg-gray-100 overflow-hidden transition-all duration-300"
> >
{question.type === "file" {question.answers &&
(question.type === "file"
? question.answers.map((answer: any) => ( ? question.answers.map((answer: any) => (
<img <img
key={answer.url} key={answer.url}
...@@ -49,9 +40,11 @@ const Accordion = ({ question }: AccordionProps) => { ...@@ -49,9 +40,11 @@ const Accordion = ({ question }: AccordionProps) => {
src={`${baseImageUrl}/${answer.url}`} src={`${baseImageUrl}/${answer.url}`}
/> />
)) ))
: question.answers.map((answer: any) => ( : question.answers.map((answer: any, index: number) => (
<p className="p-4">{answer}</p> <p key={index} className="p-4">
))} {answer}
</p>
)))}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -17,6 +17,7 @@ export const ResultSurvey = () => { ...@@ -17,6 +17,7 @@ export const ResultSurvey = () => {
comment: "", comment: "",
questions: [], questions: [],
}); });
useEffect(() => { useEffect(() => {
getAnswers(); getAnswers();
}, [surveyId]); }, [surveyId]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment