Refactor BFF Package Structure #64
@ -1,5 +1,7 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
import suLogoLandscape from "./assets/SU_logo_optimized.svg";
|
import suLogoLandscape from "./assets/SU_logo_optimized.svg";
|
||||||
|
import { setLanguagePreference } from "./hooks/backend.ts";
|
||||||
import { ProfileContext } from "./hooks/profile.ts";
|
import { ProfileContext } from "./hooks/profile.ts";
|
||||||
import Studentportalen from "./Studentportalen.tsx";
|
import Studentportalen from "./Studentportalen.tsx";
|
||||||
import { useViewTransitioningFetch } from "./hooks/fetch";
|
import { useViewTransitioningFetch } from "./hooks/fetch";
|
||||||
@ -7,6 +9,10 @@ import { useViewTransitioningFetch } from "./hooks/fetch";
|
|||||||
function App() {
|
function App() {
|
||||||
const { data: profile, error } = useViewTransitioningFetch("/profile");
|
const { data: profile, error } = useViewTransitioningFetch("/profile");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLanguagePreference(profile?.language);
|
||||||
|
}, [profile?.language]);
|
||||||
|
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
return splashScreen("Loading...");
|
return splashScreen("Loading...");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,12 @@
|
|||||||
import createClient, { Middleware } from "openapi-fetch";
|
import createClient, { Middleware } from "openapi-fetch";
|
||||||
import type { paths } from "../lib/api";
|
import type { paths } from "../lib/api";
|
||||||
|
|
||||||
|
let languagePreference: string | undefined;
|
||||||
|
|
||||||
|
export function setLanguagePreference(language: string | undefined) {
|
||||||
|
languagePreference = language;
|
||||||
|
}
|
||||||
|
|
||||||
const client = createClient<paths>({
|
const client = createClient<paths>({
|
||||||
baseUrl: import.meta.env.VITE_BACKEND_URL,
|
baseUrl: import.meta.env.VITE_BACKEND_URL,
|
||||||
});
|
});
|
||||||
@ -31,7 +37,8 @@ const includeCsrfToken: Middleware = {
|
|||||||
|
|
||||||
const includeAcceptLanguage: Middleware = {
|
const includeAcceptLanguage: Middleware = {
|
||||||
onRequest({ request }) {
|
onRequest({ request }) {
|
||||||
const language = navigator.language.split("-")[0] || "en";
|
const language =
|
||||||
|
languagePreference ?? navigator.language.split("-")[0] ?? "en";
|
||||||
request.headers.set("Accept-Language", language);
|
request.headers.set("Accept-Language", language);
|
||||||
return request;
|
return request;
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user