-
Notifications
You must be signed in to change notification settings - Fork 3
FeedbackArea 컴포넌트 구현 #16
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
The head ref may contain hidden characters: "12-fe-feedbackarea-\uCEF4\uD3EC\uB10C\uD2B8-\uAD6C\uD604"
Changes from 8 commits
d4f0fc0
e5f97f4
27e8628
eff80da
8d80d59
9a19f98
879dccb
4993d93
4bd6eec
e9674c7
aca5b7c
b976991
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { css } from '@emotion/react'; | ||
| import React, { Children, ReactNode, isValidElement } from 'react'; | ||
|
|
||
| const FVAScrollViewStyle = css` | ||
| width: 100%; | ||
| height: 200px; | ||
| background-color: red; | ||
| overflow-y: scroll; | ||
| `; | ||
|
|
||
| const FBAScrollView = ({ children }: { children?: ReactNode }) => { | ||
| return <div css={FVAScrollViewStyle}>{children}</div>; | ||
| }; | ||
|
|
||
| const FBAScrollViewType = (<FBAScrollView />).type; | ||
|
|
||
| const getFBAScrollView = (childArr: ReactNode[]) => { | ||
| return childArr.filter((child) => isValidElement(child) && child.type === FBAScrollViewType); | ||
| }; | ||
|
|
||
| const FBATextArea = () => { | ||
| return <textarea></textarea>; | ||
| }; | ||
| const FBATextAreaType = (<FBATextArea />).type; | ||
| const getFBATextArea = (childArr: ReactNode[]) => { | ||
| return childArr.filter((child) => isValidElement(child) && child.type === FBATextAreaType); | ||
| }; | ||
|
|
||
| const FBAMain = ({ children }: { children: ReactNode }) => { | ||
| const childArr = Children.toArray(children); | ||
|
|
||
| const FBAScrollView = getFBAScrollView(childArr); | ||
| const FBATextArea = getFBATextArea(childArr); | ||
|
|
||
| return ( | ||
| <div> | ||
| {FBAScrollView} | ||
| {FBATextArea} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const FeedbackArea = Object.assign(FBAMain, { | ||
| FBAScrollView, | ||
| FBATextArea, | ||
| }); | ||
|
|
||
| export default FeedbackArea; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import React, { useState, useEffect, useRef } from 'react'; | ||
| import { FeedbackBox } from '@components/@shared/FeedbackBox/FeedbackBox'; | ||
| import FeedbackArea from '@components/FeedbackArea/FeedbackArea'; | ||
| import { useRecoilState } from 'recoil'; | ||
| import { currentTimeState } from '@store/feedbackStore'; | ||
|
|
||
| const Feedback = () => { | ||
| const dummyFeedback = [ | ||
| { id: 0, content: '테스트 피드백1', startTime: 3, endTime: 4 }, | ||
| { id: 1, content: '테스트 피드백2', startTime: 6, endTime: 9 }, | ||
| { id: 2, content: '테스트 피드백3', startTime: 10, endTime: 15 }, | ||
| { id: 3, content: '테스트 피드백4', startTime: 16, endTime: 20 }, | ||
| { id: 4, content: '테스트 피드백5', startTime: 23, endTime: 30 }, | ||
| { id: 5, content: '테스트 피드백6', startTime: 31, endTime: 33 }, | ||
| { id: 6, content: '테스트 피드백7', startTime: 34, endTime: 40 }, | ||
| { id: 7, content: '테스트 피드백8', startTime: 45, endTime: 50 }, | ||
| { id: 8, content: '테스트 피드백9', startTime: 51, endTime: 53 }, | ||
| { id: 9, content: '테스트 피드백10', startTime: 56, endTime: 57 }, | ||
| ]; | ||
bh2980 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // const [currentTime, setCurrentTime] = useRecoilState(currentTimeState); | ||
| const currentTime = 16; | ||
| const [focusIndex, setFocusIndex] = useState(0); | ||
|
|
||
| const feedbackRef = useRef([]); | ||
|
|
||
| const findCurrentFeedback = () => { | ||
| let start = 0; | ||
| let end = dummyFeedback.length - 1; | ||
| let mid; | ||
|
|
||
| while (start <= end) { | ||
| mid = Math.floor((start + end) / 2); | ||
|
|
||
| if (currentTime === dummyFeedback[mid].startTime) { | ||
| return mid; | ||
| } else { | ||
| if (currentTime < dummyFeedback[mid].startTime) { | ||
| end = mid - 1; | ||
| } else { | ||
| start = mid + 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return start <= 0 ? 0 : start - 1; | ||
| }; | ||
bh2980 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| useEffect(() => { | ||
| const nearestIndex = findCurrentFeedback(); | ||
| console.log(nearestIndex, dummyFeedback[nearestIndex].startTime); | ||
| if (nearestIndex !== focusIndex) setFocusIndex(nearestIndex); | ||
| }, [currentTime]); | ||
|
|
||
| useEffect(() => { | ||
| feedbackRef.current[focusIndex].scrollIntoView({ behavior: 'smooth', block: 'start' }); | ||
| }, [focusIndex]); | ||
|
|
||
| const onClickFeedback = (e) => { | ||
| e.target.scrollIntoView({ behavior: 'smooth', block: 'start' }); | ||
| }; | ||
|
|
||
| return ( | ||
| <FeedbackArea> | ||
| <FeedbackArea.FBAScrollView> | ||
| {dummyFeedback.map((feedback, idx) => ( | ||
| <FeedbackBox | ||
| key={feedback.id} | ||
| handleClick={onClickFeedback} | ||
|
||
| ref={(elem) => (feedbackRef.current[idx] = elem)} | ||
| > | ||
| <FeedbackBox.StartTime>{feedback.startTime}</FeedbackBox.StartTime> | ||
| <FeedbackBox.Content>{feedback.content}</FeedbackBox.Content> | ||
| </FeedbackBox> | ||
| ))} | ||
| </FeedbackArea.FBAScrollView> | ||
| <FeedbackArea.FBATextArea></FeedbackArea.FBATextArea> | ||
| </FeedbackArea> | ||
| ); | ||
| }; | ||
|
|
||
| export default Feedback; | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.