|
|
|
|
@ -8,15 +8,19 @@ import { format } from 'date-fns' |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
@ -24,23 +28,37 @@ export const VideoDate = (props: Props) => { |
|
|
|
|
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 ? matchDates[selectedDateIndex] : null |
|
|
|
|
), [matchDates, selectedDateIndex]) |
|
|
|
|
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 |
|
|
|
|
}, [matchDates, selectedDateIndex]) |
|
|
|
|
}, [initialDateIndex, isInitialDateHidden, lastDateIndex, matchDates, selectedDateIndex]) |
|
|
|
|
|
|
|
|
|
const nextDay = useMemo(() => { |
|
|
|
|
if (selectedDateIndex !== matchDates.length - 1) { |
|
|
|
|
if (selectedDateIndex !== lastDateIndex) { |
|
|
|
|
if (isInitialDateHidden && selectedDateIndex + 1 === initialDateIndex) { |
|
|
|
|
return selectedDateIndex + 1 !== lastDateIndex ? matchDates[selectedDateIndex + 2] : null |
|
|
|
|
} |
|
|
|
|
return matchDates[selectedDateIndex + 1] |
|
|
|
|
} |
|
|
|
|
return null |
|
|
|
|
}, [matchDates, selectedDateIndex]) |
|
|
|
|
}, [initialDateIndex, isInitialDateHidden, lastDateIndex, matchDates, selectedDateIndex]) |
|
|
|
|
|
|
|
|
|
const onDayClick = (date: string) => { |
|
|
|
|
onDateClick?.(date) |