1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/splash/SplashPage/SplashPage.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

58 lines
1.8 KiB
TypeScript

import { useNavigate, Navigate } from 'react-router-dom';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import useSplashApi from 'hooks/api/actions/useSplashApi/useSplashApi';
import { SplashPageOperators } from 'component/splash/SplashPageOperators';
import { useEffect } from 'react';
import { useAuthSplash } from 'hooks/api/getters/useAuth/useAuthSplash';
import { splashIds, SplashId } from 'component/splash/splash';
export const SplashPage = () => {
const splashId = useRequiredPathParam('splashId');
const isKnownId = isKnownSplashId(splashId);
const { refetchSplash } = useAuthSplash();
const { setSplashSeen } = useSplashApi();
// Close the splash "modal" on escape.
useNavigationOnKeydown('Escape', '/');
// Mark the splash ID as seen.
useEffect(() => {
if (splashId && isKnownId) {
setSplashSeen(splashId)
.then(() => refetchSplash())
.catch(console.warn);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [splashId, isKnownId]);
if (!isKnownId) {
return null;
}
switch (splashId) {
case 'operators':
return <SplashPageOperators />;
default:
return <Navigate to='/' replace />;
}
};
const useNavigationOnKeydown = (key: string, path: string) => {
const navigate = useNavigate();
useEffect(() => {
const handler = (event: KeyboardEvent) => {
if (event.code === key) {
navigate(path);
}
};
window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, [key, path, navigate]);
};
const isKnownSplashId = (value: string): value is SplashId => {
return (splashIds as Readonly<string[]>).includes(value);
};