Add refreshChains function to ChallengeContext and integrate it into ChainsPage for improved data management. This allows for manual refreshing of chain data when the component mounts, enhancing user experience.
platform/bro-js/challenge-pl/pipeline/head There was a failure building this commit
platform/bro-js/challenge-pl/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -65,6 +65,7 @@ interface ChallengeContextValue {
|
|||||||
login: (nickname: string, workplaceNumber: string) => Promise<void>
|
login: (nickname: string, workplaceNumber: string) => Promise<void>
|
||||||
logout: () => void
|
logout: () => void
|
||||||
refreshStats: () => Promise<void>
|
refreshStats: () => Promise<void>
|
||||||
|
refreshChains: () => Promise<void>
|
||||||
eventEmitter: ChallengeEventEmitter
|
eventEmitter: ChallengeEventEmitter
|
||||||
pollingManager: PollingManager
|
pollingManager: PollingManager
|
||||||
metricsCollector: MetricsCollector
|
metricsCollector: MetricsCollector
|
||||||
@@ -96,10 +97,23 @@ export const ChallengeProvider = ({ children }: PropsWithChildren) => {
|
|||||||
const [authUser, { isLoading: isAuthLoading }] = useAuthUserMutation()
|
const [authUser, { isLoading: isAuthLoading }] = useAuthUserMutation()
|
||||||
const [triggerStats, statsResult] = useLazyGetUserStatsQuery()
|
const [triggerStats, statsResult] = useLazyGetUserStatsQuery()
|
||||||
|
|
||||||
const { data: chainsData, isLoading: isChainsLoading } = useGetChainsQuery(undefined, {
|
const {
|
||||||
|
data: chainsData,
|
||||||
|
isLoading: isChainsLoading,
|
||||||
|
refetch: refetchChains,
|
||||||
|
} = useGetChainsQuery(undefined, {
|
||||||
skip: !userId,
|
skip: !userId,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const refreshChains = useCallback(async () => {
|
||||||
|
if (!userId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheRef.current.clear('chains')
|
||||||
|
await refetchChains()
|
||||||
|
}, [refetchChains, userId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (chainsData) {
|
if (chainsData) {
|
||||||
setChains(chainsData)
|
setChains(chainsData)
|
||||||
@@ -189,6 +203,7 @@ export const ChallengeProvider = ({ children }: PropsWithChildren) => {
|
|||||||
login,
|
login,
|
||||||
logout,
|
logout,
|
||||||
refreshStats,
|
refreshStats,
|
||||||
|
refreshChains,
|
||||||
eventEmitter,
|
eventEmitter,
|
||||||
pollingManager,
|
pollingManager,
|
||||||
metricsCollector,
|
metricsCollector,
|
||||||
@@ -213,6 +228,7 @@ export const ChallengeProvider = ({ children }: PropsWithChildren) => {
|
|||||||
personalDashboard,
|
personalDashboard,
|
||||||
pollingManager,
|
pollingManager,
|
||||||
refreshStats,
|
refreshStats,
|
||||||
|
refreshChains,
|
||||||
saveDraft,
|
saveDraft,
|
||||||
stats,
|
stats,
|
||||||
userId,
|
userId,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type { ChallengeChain } from '../../__data__/types'
|
|||||||
|
|
||||||
export const ChainsPage = () => {
|
export const ChainsPage = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { nickname } = useChallenge()
|
const { nickname, refreshChains } = useChallenge()
|
||||||
|
|
||||||
// Проверяем авторизацию
|
// Проверяем авторизацию
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -24,6 +24,10 @@ export const ChainsPage = () => {
|
|||||||
}
|
}
|
||||||
}, [navigate, nickname])
|
}, [navigate, nickname])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refreshChains()
|
||||||
|
}, [refreshChains])
|
||||||
|
|
||||||
const handleSelectChain = (chain: ChallengeChain) => {
|
const handleSelectChain = (chain: ChallengeChain) => {
|
||||||
storage.setSelectedChainId(chain.id)
|
storage.setSelectedChainId(chain.id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user