develop #71

Merged
andrey.dekterev merged 3 commits from develop into master 3 years ago
  1. 16
      src/features/AuthStore/hooks/useAuth.tsx
  2. 4
      src/features/HomePage/hooks.tsx
  3. 1
      src/features/HomePage/index.tsx
  4. 10
      src/features/Matches/index.tsx
  5. 2
      src/features/SportsFilter/components/SelectSport/styled.tsx
  6. 6
      src/features/StreamPlayer/index.tsx
  7. 6
      src/features/UserFavorites/hooks/index.tsx
  8. 13
      src/features/UserFavorites/index.tsx
  9. 10
      src/helpers/callApi/logoutIfUnauthorized.tsx
  10. 2
      src/requests/getSound.tsx

@ -89,8 +89,9 @@ export const useAuth = () => {
if (!readToken()) { if (!readToken()) {
const token = await getTemporaryToken() const token = await getTemporaryToken()
token && await fetchUserInfo() token && await fetchUserInfo()
return Promise.resolve()
} }
return Promise.resolve() return Promise.reject()
} }
storeUser(loadedUser) storeUser(loadedUser)
@ -204,20 +205,24 @@ export const useAuth = () => {
}, [reChekNewDevice, userManager]) }, [reChekNewDevice, userManager])
useEffect(() => { useEffect(() => {
if (!needCheckNewDeviсe) return undefined if (!needCheckNewDeviсe && !user) return undefined
const startCheckDevice = setInterval(checkNewDevice, 20000) const startCheckDevice = setInterval(checkNewDevice, 20000)
isNewDeviceLogin && clearInterval(startCheckDevice) isNewDeviceLogin && clearInterval(startCheckDevice)
return () => clearInterval(startCheckDevice) return () => clearInterval(startCheckDevice)
}, [checkNewDevice,
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
checkNewDevice,
isNewDeviceLogin, isNewDeviceLogin,
setIsNewDeviceLogin, setIsNewDeviceLogin,
]) ])
useEffect(() => { useEffect(() => {
// попытаемся обновить токен используя refresh_token
const tryRenewToken = () => { const tryRenewToken = () => {
userManager.signinSilent().catch(logout) userManager.signinSilent()
.catch(() => user && logout())
} }
// попытаемся обновить токен используя refresh_token
// если запросы вернули 401 | 403 // если запросы вернули 401 | 403
window.addEventListener('FORBIDDEN_REQUEST', tryRenewToken) window.addEventListener('FORBIDDEN_REQUEST', tryRenewToken)
@ -227,6 +232,7 @@ export const useAuth = () => {
window.removeEventListener('FORBIDDEN_REQUEST', tryRenewToken) window.removeEventListener('FORBIDDEN_REQUEST', tryRenewToken)
userManager.events.removeAccessTokenExpired(tryRenewToken) userManager.events.removeAccessTokenExpired(tryRenewToken)
} }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [userManager, logout]) }, [userManager, logout])
useEffect(() => { useEffect(() => {

@ -56,7 +56,7 @@ export const useHomePage = () => {
})() })()
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [userInfo]) }, [userInfo?.email])
useEffect(() => { useEffect(() => {
const dateLastOpenSmartBanner = localStorage.getItem('dateLastOpenSmartBanner') const dateLastOpenSmartBanner = localStorage.getItem('dateLastOpenSmartBanner')
@ -75,7 +75,7 @@ export const useHomePage = () => {
timezoneOffset: getTimezoneOffset(selectedDate), timezoneOffset: getTimezoneOffset(selectedDate),
}), }),
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
[selectedDate], [selectedDate, userInfo?.email],
) )
useEffect(() => { useEffect(() => {

@ -47,6 +47,7 @@ const Home = () => {
<UserFavorites /> <UserFavorites />
<Content> <Content>
{isMobileDevice ? null : <HeaderFilters />} {isMobileDevice ? null : <HeaderFilters />}
{/* {userInfo?.email && <Matches fetch={fetchMatches} />} */}
<Matches fetch={fetchMatches} /> <Matches fetch={fetchMatches} />
<ConfirmPopup <ConfirmPopup
isModalOpen={isShowConfirmPopup} isModalOpen={isShowConfirmPopup}

@ -1,4 +1,8 @@
import { Fragment, useMemo } from 'react' import {
Fragment,
useMemo,
memo,
} from 'react'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { InfiniteScroll } from 'features/InfiniteScroll' import { InfiniteScroll } from 'features/InfiniteScroll'
@ -12,7 +16,7 @@ import { Loading } from './styled'
export type { Match } from './hooks' export type { Match } from './hooks'
export const Matches = (props: Props) => { export const Matches = memo((props: Props) => {
const { const {
fetchMoreMatches, fetchMoreMatches,
isFetching, isFetching,
@ -72,4 +76,4 @@ export const Matches = (props: Props) => {
{isMobileDevice ? mobileView : desktopView} {isMobileDevice ? mobileView : desktopView}
</InfiniteScroll> </InfiniteScroll>
) )
} })

@ -56,7 +56,7 @@ export const Arrows = styled.span<PropsArrows>`
${({ active }) => ( ${({ active }) => (
active active
? css` ? css`
transform: translate(-50%, -50%) rotate(135deg); transform: translate(-50%) rotate(135deg);
` `
: css` : css`
transform: translate(-50%, -50%) rotate(315deg); transform: translate(-50%, -50%) rotate(315deg);

@ -28,10 +28,8 @@ import { Controls } from './components/Controls'
import RewindMobile from './components/RewindMobile' import RewindMobile from './components/RewindMobile'
const tournamentsWithWatermark = { const tournamentsWithWatermark = {
131: 'Spain',
316: 'Tunisia', 316: 'Tunisia',
1136: 'Brasil', 1136: 'Brasil',
2032: 'Spain',
} }
/** /**
* HLS плеер, применяется на лайв и завершенных матчах * HLS плеер, применяется на лайв и завершенных матчах
@ -114,7 +112,9 @@ export const StreamPlayer = (props: Props) => {
<Loader color='#515151' /> <Loader color='#515151' />
</LoaderWrapper> </LoaderWrapper>
{user {user
&& Object.keys(tournamentsWithWatermark)?.includes(String(profile?.tournament.id)) && Boolean(
tournamentsWithWatermark[profile?.tournament.id as keyof typeof tournamentsWithWatermark],
)
&& playing && playing
&& isLive && isLive
&& ( && (

@ -21,6 +21,8 @@ import { useToggle } from 'hooks/useToggle'
import { ProfileTypes, SportTypes } from 'config' import { ProfileTypes, SportTypes } from 'config'
import { useAuthStore } from '../../AuthStore'
type ProfileType = { type ProfileType = {
profile: ObjectWithName & { profile: ObjectWithName & {
additionalInfo: ObjectWithName & { additionalInfo: ObjectWithName & {
@ -40,6 +42,7 @@ export type SuperTournament = ObjectWithName & {
type Args = Parameters<typeof modifyUserFavorites>[0] type Args = Parameters<typeof modifyUserFavorites>[0]
export const useUserFavorites = () => { export const useUserFavorites = () => {
const { userInfo } = useAuthStore()
const [userFavorites, setUserFavorites] = useState<UserFavorites>([]) const [userFavorites, setUserFavorites] = useState<UserFavorites>([])
const [playerHighlight, setPlayerHighlight] = useState<ProfileType>({} as ProfileType) const [playerHighlight, setPlayerHighlight] = useState<ProfileType>({} as ProfileType)
@ -78,7 +81,8 @@ export const useUserFavorites = () => {
setUserFavorites(value) setUserFavorites(value)
} }
}) })
}, []) // eslint-disable-next-line react-hooks/exhaustive-deps
}, [userInfo?.email])
const removeSuperTournament = (id: number) => { const removeSuperTournament = (id: number) => {
forEach(userFavorites, (item) => { forEach(userFavorites, (item) => {

@ -10,9 +10,9 @@ import map from 'lodash/map'
import { FavoritesActions } from 'requests' import { FavoritesActions } from 'requests'
import { Modal } from 'features/Modal' import { Modal } from 'features/Modal'
import { ProfileLink } from 'features/ProfileLink' import { ProfileLink } from 'features/ProfileLink'
import { Close } from '../../libs/objects/Close'
import { Close } from 'libs/objects/Close'
import { TooltipBlock } from './TooltipBlock' import { TooltipBlock } from './TooltipBlock'
import { FavoritesToolip } from './FavoritesTooltip' import { FavoritesToolip } from './FavoritesTooltip'
@ -29,6 +29,8 @@ import {
ScrollWrapper, ScrollWrapper,
} from './styled' } from './styled'
import { useAuthStore } from '../AuthStore'
type Props = { type Props = {
marginTop?: number, marginTop?: number,
} }
@ -44,9 +46,14 @@ export const UserFavorites = ({ marginTop }: Props) => {
userFavorites, userFavorites,
} = useUserFavoritesStore() } = useUserFavoritesStore()
const { user } = useAuthStore()
const [position, setPosition] = useState(0) const [position, setPosition] = useState(0)
useEffect(fetchFavorites, [fetchFavorites]) useEffect(() => {
if (!user) return
fetchFavorites()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchFavorites])
const getPosition = (event: MouseEvent<HTMLDivElement> | FocusEvent<HTMLDivElement>) => { const getPosition = (event: MouseEvent<HTMLDivElement> | FocusEvent<HTMLDivElement>) => {
if (event.currentTarget) { if (event.currentTarget) {

@ -1,11 +1,9 @@
import { removeToken } from '../token'
export const logoutIfUnauthorized = async (response: Response) => { export const logoutIfUnauthorized = async (response: Response) => {
/* отключили из-за доступа без авторизации */ /* отключили из-за доступа без авторизации */
if (response.status === 401 || response.status === 403) { // if (response.status === 401 || response.status === 403) {
removeToken() // removeToken()
window.dispatchEvent(new Event('FORBIDDEN_REQUEST')) // window.dispatchEvent(new Event('FORBIDDEN_REQUEST'))
} // }
const error = new Error(response.statusText) const error = new Error(response.statusText)
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

@ -12,6 +12,6 @@ export const getSound = async (id: number | string): Promise<ResponseSound> => {
return callApi({ return callApi({
config, config,
url: `${API_ROOT}/v1/highlights/music/${id}`, url: `${API_ROOT}/v1/aws/highlights/music/${id}`,
}) })
} }

Loading…
Cancel
Save