PromucFlow_constructor/app/client/src/sagas/ThemeSaga.tsx
2022-12-15 09:36:13 +05:30

37 lines
1.3 KiB
TypeScript

import {
ReduxActionTypes,
ReduxAction,
} from "@appsmith/constants/ReduxActionConstants";
import { select, takeLatest } from "redux-saga/effects";
import localStorage from "utils/localStorage";
import { getCurrentThemeDetails, ThemeMode } from "selectors/themeSelectors";
import { trimTrailingSlash } from "utils/helpers";
export type BackgroundTheme = {
colors: { homepageBackground: string; appBackground: string };
};
export function changeAppBackground(currentTheme: BackgroundTheme) {
if (
trimTrailingSlash(window.location.pathname) === "/applications" ||
window.location.pathname.indexOf("/settings/") !== -1 ||
trimTrailingSlash(window.location.pathname) === "/profile" ||
trimTrailingSlash(window.location.pathname) === "/signup-success"
) {
document.body.style.backgroundColor =
currentTheme.colors.homepageBackground;
} else {
document.body.style.backgroundColor = currentTheme.colors.appBackground;
}
}
export function* setThemeSaga(actionPayload: ReduxAction<ThemeMode>) {
const theme: BackgroundTheme = yield select(getCurrentThemeDetails);
changeAppBackground(theme);
yield localStorage.setItem("THEME", actionPayload.payload);
}
export default function* themeSagas() {
yield takeLatest(ReduxActionTypes.SET_THEME, setThemeSaga);
}