diff --git a/frontend/src/access_control/authProvider.ts b/frontend/src/access_control/authProvider.ts index 9a57b9638..48eced81e 100644 --- a/frontend/src/access_control/authProvider.ts +++ b/frontend/src/access_control/authProvider.ts @@ -4,7 +4,7 @@ import { AuthProvider } from "react-admin"; import { set_settings_in_local_storage } from "../commons/functions"; import { httpClient } from "../commons/ra-data-django-rest-framework"; -import { getSettingTheme, saveSettingListProperties, setListProperties } from "../commons/settings/functions"; +import { saveSettingListProperties, setListProperties } from "../commons/settings/functions"; const authProvider: AuthProvider = { login: ({ username, password }) => { @@ -85,7 +85,7 @@ const authProvider: AuthProvider = { fullName = user_json.full_name; } else { const userinfo = await getUserInfo(); - const { id: id, full_name: fullName, username: avatar } = userinfo; + const { id: id, full_name: fullName, null: avatar } = userinfo; return Promise.resolve({ id, fullName, avatar }); } @@ -97,14 +97,9 @@ const authProvider: AuthProvider = { const getUserInfo = async () => { return httpClient(window.__RUNTIME_CONFIG__.API_BASE_URL + "/users/me/").then((response) => { - const before_theme = getSettingTheme(); setListProperties(response.json.setting_list_properties); delete response.json.setting_list_properties; localStorage.setItem("user", JSON.stringify(response.json)); - const after_theme = getSettingTheme(); - if (before_theme != after_theme) { - window.location.reload(); - } return response.json; }); }; diff --git a/frontend/src/dashboard/Dashboard.tsx b/frontend/src/dashboard/Dashboard.tsx index 4d1f14758..be0e370e2 100644 --- a/frontend/src/dashboard/Dashboard.tsx +++ b/frontend/src/dashboard/Dashboard.tsx @@ -1,8 +1,10 @@ import { Stack } from "@mui/material"; -import { Fragment } from "react"; +import { Fragment, useEffect, useState } from "react"; +import { useTheme } from "react-admin"; import { useAuth } from "react-oidc-context"; import { jwt_signed_in } from "../access_control/authProvider"; +import { getSettingTheme, getTheme } from "../commons/settings/functions"; import ObservationDashboardList from "../core/observations/ObservationDashboardList"; import MetricsHeader from "../metrics/MetricsHeader"; import MetricsSeveritiesCurrent from "../metrics/MetricsSeveritiesCurrent"; @@ -11,6 +13,16 @@ import MetricsStatusCurrent from "../metrics/MetricsStatusCurrent"; const Dashboard = () => { const auth = useAuth(); + const [setting_theme, setSettingTheme] = useState(""); + const [, setTheme] = useTheme(); + + if (setting_theme != getSettingTheme()) { + setSettingTheme(getSettingTheme()); + } + + useEffect(() => { + setTheme(getTheme()); + }, [setting_theme, setTheme]); return ( (jwt_signed_in() || auth.isAuthenticated) && (