feat(in-141): matches cards redesign #26
Merged
andrey.dekterev
merged 1 commits from in-141-matches-cards into in-142 3 years ago
@ -1,92 +0,0 @@ |
||||
import { useCallback, useMemo } from 'react' |
||||
|
||||
import { format } from 'date-fns' |
||||
|
||||
import { parseDate } from 'helpers/parseDate' |
||||
|
||||
import { WeekDay, Wrapper } from './styled' |
||||
|
||||
export type Props = { |
||||
isInitialDateHidden: boolean, |
||||
matchDates: Array<string>, |
||||
onDateClick: (date: string) => void, |
||||
profileDate: string, |
||||
selectedDate: string, |
||||
} |
||||
|
||||
export const VideoDate = (props: Props) => { |
||||
const { |
||||
isInitialDateHidden, |
||||
matchDates, |
||||
onDateClick, |
||||
profileDate, |
||||
selectedDate, |
||||
} = props |
||||
|
||||
const selectedDateIndex = useMemo(() => ( |
||||
matchDates.findIndex((date) => date === selectedDate) |
||||
), [matchDates, selectedDate]) |
||||
|
||||
const lastDateIndex = matchDates.length - 1 |
||||
|
||||
const initialDateIndex = useMemo(() => ( |
||||
matchDates.findIndex((date) => date === profileDate) |
||||
), [matchDates, profileDate]) |
||||
|
||||
const currentDay = useMemo(() => ( |
||||
matchDates.length && !(isInitialDateHidden && selectedDateIndex === initialDateIndex) |
||||
? matchDates[selectedDateIndex] |
||||
: null |
||||
), [initialDateIndex, isInitialDateHidden, matchDates, selectedDateIndex]) |
||||
|
||||
const previousDay = useMemo(() => { |
||||
if (selectedDateIndex !== 0) { |
||||
if (isInitialDateHidden && selectedDateIndex - 1 === initialDateIndex) { |
||||
return selectedDateIndex - 1 !== lastDateIndex ? matchDates[selectedDateIndex - 2] : null |
||||
} |
||||
return matchDates[selectedDateIndex - 1] |
||||
} |
||||
return null |
||||
}, [initialDateIndex, isInitialDateHidden, lastDateIndex, matchDates, selectedDateIndex]) |
||||
|
||||
const nextDay = useMemo(() => { |
||||
if (selectedDateIndex !== lastDateIndex) { |
||||
if (isInitialDateHidden && selectedDateIndex + 1 === initialDateIndex) { |
||||
return selectedDateIndex + 1 !== lastDateIndex ? matchDates[selectedDateIndex + 2] : null |
||||
} |
||||
return matchDates[selectedDateIndex + 1] |
||||
} |
||||
return null |
||||
}, [initialDateIndex, isInitialDateHidden, lastDateIndex, matchDates, selectedDateIndex]) |
||||
|
||||
const onDayClick = (date: string) => { |
||||
onDateClick?.(date) |
||||
} |
||||
|
||||
const formatDate = useCallback((date: string) => ( |
||||
format(parseDate(date, 'yyyy-MM-dd'), 'MMM dd, EE') |
||||
), []) |
||||
|
||||
return ( |
||||
<Wrapper> |
||||
{previousDay && ( |
||||
<WeekDay |
||||
onClick={() => onDayClick(previousDay)} |
||||
>{formatDate(previousDay)} |
||||
</WeekDay> |
||||
)} |
||||
{currentDay && ( |
||||
<WeekDay |
||||
isActive |
||||
>{formatDate(currentDay)} |
||||
</WeekDay> |
||||
)} |
||||
{nextDay && ( |
||||
<WeekDay |
||||
onClick={() => onDayClick(nextDay)} |
||||
>{formatDate(nextDay)} |
||||
</WeekDay> |
||||
)} |
||||
</Wrapper> |
||||
) |
||||
} |
||||
@ -1,52 +0,0 @@ |
||||
import styled, { css } from 'styled-components/macro' |
||||
|
||||
import { isMobileDevice } from 'config/userAgent' |
||||
|
||||
export const Wrapper = styled.div` |
||||
color: #FFFFFF; |
||||
display: flex; |
||||
justify-content: center; |
||||
align-items: center; |
||||
margin-bottom: 10px; |
||||
|
||||
> :not(:last-child) { |
||||
margin-right: 20px; |
||||
} |
||||
|
||||
${isMobileDevice ? css` |
||||
@media screen and (orientation: landscape){
|
||||
> :not(:last-child) { |
||||
margin-right: 3px; |
||||
} |
||||
} |
||||
` : ''}
|
||||
` |
||||
|
||||
export const WeekDay = styled.div.attrs(() => ({ |
||||
'aria-hidden': true, |
||||
}))<{isActive?: boolean}>` |
||||
position: relative; |
||||
color: rgba(255, 255, 255, 0.5); |
||||
font-size: 12px; |
||||
white-space: nowrap; |
||||
padding: 5px; |
||||
cursor: pointer; |
||||
|
||||
${({ isActive }) => ( |
||||
isActive |
||||
? css` |
||||
color: #FFFFFF; |
||||
cursor: default; |
||||
|
||||
:after { |
||||
position: absolute; |
||||
bottom: 0; |
||||
left: 0; |
||||
content: ''; |
||||
width: 100%; |
||||
height: 2px; |
||||
background-color: #FFFFFF; |
||||
} |
||||
` |
||||
: '')} |
||||
` |
||||
Loading…
Reference in new issue