fix(frontend): restore default session context store in vertical slice
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
import type { ApiClient } from '../api/client';
|
||||
import type { SessionDetailResponse } from '../api/types';
|
||||
import {
|
||||
createSessionContextStore,
|
||||
type SessionContext,
|
||||
type SessionContextInput,
|
||||
type SessionContextStore as PersistedSessionContextStore
|
||||
} from './session-context-store';
|
||||
|
||||
export type AsyncState = 'idle' | 'loading' | 'success' | 'error';
|
||||
|
||||
export interface SessionContext {
|
||||
sessionCode: string;
|
||||
playerToken: string;
|
||||
nickname: string;
|
||||
}
|
||||
|
||||
export interface SessionContextStore {
|
||||
get(): SessionContext | null;
|
||||
set(context: SessionContext): void;
|
||||
}
|
||||
export type SessionContextStore = Pick<PersistedSessionContextStore, 'get' | 'set'>;
|
||||
|
||||
export interface VerticalSliceState {
|
||||
sessionCode: string;
|
||||
@@ -30,14 +27,9 @@ export interface VerticalSliceController {
|
||||
startRound(sessionCode: string, categorySlug: string): Promise<VerticalSliceState>;
|
||||
}
|
||||
|
||||
const NOOP_SESSION_CONTEXT_STORE: SessionContextStore = {
|
||||
get: () => null,
|
||||
set: () => undefined
|
||||
};
|
||||
|
||||
export function createVerticalSliceController(
|
||||
api: ApiClient,
|
||||
sessionContextStore: SessionContextStore = NOOP_SESSION_CONTEXT_STORE
|
||||
sessionContextStore: SessionContextStore = createSessionContextStore()
|
||||
): VerticalSliceController {
|
||||
const persistedContext = sessionContextStore.get();
|
||||
|
||||
@@ -96,11 +88,12 @@ export function createVerticalSliceController(
|
||||
state.joinState = 'success';
|
||||
state.sessionCode = normalizeCode(join.data.session.code || requestCode);
|
||||
|
||||
sessionContextStore.set({
|
||||
const nextContext: SessionContextInput = {
|
||||
sessionCode: state.sessionCode,
|
||||
playerToken: join.data.player.session_token,
|
||||
nickname: join.data.player.nickname
|
||||
});
|
||||
playerId: join.data.player.id,
|
||||
token: join.data.player.session_token
|
||||
};
|
||||
sessionContextStore.set(nextContext);
|
||||
|
||||
return hydrateLobby(state.sessionCode);
|
||||
}
|
||||
@@ -131,3 +124,5 @@ export function createVerticalSliceController(
|
||||
startRound
|
||||
};
|
||||
}
|
||||
|
||||
export type { SessionContext };
|
||||
|
||||
Reference in New Issue
Block a user