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