Refactor BFF Package Structure #64

Merged
stne3960 merged 12 commits from refactor/bff-structure into main 2026-01-12 17:38:55 +01:00
2 changed files with 14 additions and 1 deletions
Showing only changes of commit 63eaebb7dc - Show all commits

View File

@ -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...");
} }

View File

@ -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;
}, },