mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
fix: resolve all 14 ESLint warnings across the codebase
- Add varsIgnorePattern to no-unused-vars for destructuring patterns - Fix all react-hooks/exhaustive-deps by adding missing dependencies - Refactor useAnimatedNumber to use ref instead of stale state closure - Wrap handleLinkResult in useCallback for stable deps - Extract OAuth utilities from OAuthCallback.tsx to utils/oauth.ts - Extract background config utilities to utils/backgroundConfig.ts - Remove unused catch parameter in GiftSubscription
This commit is contained in:
63
src/utils/backgroundConfig.ts
Normal file
63
src/utils/backgroundConfig.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { AnimationConfig, BackgroundType } from '@/components/ui/backgrounds/types';
|
||||
|
||||
const ANIMATION_CACHE_KEY = 'cabinet_animation_config';
|
||||
const MAX_CONFIG_JSON_LENGTH = 10_000;
|
||||
|
||||
const VALID_TYPES: ReadonlySet<string> = new Set<BackgroundType>([
|
||||
'aurora',
|
||||
'sparkles',
|
||||
'vortex',
|
||||
'shooting-stars',
|
||||
'background-beams',
|
||||
'background-beams-collision',
|
||||
'gradient-animation',
|
||||
'wavy',
|
||||
'background-lines',
|
||||
'boxes',
|
||||
'meteors',
|
||||
'grid',
|
||||
'dots',
|
||||
'spotlight',
|
||||
'ripple',
|
||||
'none',
|
||||
]);
|
||||
|
||||
export function validateConfig(parsed: unknown): AnimationConfig | null {
|
||||
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return null;
|
||||
const obj = parsed as Record<string, unknown>;
|
||||
if (typeof obj.enabled !== 'boolean') return null;
|
||||
if (typeof obj.type !== 'string' || !VALID_TYPES.has(obj.type)) return null;
|
||||
if (typeof obj.opacity !== 'number') return null;
|
||||
if (typeof obj.blur !== 'number') return null;
|
||||
if (obj.settings != null && (typeof obj.settings !== 'object' || Array.isArray(obj.settings)))
|
||||
return null;
|
||||
return {
|
||||
enabled: obj.enabled,
|
||||
type: obj.type as BackgroundType,
|
||||
opacity: Math.max(0, Math.min(1, obj.opacity)),
|
||||
blur: Math.max(0, Math.min(50, obj.blur)),
|
||||
settings: (obj.settings as Record<string, unknown>) ?? {},
|
||||
reducedOnMobile: typeof obj.reducedOnMobile === 'boolean' ? obj.reducedOnMobile : true,
|
||||
};
|
||||
}
|
||||
|
||||
export function getCachedConfig(): AnimationConfig | null {
|
||||
try {
|
||||
const cached = localStorage.getItem(ANIMATION_CACHE_KEY);
|
||||
if (!cached || cached.length > MAX_CONFIG_JSON_LENGTH) return null;
|
||||
return validateConfig(JSON.parse(cached));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function setCachedConfig(config: AnimationConfig) {
|
||||
try {
|
||||
localStorage.setItem(ANIMATION_CACHE_KEY, JSON.stringify(config));
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function setCachedAnimationConfig(config: AnimationConfig) {
|
||||
const validated = validateConfig(config);
|
||||
if (validated) setCachedConfig(validated);
|
||||
}
|
||||
48
src/utils/oauth.ts
Normal file
48
src/utils/oauth.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
export const LINK_OAUTH_STATE_KEY = 'link_oauth_state';
|
||||
export const LINK_OAUTH_PROVIDER_KEY = 'link_oauth_provider';
|
||||
|
||||
const OAUTH_STATE_KEY = 'oauth_state';
|
||||
const OAUTH_PROVIDER_KEY = 'oauth_provider';
|
||||
|
||||
export function saveOAuthState(state: string, provider: string): void {
|
||||
sessionStorage.setItem(OAUTH_STATE_KEY, state);
|
||||
sessionStorage.setItem(OAUTH_PROVIDER_KEY, provider);
|
||||
}
|
||||
|
||||
export function loadOAuthState(): { state: string; provider: string } | null {
|
||||
const state = sessionStorage.getItem(OAUTH_STATE_KEY);
|
||||
const provider = sessionStorage.getItem(OAUTH_PROVIDER_KEY);
|
||||
if (!state || !provider) return null;
|
||||
return { state, provider };
|
||||
}
|
||||
|
||||
export function clearOAuthState(): void {
|
||||
sessionStorage.removeItem(OAUTH_STATE_KEY);
|
||||
sessionStorage.removeItem(OAUTH_PROVIDER_KEY);
|
||||
}
|
||||
|
||||
export function peekLinkOAuthState(): { state: string; provider: string } | null {
|
||||
const state = sessionStorage.getItem(LINK_OAUTH_STATE_KEY);
|
||||
const provider = sessionStorage.getItem(LINK_OAUTH_PROVIDER_KEY);
|
||||
if (!state || !provider) return null;
|
||||
return { state, provider };
|
||||
}
|
||||
|
||||
export function clearLinkOAuthState(): void {
|
||||
sessionStorage.removeItem(LINK_OAUTH_STATE_KEY);
|
||||
sessionStorage.removeItem(LINK_OAUTH_PROVIDER_KEY);
|
||||
}
|
||||
|
||||
export function getErrorDetail(err: unknown): string | null {
|
||||
if (err && typeof err === 'object' && 'response' in err) {
|
||||
const resp = (err as { response?: { data?: { detail?: unknown } } }).response;
|
||||
const detail = resp?.data?.detail;
|
||||
if (typeof detail === 'string') return detail;
|
||||
if (detail && typeof detail === 'object' && 'message' in detail) {
|
||||
const msg = (detail as Record<string, unknown>).message;
|
||||
if (typeof msg === 'string') return msg;
|
||||
}
|
||||
}
|
||||
if (err instanceof Error) return err.message;
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user