From 5a0324fbd4e15eaf4dab8c8c1f7c91a56f0bfbe3 Mon Sep 17 00:00:00 2001 From: Wutras Date: Tue, 17 Oct 2023 17:19:52 +0200 Subject: [PATCH] Store theme choice in localstorage, use env for default --- Dockerfile | 1 + src/components/App/App.js | 4 +++- src/helpers/constants.js | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 45929da..a1efd84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ ARG DEFAULT_CHATBOT_BACKEND_URL ARG DEFAULT_CHATBOT_COMPONENTS ARG INITIAL_QUESTION_PARAMETER_NAME ARG DEFAULT_BACKEND_TYPE +ARG DEFAULT_THEME WORKDIR /app COPY ./package*.json ./ diff --git a/src/components/App/App.js b/src/components/App/App.js index d18c81d..f2f7c08 100644 --- a/src/components/App/App.js +++ b/src/components/App/App.js @@ -8,6 +8,7 @@ import { defaultBackendType, defaultChatbotComponents, initialQuestionParameter, + defaultTheme, } from "../../helpers/constants"; import { supportedServiceNames, @@ -61,7 +62,7 @@ class App extends Component { backendUrl, isSending: false, backendType, - currentTheme: "default", + currentTheme: localStorage.getItem("currentTheme") ?? defaultTheme, iconUrl, }; @@ -186,6 +187,7 @@ class App extends Component { setTheme(themeName) { if (!supportedThemes.includes(themeName)) return; + localStorage.setItem("currentTheme", themeName); this.setState({ currentTheme: themeName, }); diff --git a/src/helpers/constants.js b/src/helpers/constants.js index 2546a90..56aa844 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -20,3 +20,6 @@ export const defaultRasaBackendUrl = export const defaultBackendType = window._env_?.DEFAULT_BACKEND_TYPE ?? "qanary"; + +export const defaultTheme = + window._env_?.DEFAULT_THEME ?? "default";