umami/src/app/(main)/App.tsx

37 lines
822 B
TypeScript
Raw Normal View History

2024-02-13 20:36:55 +00:00
'use client';
2023-11-29 22:03:10 +00:00
import { Loading } from 'react-basics';
2023-09-29 12:29:22 +00:00
import Script from 'next/script';
import { usePathname } from 'next/navigation';
2023-11-29 22:03:10 +00:00
import { useLogin, useConfig } from 'components/hooks';
2023-11-12 04:47:06 +00:00
import UpdateNotice from './UpdateNotice';
2023-09-29 12:29:22 +00:00
2023-11-12 04:45:09 +00:00
export function App({ children }) {
2023-11-29 22:03:10 +00:00
const { user, isLoading, error } = useLogin();
2023-09-29 12:29:22 +00:00
const config = useConfig();
const pathname = usePathname();
2023-11-29 22:03:10 +00:00
if (isLoading) {
return <Loading />;
}
if (error) {
window.location.href = `${process.env.basePath || ''}/login`;
}
2023-09-29 12:29:22 +00:00
if (!user || !config) {
return null;
}
return (
<>
{children}
<UpdateNotice user={user} config={config} />
{process.env.NODE_ENV === 'production' && !pathname.includes('/share/') && (
2023-12-20 17:31:33 +00:00
<Script src={`/telemetry.js`} />
2023-09-29 12:29:22 +00:00
)}
</>
);
}
2023-11-12 04:45:09 +00:00
export default App;