fix(repeat method): fix repeat method

test-f
Rakov 2 years ago
parent 8896df9f1f
commit b83bf3c73d
  1. 4
      src/components/Ads/hooks.tsx
  2. 9
      src/features/AuthStore/hooks/useAuth.tsx
  3. 13
      src/features/MatchCard/CardFrontside/hooks.tsx
  4. 15
      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 { isMatchPage } from 'helpers/isMatchPage'
import { useLang } from 'features/LexicsStore/hooks/useLang'
import { useAuthStore } from 'features/AuthStore'
import { useLexicsStore } from 'features/LexicsStore'
import {
DeviceType,
PageType,
@ -31,7 +31,7 @@ export const useAds = ({
tournamentId,
}: Props) => {
const [ads, setAds] = useRecoilState(adsStore)
const { lang } = useLang()
const { lang } = useLexicsStore()
const { user } = useAuthStore()
useQuery({

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

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

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

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

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

Loading…
Cancel
Save