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

This commit is contained in:
2025-12-15 17:43:21 +03:00
parent 23ec02e29a
commit a0ac758049
2 changed files with 22 additions and 2 deletions
+17 -1
View File
@@ -65,6 +65,7 @@ interface ChallengeContextValue {
login: (nickname: string, workplaceNumber: string) => Promise<void>
logout: () => void
refreshStats: () => Promise<void>
refreshChains: () => Promise<void>
eventEmitter: ChallengeEventEmitter
pollingManager: PollingManager
metricsCollector: MetricsCollector
@@ -96,10 +97,23 @@ export const ChallengeProvider = ({ children }: PropsWithChildren) => {
const [authUser, { isLoading: isAuthLoading }] = useAuthUserMutation()
const [triggerStats, statsResult] = useLazyGetUserStatsQuery()
const { data: chainsData, isLoading: isChainsLoading } = useGetChainsQuery(undefined, {
const {
data: chainsData,
isLoading: isChainsLoading,
refetch: refetchChains,
} = useGetChainsQuery(undefined, {
skip: !userId,
})
const refreshChains = useCallback(async () => {
if (!userId) {
return
}
cacheRef.current.clear('chains')
await refetchChains()
}, [refetchChains, userId])
useEffect(() => {
if (chainsData) {
setChains(chainsData)
@@ -189,6 +203,7 @@ export const ChallengeProvider = ({ children }: PropsWithChildren) => {
login,
logout,
refreshStats,
refreshChains,
eventEmitter,
pollingManager,
metricsCollector,
@@ -213,6 +228,7 @@ export const ChallengeProvider = ({ children }: PropsWithChildren) => {
personalDashboard,
pollingManager,
refreshStats,
refreshChains,
saveDraft,
stats,
userId,
+5 -1
View File
@@ -10,7 +10,7 @@ import type { ChallengeChain } from '../../__data__/types'
export const ChainsPage = () => {
const navigate = useNavigate()
const { nickname } = useChallenge()
const { nickname, refreshChains } = useChallenge()
// Проверяем авторизацию
useEffect(() => {
@@ -24,6 +24,10 @@ export const ChainsPage = () => {
}
}, [navigate, nickname])
useEffect(() => {
refreshChains()
}, [refreshChains])
const handleSelectChain = (chain: ChallengeChain) => {
storage.setSelectedChainId(chain.id)