-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FE] feat: 문제 보여주기 #153
Merged
Merged
[FE] feat: 문제 보여주기 #153
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f75db41
feat: [FE] 퀴즈데이터를 받아오는 함수 구현
d0422 2ec4a58
feat: [FE] 공통 Dark버튼 추가
d0422 ec5d768
feat: [FE] 문제를 모달로 입력받고 보여주는 기능추가
d0422 8cc503b
refactor: [FE] QuizViewSection컴포넌트 파일로 분리
d0422 480f901
feat: [FE] 문제 로드중 로딩 컴포넌트를 보여주도록 처리
d0422 cf1d28e
chore: [FE] 로딩 컴포넌트 개선
d0422 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Request from './Request'; | ||
|
||
export default async function getQuizData(problemURL: string) { | ||
const result = await Request.get(`/cache?url=${problemURL}`); | ||
return result.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
import { useState } from 'react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import useModal from '@/hooks/useModal'; | ||
import LinkInputModal from './modal/LinkInputModal'; | ||
import clickSrc from '@/assets/click.svg'; | ||
import QUERY_KEYS from '@/constants/queryKeys'; | ||
import getQuizData from '@/apis/getQuizData'; | ||
import Button from '../common/Button'; | ||
import ClickToQuizInput from './quizView/ClickToQuizInput'; | ||
import QuizIframe from './quizView/QuizIframe'; | ||
import Loading from './quizView/Loading'; | ||
|
||
export default function QuizViewSection() { | ||
const { show, hide } = useModal(LinkInputModal); | ||
const [url, setURL] = useState(''); | ||
const { show: showLinkInputModal } = useModal(LinkInputModal); | ||
const { data, isLoading } = useQuery({ queryKey: [QUERY_KEYS, url], queryFn: () => getQuizData(url), enabled: !!url }); | ||
|
||
if (url === '' && !data) | ||
return ( | ||
<button | ||
type="button" | ||
className="flex items-center justify-center w-full h-full text-white rounded-lg bg-primary " | ||
onClick={() => showLinkInputModal({ setURL })} | ||
> | ||
<ClickToQuizInput /> | ||
</button> | ||
); | ||
|
||
if (isLoading) return <Loading />; | ||
|
||
return ( | ||
<button | ||
type="button" | ||
className="flex items-center justify-center w-full h-full text-white rounded-lg bg-primary " | ||
onClick={() => show({ hide })} | ||
> | ||
<div className="flex gap-2"> | ||
<img src={clickSrc} width="20px" alt="clickIcon" /> | ||
<div>클릭해서 링크 입력하기</div> | ||
<div className="flex flex-col w-full h-full gap-2 p-4 rounded-lg ovelrflow-hidden bg-primary"> | ||
<div className="flex justify-end w-full"> | ||
<Button.Dark fontSize="0.8rem" onClick={() => showLinkInputModal({ setURL })}> | ||
변경하기 | ||
</Button.Dark> | ||
</div> | ||
</button> | ||
<QuizIframe htmlData={data} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
frontEnd/src/components/room/quizView/ClickToQuizInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import clickSrc from '@/assets/click.svg'; | ||
|
||
export default function ClickToQuizInput() { | ||
return ( | ||
<div className="flex gap-2"> | ||
<img src={clickSrc} width="20px" alt="clickIcon" /> | ||
<div>클릭해서 링크 입력하기</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export default function Loading() { | ||
return ( | ||
<div className="flex flex-col items-center justify-center w-full h-full px-12 border rounded-md shadow mx4-auto bg-primary"> | ||
<div className="flex flex-col justify-center w-full"> | ||
<div className="flex flex-col justify-center gap-8 animate-pulse"> | ||
<div className="h-3 rounded bg-slate-200" /> | ||
<div className="flex-1 py-1 space-y-6"> | ||
<div className="h-3 rounded bg-slate-200" /> | ||
<div className="space-y-3"> | ||
<div className="grid grid-cols-3 gap-4"> | ||
<div className="h-3 col-span-2 rounded bg-slate-200" /> | ||
<div className="h-3 col-span-1 rounded bg-slate-200" /> | ||
</div> | ||
<div className="h-3 rounded bg-slate-200" /> | ||
<div className="h-3 rounded bg-slate-200" /> | ||
</div> | ||
<div className="h-3 rounded bg-slate-200" /> | ||
<div className="grid grid-cols-3 gap-4"> | ||
<div className="h-3 col-span-1 rounded bg-slate-200" /> | ||
<div className="h-3 col-span-2 rounded bg-slate-200" /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
const overFlowXHidden = (document: Document) => { | ||
document.body.style.overflowX = 'hidden'; | ||
}; | ||
|
||
const clickDisable = (document: Document) => { | ||
document.body.addEventListener( | ||
'click', | ||
(e) => { | ||
e.preventDefault(); | ||
}, | ||
true, | ||
); | ||
}; | ||
|
||
export default function QuizIframe({ htmlData }: { htmlData?: string }) { | ||
const iframeRef = useRef<HTMLIFrameElement>(null); | ||
useEffect(() => { | ||
const iframe = iframeRef.current; | ||
const handleLoad = () => { | ||
const innerDocument = iframe?.contentDocument; | ||
if (innerDocument) { | ||
overFlowXHidden(innerDocument); | ||
clickDisable(innerDocument); | ||
} | ||
}; | ||
if (iframe && htmlData) { | ||
iframe.srcdoc = htmlData; | ||
iframe.onload = handleLoad; | ||
} | ||
}, [htmlData]); | ||
|
||
return ( | ||
<div className="w-full h-[90%]"> | ||
<iframe ref={iframeRef} title="quiz" className="flex items-center justify-center w-full h-full overflow-hidden text-white" /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const QUERY_KEYS = { | ||
LOAD_CODES: 'codes', | ||
QUIZ: 'quiz', | ||
}; | ||
export default QUERY_KEYS; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 컴포넌트와 동일하게 Props를 interface로 정의하는것은 어떨까요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모달 컴포넌트의 경우 useModal의 Props type때문에 타입 정의를 명확하게 할 수가 없네요 ㅠㅠ