/
voting
/
frontend
Обзор
Документация
Войти
/
voting
/
frontend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
main
src/stores/userFlowStore.ts
55 строк
2 KB
TimPulin
039-update-sse-unified-payload
19 июл 2026, 15:39
19 июл 2026, 15:39
ce4a214
Код
Авторство
О чём код?
import { create } from 'zustand' import type { ResultScreenType } from '../api/types' import type { SseScreenType, UserFlowSnapshot } from '../types/user-flow' import { isResultScreenType, mapEventScreenTypeToSseScreenType } from '../utils/userFlowHelpers' export interface UserFlowStoreState { eventId: string | null currentScreen: SseScreenType | null snapshot: UserFlowSnapshot | null resultScreenType: ResultScreenType | null isHydrating: boolean hydrateError: string | null setEventId: (eventId: string | null) => void setCurrentScreen: (screen: SseScreenType) => void setSnapshot: (snapshot: UserFlowSnapshot | null) => void setResultScreenType: (screenType: ResultScreenType | null) => void setIsHydrating: (value: boolean) => void setHydrateError: (error: string | null) => void applyHydratedSnapshot: (snapshot: UserFlowSnapshot) => void reset: () => void } const initialState = { eventId: null as string | null, currentScreen: null as SseScreenType | null, snapshot: null as UserFlowSnapshot | null, resultScreenType: null as ResultScreenType | null, isHydrating: false, hydrateError: null as string | null } export const useUserFlowStore = create<UserFlowStoreState>((set) => ({ ...initialState, setEventId: (eventId) => set({ eventId }), setCurrentScreen: (currentScreen) => set({ currentScreen }), setSnapshot: (snapshot) => set({ snapshot }), setResultScreenType: (resultScreenType) => set({ resultScreenType }), setIsHydrating: (isHydrating) => set({ isHydrating }), setHydrateError: (hydrateError) => set({ hydrateError }), applyHydratedSnapshot: (snapshot) => { const mapped = mapEventScreenTypeToSseScreenType(snapshot.event.currentScreenType) set({ snapshot, currentScreen: mapped, hydrateError: null, ...(mapped && mapped !== 'nomination' && isResultScreenType(snapshot.event.currentScreenType) ? { resultScreenType: snapshot.event.currentScreenType } : {}) }) }, reset: () => set({ ...initialState }) }))