Skip to content
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

Feature/sticky player #24

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
54 changes: 54 additions & 0 deletions __tests__/mockData/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,60 @@ export const playerCommentsMockData: MockDataType = {
],
time: 7,
},
{
id: 'test4',
kind: COMMENT_TYPE.ACTION_DIRECTOR,
contents: [
'방황하였으며, 우리의 얼마나 심장은 불어 청춘의 이상의 투명하되 것이다. 가슴이 따뜻한 작고 힘있다. 얼음이 무엇을 천고에 쓸쓸하랴? 같으며,설레는 거친 새 장식하는 희망의 얼음과 것 같으며, 설레는 거친 새장식하는 희망의 얼음과 것 같으며, 설레는 거친 새 장식하는 희망의',
'가슴이 따뜻한 작고 힘있다.',
],
time: 9,
},
{
id: 'test5',
kind: COMMENT_TYPE.ACTION_DIRECTOR,
contents: [
'방황하였으며, 우리의 얼마나 심장은 불어 청춘의 이상의 투명하되 것이다. 가슴이 따뜻한 작고 힘있다. 얼음이 무엇을 천고에 쓸쓸하랴? 같으며,설레는 거친 새 장식하는 희망의 얼음과 것 같으며, 설레는 거친 새장식하는 희망의 얼음과 것 같으며, 설레는 거친 새 장식하는 희망의',
'가슴이 따뜻한 작고 힘있다.',
],
time: 11,
},
{
id: 'test6',
kind: COMMENT_TYPE.ACTION_DIRECTOR,
contents: [
'방황하였으며, 우리의 얼마나 심장은 불어 청춘의 이상의 투명하되 것이다. 가슴이 따뜻한 작고 힘있다. 얼음이 무엇을 천고에 쓸쓸하랴? 같으며,설레는 거친 새 장식하는 희망의 얼음과 것 같으며, 설레는 거친 새장식하는 희망의 얼음과 것 같으며, 설레는 거친 새 장식하는 희망의',
'가슴이 따뜻한 작고 힘있다.',
],
time: 12,
},
{
id: 'test7',
kind: COMMENT_TYPE.ACTION_DIRECTOR,
contents: [
'방황하였으며, 우리의 얼마나 심장은 불어 청춘의 이상의 투명하되 것이다. 가슴이 따뜻한 작고 힘있다. 얼음이 무엇을 천고에 쓸쓸하랴? 같으며,설레는 거친 새 장식하는 희망의 얼음과 것 같으며, 설레는 거친 새장식하는 희망의 얼음과 것 같으며, 설레는 거친 새 장식하는 희망의',
'가슴이 따뜻한 작고 힘있다.',
],
time: 13,
},
{
id: 'test8',
kind: COMMENT_TYPE.ACTION_DIRECTOR,
contents: [
'방황하였으며, 우리의 얼마나 심장은 불어 청춘의 이상의 투명하되 것이다. 가슴이 따뜻한 작고 힘있다. 얼음이 무엇을 천고에 쓸쓸하랴? 같으며,설레는 거친 새 장식하는 희망의 얼음과 것 같으며, 설레는 거친 새장식하는 희망의 얼음과 것 같으며, 설레는 거친 새 장식하는 희망의',
'가슴이 따뜻한 작고 힘있다.',
],
time: 14,
},
{
id: 'test9',
kind: COMMENT_TYPE.ACTION_DIRECTOR,
contents: [
'방황하였으며, 우리의 얼마나 심장은 불어 청춘의 이상의 투명하되 것이다. 가슴이 따뜻한 작고 힘있다. 얼음이 무엇을 천고에 쓸쓸하랴? 같으며,설레는 거친 새 장식하는 희망의 얼음과 것 같으며, 설레는 거친 새장식하는 희망의 얼음과 것 같으며, 설레는 거친 새 장식하는 희망의',
'가슴이 따뜻한 작고 힘있다.',
],
time: 15,
},
],
},
}
43 changes: 43 additions & 0 deletions components/common/HideWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { keyframes } from '@emotion/core'
import styled from '@emotion/styled'
import { useWheel } from 'hooks/useWheel'
import React from 'react'

const hide = keyframes`
0% {
max-height: 500px;
}

100% {
max-height: 0;
}
`

const show = keyframes`
0% {
max-height: 0;
}

100% {
max-height: 500px;
}
`

const Container = styled<'div', {isVisible: boolean}>('div')`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about this?

Suggested change
const Container = styled<'div', {isVisible: boolean}>('div')`
const Container = styled.div<{ isVisible: boolean }>`

animation: ${({ isVisible }) => isVisible ? show : hide} 0.7s ease-in-out forwards 1;
overflow: hidden;
`

interface Props {
children: React.ReactNode;
}

export const HideWrapper = ({ children }: Props) => {
const { isVisible } = useWheel()

return (
<Container isVisible={isVisible}>
{ children }
</Container>
)
}
27 changes: 15 additions & 12 deletions components/player/PlayerButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from '@emotion/styled'
import { FlexWrapper } from 'components/common/FlexWrapper'
import { HideWrapper } from 'components/common/HideWrapper'
import { RootState } from 'features'
import { playerActions, playerSelectors, PlayerTime } from 'features/playerSlice'
import React from 'react'
Expand Down Expand Up @@ -39,17 +40,19 @@ export const PlayerButton = () => {
const { toggle, requestUpdateCurrentTime } = playerActions

return (
<FlexWrapper>
<BackwardButton
onClick={() => dispatch(requestUpdateCurrentTime(current-5))}
/>
<PlayButton
isPlaying={isPlaying}
onClick={() => dispatch(toggle()) }
/>
<ForwardButton
onClick={() => dispatch(requestUpdateCurrentTime(current+5))}
/>
</FlexWrapper>
<HideWrapper>
<FlexWrapper>
<BackwardButton
onClick={() => dispatch(requestUpdateCurrentTime(current-5))}
/>
<PlayButton
isPlaying={isPlaying}
onClick={() => dispatch(toggle()) }
/>
<ForwardButton
onClick={() => dispatch(requestUpdateCurrentTime(current+5))}
/>
</FlexWrapper>
</HideWrapper>
)
}
4 changes: 3 additions & 1 deletion components/player/PlayerController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ interface Props {
}

const PlayerTop = styled.div`
position: relative;
position: sticky;
top: 0;
margin-bottom: 16px;
padding: 24px 0;
background: rgba(0, 0, 0, 0.7);
border-radius: 0px 0px 25px 25px;
z-index: 10;
`

const CloseButton = styled.span`
Expand Down
39 changes: 23 additions & 16 deletions components/player/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from '@emotion/styled'
import { FetchStatusCode } from 'api'
import { HideWrapper } from 'components/common/HideWrapper'
import { RootState } from 'features'
import {
Comment,
Expand All @@ -8,7 +9,7 @@ import {
playerActions,
} from 'features/playerSlice'
import { useFetchWithStore } from 'hooks/useFetch'
import React from 'react'
import React from 'react'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import React from 'react'
import React from 'react'

import { useSelector } from 'react-redux'
import { renderByFetchState } from 'utils/renderUtils'

Expand All @@ -17,14 +18,16 @@ import { PlayerController } from './PlayerController'

interface Props {}

const COMMENT_WRAPPER = 'commentWrapper'

const PlayerTitle = styled.h2`
width: 100%;
overflow: hidden;
font-style: normal;
font-weight: bold;
font-size: 20px;
line-height: 29px;
text-align: center;

color: #ffffff;
`

Expand All @@ -45,22 +48,26 @@ export const Player: React.FC<Props> = () => {
return (
<>
<PlayerController>
<PlayerTitle>{title}</PlayerTitle>
<HideWrapper>
<PlayerTitle>{title}</PlayerTitle>
</HideWrapper>
</PlayerController>
{
currentComment.map((comment: Comment) => {
const { kind, contents, time, id } = comment
<div id={COMMENT_WRAPPER}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

{
currentComment.map((comment: Comment) => {
const { kind, contents, time, id } = comment

return (
<Comments
key={id}
kind={kind}
contents={contents}
time={time}
/>
)
})
}
return (
<Comments
key={id}
kind={kind}
contents={contents}
time={time}
/>
)
})
}
</div>
</>
)
}
Expand Down
29 changes: 29 additions & 0 deletions hooks/useWheel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useCallback, useEffect, useState } from 'react'

interface Params {
handleWheel: (params?: any) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about this?

WheelEventHandler

}

export const useWheel = () => {
const [isVisible, setIsVisible] = useState(true)
const handleWheel = useCallback(
(e: WheelEvent) => {
if (e.deltaY > 0 && isVisible) {
return setIsVisible(false)
}

if (e.deltaY < 0 && !isVisible) {
return setIsVisible(true)
}
},
[isVisible],
)

useEffect(() => {
window.addEventListener('wheel', handleWheel)

return (() => window.removeEventListener('wheel', handleWheel))
}, [handleWheel])

return { isVisible, setIsVisible }
}