Ott 763 match time in users tz (#282)

* refactor(768): simplified match dates

* refactor(768): show match date on not available matches too

* fix(768): added cleanup arg to useQueryParamHook
keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 5 years ago committed by GitHub
parent dd87080d1b
commit fa86dc6602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/features/Common/Image/index.tsx
  2. 3
      src/features/HeaderFilters/store/hooks/index.tsx
  3. 7
      src/features/HomePage/hooks.tsx
  4. 32
      src/features/MatchCard/CardFrontside/index.tsx
  5. 47
      src/features/Matches/helpers/prepareMatches.tsx
  6. 7
      src/hooks/useStorage/index.tsx

@ -38,7 +38,7 @@ export const Image = ({
data-src={dataSrc} data-src={dataSrc}
className={className} className={className}
onError={onError} onError={onError}
onLoad={() => onLoad?.()} onLoad={onLoad}
title={title} title={title}
/> />
) )

@ -29,6 +29,7 @@ const dateFormat = 'dd/MM/yyyy HH:mm:ss'
export const useFilters = () => { export const useFilters = () => {
const { search } = useLocation() const { search } = useLocation()
const [selectedDate, setSelectedDate] = useQueryParamStore({ const [selectedDate, setSelectedDate] = useQueryParamStore({
clearOnUnmount: true,
defaultValue: new Date(), defaultValue: new Date(),
key: filterKeys.DATE, key: filterKeys.DATE,
validator: isValidDate, validator: isValidDate,
@ -38,6 +39,7 @@ export const useFilters = () => {
selectedMatchStatus, selectedMatchStatus,
setMatchStatus, setMatchStatus,
] = useQueryParamStore<MatchStatuses | null>({ ] = useQueryParamStore<MatchStatuses | null>({
clearOnUnmount: true,
defaultValue: null, defaultValue: null,
key: filterKeys.MATCH_STATUS, key: filterKeys.MATCH_STATUS,
validator: isValidMatchStatus, validator: isValidMatchStatus,
@ -58,6 +60,7 @@ export const useFilters = () => {
selectedSportTypeId, selectedSportTypeId,
setSelectedSportTypeId, setSelectedSportTypeId,
] = useQueryParamStore<SportTypes | null>({ ] = useQueryParamStore<SportTypes | null>({
clearOnUnmount: true,
defaultValue: null, defaultValue: null,
key: filterKeys.SPORT_TYPE, key: filterKeys.SPORT_TYPE,
validator: isValidSportType, validator: isValidSportType,

@ -16,9 +16,9 @@ import { useMatchSwitchesStore } from 'features/MatchSwitches'
const matchesFilteredByStatus = (matches : Matches, status : MatchStatuses | null) => { const matchesFilteredByStatus = (matches : Matches, status : MatchStatuses | null) => {
if (!status) return matches if (!status) return matches
const filteredMatches = filter(matches, (match) => { const filteredMatches = filter(matches, (match) => {
const localDate = new Date(`${match.date}+03:00`) const matchDate = new Date(match.date)
const matchIsStarted = isPast(new Date(match.date)) const matchIsStarted = isPast(matchDate)
const difTime = differenceInMinutes(new Date(), localDate) const difTime = differenceInMinutes(new Date(), matchDate)
switch (status) { switch (status) {
case MatchStatuses.Soon: case MatchStatuses.Soon:
@ -32,6 +32,7 @@ const matchesFilteredByStatus = (matches : Matches, status : MatchStatuses | nul
}) })
return filteredMatches return filteredMatches
} }
const setMatches = ( const setMatches = (
matches : MatchesBySection, matches : MatchesBySection,
status : MatchStatuses | null, status : MatchStatuses | null,

@ -1,5 +1,7 @@
import type { KeyboardEvent } from 'react' import type { KeyboardEvent } from 'react'
import getUnixTime from 'date-fns/getUnixTime'
import { ProfileTypes } from 'config' import { ProfileTypes } from 'config'
import type { Match } from 'features/Matches' import type { Match } from 'features/Matches'
@ -7,7 +9,6 @@ import { SportName } from 'features/Common'
import { useMatchSwitchesStore } from 'features/MatchSwitches' import { useMatchSwitchesStore } from 'features/MatchSwitches'
import { useName } from 'features/Name' import { useName } from 'features/Name'
import { getUnixTime } from 'date-fns'
import { NoAccessMessage } from '../NoAccessMessage' import { NoAccessMessage } from '../NoAccessMessage'
import { import {
CardWrapper, CardWrapper,
@ -38,6 +39,7 @@ export const CardFrontside = ({
accessibleBySubscription, accessibleBySubscription,
accessibleInUsersCountry, accessibleInUsersCountry,
date, date,
formattedDate,
hasVideo, hasVideo,
preview, preview,
sportType, sportType,
@ -46,7 +48,6 @@ export const CardFrontside = ({
team2, team2,
time, time,
tournament, tournament,
unformattedDate,
}, },
onClick, onClick,
onKeyPress, onKeyPress,
@ -54,7 +55,7 @@ export const CardFrontside = ({
}: Props) => { }: Props) => {
const tournamentName = useName(tournament) const tournamentName = useName(tournament)
const { isScoreHidden } = useMatchSwitchesStore() const { isScoreHidden } = useMatchSwitchesStore()
const unixTimeOfMatch = getUnixTime(new Date(unformattedDate)) const unixTimeOfMatch = getUnixTime(date)
return ( return (
<CardWrapper <CardWrapper
@ -91,20 +92,17 @@ export const CardFrontside = ({
) )
} }
{!accessibleBySubscription && <BuyMatchButton />} {!accessibleBySubscription && <BuyMatchButton />}
{(accessibleBySubscription && !accessibleInUsersCountry) {(accessibleBySubscription && !accessibleInUsersCountry) && <NoAccessMessage />}
? <NoAccessMessage /> <MatchDate>
: ( {formattedDate}
<MatchDate> {unixTimeOfMatch > getUnixTime(new Date()) && (!hasVideo || !storage)
{date} ? (
{unixTimeOfMatch > getUnixTime(new Date()) && (!hasVideo || !storage) <Time>
? ( {time}
<Time> </Time>
{time} )
</Time> : null}
) </MatchDate>
: null}
</MatchDate>
)}
</PreviewWrapper> </PreviewWrapper>
<Info> <Info>
{showSportName && <SportName sport={sportType} />} {showSportName && <SportName sport={sportType} />}

@ -7,7 +7,7 @@ import { getSportLexic } from 'helpers'
const prepareMatch = ({ const prepareMatch = ({
access, access,
date, date: matchDate,
has_video, has_video,
id, id,
live, live,
@ -18,27 +18,30 @@ const prepareMatch = ({
team1, team1,
team2, team2,
tournament, tournament,
}: Match) => ({ }: Match) => {
accessibleBySubscription: sub, const date = new Date(matchDate)
accessibleInUsersCountry: access, return {
date: format(new Date(date), 'dd.MM.yy'), accessibleBySubscription: sub,
hasVideo: has_video, accessibleInUsersCountry: access,
id, date,
isClickable: (sub && access && ( formattedDate: format(date, 'dd.MM.yy'),
has_video hasVideo: has_video,
|| storage id,
)), isClickable: (sub && access && (
live, has_video
preview, || storage
sportName: getSportLexic(sport), )),
sportType: sport, live,
storage, preview,
team1, sportName: getSportLexic(sport),
team2, sportType: sport,
time: format(new Date(date), 'HH:mm'), storage,
tournament, team1,
unformattedDate: date, team2,
}) time: format(date, 'HH:mm'),
tournament,
}
}
export const prepareMatches = (matches: Array<Match>) => map( export const prepareMatches = (matches: Array<Match>) => map(
matches, matches,

@ -10,6 +10,7 @@ import {
const defaultValidator = () => true const defaultValidator = () => true
type Args<T> = { type Args<T> = {
clearOnUnmount?: boolean,
defaultValue: T, defaultValue: T,
key: string, key: string,
@ -30,6 +31,7 @@ type Args<T> = {
*/ */
const createHook = (storage: Storage) => ( const createHook = (storage: Storage) => (
<T extends any>({ <T extends any>({
clearOnUnmount,
defaultValue, defaultValue,
key, key,
validator = defaultValidator, validator = defaultValidator,
@ -54,6 +56,11 @@ const createHook = (storage: Storage) => (
storage.setItem(key, JSON.stringify(state, dateReplacer)) storage.setItem(key, JSON.stringify(state, dateReplacer))
}, [key, state]) }, [key, state])
useEffect(() => {
if (clearOnUnmount) return () => storage.removeItem(key)
return undefined
}, [key, clearOnUnmount])
return [state, setState] as const return [state, setState] as const
} }
) )

Loading…
Cancel
Save