mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(website): migration from old website
This commit is contained in:
@@ -2,7 +2,15 @@
|
||||
|
||||
import { ThemeProvider } from 'next-themes';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { ServiceWorker } from '~/components/ServiceWorker';
|
||||
import { SystemThemeFallback } from '~/components/SystemThemeFallback';
|
||||
|
||||
export function Providers({ children }: PropsWithChildren) {
|
||||
return <ThemeProvider attribute="class">{children}</ThemeProvider>;
|
||||
return (
|
||||
<>
|
||||
<ThemeProvider attribute="class">{children}</ThemeProvider>
|
||||
<ServiceWorker />
|
||||
<SystemThemeFallback />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
9
apps/website/src/components/ServiceWorker.tsx
Normal file
9
apps/website/src/components/ServiceWorker.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import { useUnregisterServiceWorker } from '~/hooks/useUnregisterServiceWorker';
|
||||
|
||||
export function ServiceWorker() {
|
||||
useUnregisterServiceWorker();
|
||||
|
||||
return null;
|
||||
}
|
||||
9
apps/website/src/components/SystemThemeFallback.tsx
Normal file
9
apps/website/src/components/SystemThemeFallback.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import { useSystemThemeFallback } from '~/hooks/useSystemThemeFallback';
|
||||
|
||||
export function SystemThemeFallback() {
|
||||
useSystemThemeFallback();
|
||||
|
||||
return null;
|
||||
}
|
||||
13
apps/website/src/hooks/useSystemThemeFallback.ts
Normal file
13
apps/website/src/hooks/useSystemThemeFallback.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useSystemThemeFallback() {
|
||||
useEffect(() => {
|
||||
const theme = localStorage.getItem('theme');
|
||||
if (theme === 'auto') {
|
||||
localStorage.setItem('theme', 'system');
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
}
|
||||
14
apps/website/src/hooks/useUnregisterServiceWorker.ts
Normal file
14
apps/website/src/hooks/useUnregisterServiceWorker.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useUnregisterServiceWorker() {
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line promise/prefer-await-to-then
|
||||
void navigator.serviceWorker.getRegistrations().then((registrations) => {
|
||||
for (const registration of registrations) {
|
||||
void registration.unregister();
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user