Skip to content

Commit

Permalink
flytter driftsmeldinger til server-side
Browse files Browse the repository at this point in the history
  • Loading branch information
toresbe committed Nov 21, 2024
1 parent 37b0987 commit dd786a0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {getPathPrefixIncludingLocale} from "./getPathPrefixIncludingLocale.ts";
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
import {ReactQueryDevtools} from "@tanstack/react-query-devtools";
import {onLanguageSelect, setParams} from "@navikt/nav-dekoratoren-moduler";
import {Driftsmeldinger} from "./lib/driftsmeldinger/Driftsmeldinger.tsx";

const queryClient = new QueryClient();

Expand Down Expand Up @@ -53,7 +52,6 @@ export default function App() {
return (
<Suspense fallback={<ApplicationSpinner />}>
<QueryClientProvider client={queryClient}>
<Driftsmeldinger />
<BrowserRouter
basename={prefix}
future={{
Expand Down
6 changes: 5 additions & 1 deletion src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {isSupportedLanguage} from "../../lib/i18n/common.ts";
import {DigisosContextProvider} from "../../lib/providers/DigisosContextProvider.tsx";
import {NextIntlClientProvider} from "next-intl";
import {getMessages} from "next-intl/server";
import {Driftsmeldinger} from "../../lib/driftsmeldinger/Driftsmeldinger.tsx";

export default async function Layout({
children,
Expand All @@ -16,7 +17,10 @@ export default async function Layout({
const locale = isSupportedLanguage(localeParam) ? localeParam : "nb";
return (
<NextIntlClientProvider messages={messages} locale={locale}>
<DigisosContextProvider locale={locale}>{children}</DigisosContextProvider>
<DigisosContextProvider locale={locale}>
<Driftsmeldinger />
{children}
</DigisosContextProvider>
</NextIntlClientProvider>
);
}
8 changes: 1 addition & 7 deletions src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {DigisosContext} from "../../lib/providers/DigisosContext.ts";
import {BASE_PATH} from "../../lib/constants.ts";
import {configureLogger} from "@navikt/next-logger";
import {initAmplitude} from "../../lib/amplitude/Amplitude.tsx";
import {Driftsmeldinger} from "../../lib/driftsmeldinger/Driftsmeldinger.tsx";

const Page = () => {
configureLogger({basePath: BASE_PATH});
Expand All @@ -21,12 +20,7 @@ const Page = () => {
onLanguageSelect(({locale: language, url}) =>
setParams({language}).then(() => window.location.assign(`${url}${path}`))
);
return (
<>
<Driftsmeldinger />
<Informasjon />
</>
);
return <Informasjon />;
};

export default Page;
10 changes: 2 additions & 8 deletions src/lib/driftsmeldinger/Driftsmeldinger.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
"use client";
import {Alert} from "@navikt/ds-react";
import Markdown from "markdown-to-jsx";
import {getDriftsmeldinger} from "./getDriftsmeldinger.ts";
import {useEffect, useState} from "react";
import {Driftsmelding} from "./types.ts";

export const Driftsmeldinger = () => {
const [driftsmeldinger, setDriftsmeldinger] = useState<Driftsmelding[] | null>(null);
useEffect(() => {
getDriftsmeldinger().then(setDriftsmeldinger);
}, []);
export const Driftsmeldinger = async () => {
const driftsmeldinger = await getDriftsmeldinger();
return driftsmeldinger?.map(({severity, text}) => (
<Alert
variant={severity}
Expand Down

0 comments on commit dd786a0

Please sign in to comment.