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,19 +29,22 @@ const Accordion = ({ question }: AccordionProps) => { ...@@ -39,19 +29,22 @@ 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.answers.map((answer: any) => ( (question.type === "file"
<img ? question.answers.map((answer: any) => (
key={answer.url} <img
alt="file" key={answer.url}
src={`${baseImageUrl}/${answer.url}`} alt="file"
/> src={`${baseImageUrl}/${answer.url}`}
)) />
: question.answers.map((answer: any) => ( ))
<p className="p-4">{answer}</p> : question.answers.map((answer: any, index: number) => (
))} <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