From 11318d3a904afbcd4e420907a967a8aae4129efa Mon Sep 17 00:00:00 2001 From: ehddnr301 Date: Sun, 14 Jul 2024 13:05:08 +0000 Subject: [PATCH] feat(faust): Basic skeleton after keyword selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 키워드 선택 후 플레이 화면으로 넘어가는 부분을 구현하였습니다. #31 --- src/modules/Faust/FaustContainer.tsx | 49 +++++++++++++++++++++ src/modules/Faust/FaustPresenter.tsx | 65 +++++++++++++++++++++++----- 2 files changed, 102 insertions(+), 12 deletions(-) diff --git a/src/modules/Faust/FaustContainer.tsx b/src/modules/Faust/FaustContainer.tsx index 741aa22..087c511 100644 --- a/src/modules/Faust/FaustContainer.tsx +++ b/src/modules/Faust/FaustContainer.tsx @@ -16,9 +16,19 @@ const getKeywordList = () => { ]; }; +const useInput = (initialValue: string) => { + const [value, setValue] = useState(initialValue); + const onChange = (e: React.ChangeEvent) => { + setValue(e.target.value); + }; + return { value, onChange }; +}; + const FaustContainer = () => { const [keywordList, _] = useState(getKeywordList()); const [selectedKeywords, setSelectedKeywords] = useState([]); + const [isClicked, setIsClicked] = useState(false); + const sentenceId = useInput("42"); const handleKeywordClick = (keyword: string) => { setSelectedKeywords((prevSelected) => { @@ -30,12 +40,51 @@ const FaustContainer = () => { return prevSelected; }); }; + const handleSentenceIDChange = ( + event: React.ChangeEvent + ) => { + sentenceId.onChange(event); + }; + const handleRegisterSentence = () => { + try { + const sentences: { [key: string]: string } = { + "42": "삶과 우주, 그리고 모든 것에 대한 답은 42 입니다.", + }; + + if (typeof sentenceId.value !== "string") { + throw new Error("sentenceId.value must be a string"); + } + + if (!sentences.hasOwnProperty(sentenceId.value)) { + throw new Error( + `No sentence found for sentenceId.value: ${sentenceId.value}` + ); + } + + alert(sentences[sentenceId.value]); + } catch (error) { + return `Error: ${(error as any).message}`; + } + }; + + const handleNextButtonClick = () => { + if (selectedKeywords.length === 4) { + setIsClicked(true); + } else { + alert("4개의 키워드를 선택해주세요."); + } + }; return ( ); }; diff --git a/src/modules/Faust/FaustPresenter.tsx b/src/modules/Faust/FaustPresenter.tsx index 032b85b..3cb3239 100644 --- a/src/modules/Faust/FaustPresenter.tsx +++ b/src/modules/Faust/FaustPresenter.tsx @@ -1,5 +1,5 @@ import { styled } from "@mui/material"; -import { Container } from "@mui/material"; +import { Container, Input } from "@mui/material"; const Wrapper = styled(Container)({ width: "60vw", @@ -29,28 +29,69 @@ const Keyword = styled(Container)<{ isSelected: boolean }>((props) => ({ }, })); +const MyButton = styled(Container)({ + marginTop: "1rem", + width: "100%", + height: "3rem", + display: "flex", + justifyContent: "center", + alignItems: "center", + background: "#ffcc33", + borderRadius: "5px", +}); + +const InputContainer = styled(Container)({ + marginTop: "1rem", + display: "flex", + justifyContent: "center", + alignItems: "center", +}); + +const InputBox = styled(Input)({ + marginTop: "5rem", +}); + // Container Props type FaustPresenterProps = { keywordList: string[]; selectedKeywords: string[]; + isClicked: boolean; + sentenceId: string; handleKeywordClick: (keyword: string) => void; + handleNextButtonClick: () => void; + handleSentenceIDChange: (event: React.ChangeEvent) => void; + handleRegisterSentence: () => void; }; const FaustPresenter = (props: FaustPresenterProps) => { return ( <> - - {props.keywordList.map((keyword, index) => ( - props.handleKeywordClick(keyword)} - > - {keyword} - - ))} - + {props.isClicked ? ( + <> + + 등록 + + ) : ( + <> + + {props.keywordList.map((keyword, index) => ( + props.handleKeywordClick(keyword)} + > + {keyword} + + ))} + + 다음 + + )} );