Compare commits

..

No commits in common. 'test-f' and 'develop' have entirely different histories.

  1. 4
      src/components/Ads/hooks.tsx
  2. 9
      src/features/AuthStore/hooks/useAuth.tsx
  3. 13
      src/features/MatchCard/CardFrontside/hooks.tsx
  4. 71
      src/features/MatchesSlider/index.tsx
  5. 6
      src/features/MatchesTimeline/hooks.tsx
  6. 11
      src/requests/getMatches/getTimelineMatches.tsx

@ -9,9 +9,9 @@ import { isMobileDevice, querieKeys } from 'config'
import { getAds } from 'requests' import { getAds } from 'requests'
import { isMatchPage } from 'helpers/isMatchPage' import { isMatchPage } from 'helpers/isMatchPage'
import { useLang } from 'features/LexicsStore/hooks/useLang'
import { useAuthStore } from 'features/AuthStore' import { useAuthStore } from 'features/AuthStore'
import { useLexicsStore } from 'features/LexicsStore'
import { import {
DeviceType, DeviceType,
PageType, PageType,
@ -31,7 +31,7 @@ export const useAds = ({
tournamentId, tournamentId,
}: Props) => { }: Props) => {
const [ads, setAds] = useRecoilState(adsStore) const [ads, setAds] = useRecoilState(adsStore)
const { lang } = useLexicsStore() const { lang } = useLang()
const { user } = useAuthStore() const { user } = useAuthStore()
useQuery({ useQuery({

@ -111,12 +111,10 @@ export const useAuth = () => {
token && await fetchUserInfo() token && await fetchUserInfo()
return Promise.resolve() return Promise.resolve()
} }
await fetchUserInfo()
return Promise.resolve() return Promise.resolve()
} }
storeUser(loadedUser) storeUser(loadedUser)
await fetchUserInfo()
markUserLoaded() markUserLoaded()
return loadedUser return loadedUser
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@ -169,9 +167,8 @@ export const useAuth = () => {
setPage(history.location.pathname) setPage(history.location.pathname)
userManager.signinRedirectCallback() userManager.signinRedirectCallback()
.then(async (loadedUser) => { .then((loadedUser) => {
storeUser(loadedUser) storeUser(loadedUser)
await fetchUserInfo()
if (refreshToken) writeRefreshToken(refreshToken) if (refreshToken) writeRefreshToken(refreshToken)
@ -300,6 +297,10 @@ export const useAuth = () => {
} catch (error) {} } catch (error) {}
}, [changeLang]) }, [changeLang])
useEffect(() => {
readToken() && fetchUserInfo()
}, [fetchUserInfo, user])
// временно отрубили возможность смотреть матчи вирт. юзерам // временно отрубили возможность смотреть матчи вирт. юзерам
// в связи с переездом бэка // в связи с переездом бэка
useEffect(() => { useEffect(() => {

@ -21,16 +21,11 @@ export const useCardPreview = ({
), [preview, previewURL]) ), [preview, previewURL])
useEffect(() => { useEffect(() => {
const controller = new AbortController()
const { signal } = controller;
(async () => { (async () => {
if (!currentPreviewURL) return if (!currentPreviewURL) return
try { try {
const image = await fetch(String(currentPreviewURL), { const image = await fetch(String(currentPreviewURL))
signal,
})
.then(async (result) => ({ .then(async (result) => ({
blob: await result.blob(), blob: await result.blob(),
status: result.status, status: result.status,
@ -45,10 +40,8 @@ export const useCardPreview = ({
} }
})() })()
return () => { return () => URL.revokeObjectURL(previewImage)
URL.revokeObjectURL(previewImage)
controller.abort()
}
// добавление previewImage в зависимость вызывает бесконечный цикл // добавление previewImage в зависимость вызывает бесконечный цикл
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentPreviewURL]) }, [currentPreviewURL])

@ -37,48 +37,45 @@ export const MatchesSlider = ({ cardSize, matches }: MatchesSliderProps) => {
} = useMatchesSlider(matches) } = useMatchesSlider(matches)
const scrollToMatchByIndex = (index: number) => { const scrollToMatchByIndex = (index: number) => {
if (slidesRef.current) { const match = slidesRef.current!.querySelectorAll('li')[index]
const match = slidesRef.current.querySelectorAll('li')[index] const offsetLeftCount = match.offsetLeft
const offsetLeftCount = match.offsetLeft
const offsetLeft = offsetLeftCount - PADDING_PARENT
const offsetLeft = offsetLeftCount - PADDING_PARENT
setTimeout(() => {
setTimeout(() => { slidesRef.current!.scrollBy({
slidesRef.current?.scrollBy({ // @ts-ignore
// @ts-ignore behavior: 'instant',
behavior: 'instant', left: offsetLeft,
left: offsetLeft, })
}) }, 0)
}, 0)
}
} }
// скролл к лайв матчам или сегодняшней дате // скролл к лайв матчам или сегодняшней дате
useEffect(() => { useEffect(() => {
if (slidesRef.current) { const matchIndexLive = matches.findIndex(({ live }) => live)
const matchIndexLive = matches.findIndex(({ live }) => live) if (matchIndexLive !== -1) {
if (matchIndexLive !== -1) { scrollToMatchByIndex(matchIndexLive)
scrollToMatchByIndex(matchIndexLive) return
return
}
const matchIndex = matches.findIndex((item) => new Date() <= item.date)
if (matchIndex !== -1) {
scrollToMatchByIndex(matchIndex)
return
}
const slidesRefClientWidth = slidesRef.current.clientWidth
const slidesRefScrollWidth = slidesRef.current.scrollWidth
setTimeout(() => {
slidesRef.current?.scrollBy({
// @ts-ignore
behavior: 'instant',
left: slidesRefScrollWidth - slidesRefClientWidth + PADDING_PARENT,
})
}, 0)
} }
const matchIndex = matches.findIndex((item) => new Date() <= item.date)
if (matchIndex !== -1) {
scrollToMatchByIndex(matchIndex)
return
}
const slidesRefClientWidth = slidesRef.current!.clientWidth
const slidesRefScrollWidth = slidesRef.current!.scrollWidth
setTimeout(() => {
slidesRef.current!.scrollBy({
// @ts-ignore
behavior: 'instant',
left: slidesRefScrollWidth - slidesRefClientWidth + PADDING_PARENT,
})
}, 0)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])

@ -54,13 +54,10 @@ export const useTimeline = () => {
), [user]) ), [user])
useEffect(() => { useEffect(() => {
const controller = new AbortController()
const { signal } = controller;
(async () => { (async () => {
setIsTimelineFetching(true) setIsTimelineFetching(true)
try { try {
const timelineFetched = await getTimelineMatches({ signal }) const timelineFetched = await getTimelineMatches()
setTimeline(timelineFetched) setTimeline(timelineFetched)
const convertedMatches = timelineFetched.online_upcoming[0].matches const convertedMatches = timelineFetched.online_upcoming[0].matches
const preparedMatches = prepareMatchesDto(convertedMatches) const preparedMatches = prepareMatchesDto(convertedMatches)
@ -84,7 +81,6 @@ export const useTimeline = () => {
setIsTimelineFetching(false) setIsTimelineFetching(false)
} }
})() })()
return () => controller.abort()
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])

@ -17,15 +17,7 @@ export type MatchesTimeline = {
promo: Array<TimelineTournamentDto>, promo: Array<TimelineTournamentDto>,
} }
type getTimelineMatchesProps = { export const getTimelineMatches = (sportId?: number): Promise<MatchesTimeline> => {
signal?: AbortSignal,
sportId?: number,
}
export const getTimelineMatches = ({
signal,
sportId,
}: getTimelineMatchesProps): Promise<MatchesTimeline> => {
const getTimezoneOffset = () => { const getTimezoneOffset = () => {
const offset = new Date().getTimezoneOffset() const offset = new Date().getTimezoneOffset()
if (offset === 0) return offset if (offset === 0) return offset
@ -44,7 +36,6 @@ export const getTimelineMatches = ({
} }
return callApi({ return callApi({
abortSignal: signal,
config, config,
url: url.href, url: url.href,
}) })

Loading…
Cancel
Save