-
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
Feature/sticky player #24
base: develop
Are you sure you want to change the base?
Changes from all commits
5be8326
0864f6a
b0ffbb5
4a6f876
d26d871
17e028c
76b4fed
616c26c
6a596fe
cde00e6
e4ea412
b69d2d5
438a911
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,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')` | ||
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> | ||
) | ||
} |
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, | ||||||
|
@@ -8,7 +9,7 @@ import { | |||||
playerActions, | ||||||
} from 'features/playerSlice' | ||||||
import { useFetchWithStore } from 'hooks/useFetch' | ||||||
import React from 'react' | ||||||
import React from 'react' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
import { useSelector } from 'react-redux' | ||||||
import { renderByFetchState } from 'utils/renderUtils' | ||||||
|
||||||
|
@@ -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; | ||||||
` | ||||||
|
||||||
|
@@ -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}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||||||
</> | ||||||
) | ||||||
} | ||||||
|
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about this?
|
||
} | ||
|
||
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 } | ||
} |
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.
how about this?