This commit is contained in:
dahyeon committed 2026-05-02 04:05:35 -07:00
1 parent 4baea89f89
commit fd386ed202
32 files changed
+1128 -601

No files matched your search

+24 -19
View File
@@ -1,9 +1,8 @@
import { useSyncExternalStore } from 'react';
export type DevCaptainSide = 'spectator' | 'blue' | 'red';
const AUTH_USER_ID_STORAGE_KEY = 'lolympus.authUserId';
const DEV_CAPTAIN_SIDE_STORAGE_KEY = 'lolympus.devCaptainSide';
const DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY = 'lolympus.devCaptainTeamIndex';
const LEGACY_DEV_CAPTAIN_SIDE_STORAGE_KEY = 'lolympus.devCaptainSide';
const AUTH_USER_CHANGED_EVENT = 'lolympus:auth-user-changed';
const CAPTAIN_SIDE_CHANGED_EVENT = 'lolympus:captain-side-changed';
@@ -55,23 +54,29 @@ export function setAuthUserId(userId: string | null) {
dispatchWindowEvent(AUTH_USER_CHANGED_EVENT);
}
export function getDevCaptainSide(): DevCaptainSide {
if (typeof window === 'undefined') return 'spectator';
export function getDevCaptainTeamIndex(): number | null {
if (typeof window === 'undefined') return null;
const value = window.localStorage.getItem(
DEV_CAPTAIN_SIDE_STORAGE_KEY,
) as DevCaptainSide | null;
const value = window.localStorage.getItem(DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY);
const parsed = Number(value);
if (Number.isInteger(parsed) && parsed > 0) return parsed;
if (value === 'blue' || value === 'red' || value === 'spectator') {
return value;
}
return 'spectator';
const legacy = window.localStorage.getItem(LEGACY_DEV_CAPTAIN_SIDE_STORAGE_KEY);
if (legacy === 'blue') return 1;
if (legacy === 'red') return 2;
return null;
}
export function setDevCaptainSide(side: DevCaptainSide) {
export function setDevCaptainTeamIndex(teamIndex: number | null) {
if (typeof window === 'undefined') return;
window.localStorage.setItem(DEV_CAPTAIN_SIDE_STORAGE_KEY, side);
if (teamIndex && Number.isInteger(teamIndex) && teamIndex > 0) {
window.localStorage.setItem(
DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY,
String(teamIndex),
);
} else {
window.localStorage.removeItem(DEV_CAPTAIN_TEAM_INDEX_STORAGE_KEY);
}
dispatchWindowEvent(CAPTAIN_SIDE_CHANGED_EVENT);
}
@@ -83,10 +88,10 @@ export function useAuthUserId(): string | null {
);
}
export function useDevCaptainSide(): DevCaptainSide {
return useSyncExternalStore<DevCaptainSide>(
export function useDevCaptainTeamIndex(): number | null {
return useSyncExternalStore<number | null>(
(callback) => subscribeToWindowChanges(CAPTAIN_SIDE_CHANGED_EVENT, callback),
getDevCaptainSide,
() => 'spectator',
getDevCaptainTeamIndex,
() => null,
);
}