PromucFlow_constructor/app/client/src/pages/common/AppRoute.tsx

62 lines
1.7 KiB
TypeScript
Raw Normal View History

import React from "react";
import { Route, RouteComponentProps } from "react-router-dom";
import * as Sentry from "@sentry/react";
import { connect } from "react-redux";
import { getCurrentThemeDetails, ThemeMode } from "selectors/themeSelectors";
2020-09-21 13:08:57 +00:00
import { AppState } from "reducers";
import { setThemeMode } from "actions/themeActions";
import equal from "fast-deep-equal/es6";
const SentryRoute = Sentry.withSentryRouting(Route);
interface AppRouteProps {
2020-09-21 13:08:57 +00:00
currentTheme: any;
2020-03-11 13:59:46 +00:00
path?: string;
component:
| React.ComponentType<RouteComponentProps<any>>
| React.ComponentType<any>;
exact?: boolean;
2020-03-11 13:59:46 +00:00
logDisable?: boolean;
name: string;
location?: any;
setTheme: (themeMode: ThemeMode) => void;
}
class AppRouteWithoutProps extends React.Component<AppRouteProps> {
shouldComponentUpdate(prevProps: AppRouteProps, nextProps: AppRouteProps) {
return !equal(prevProps?.location, nextProps?.location);
2020-09-21 13:08:57 +00:00
}
2020-09-21 13:08:57 +00:00
render() {
2021-01-12 01:22:31 +00:00
const { currentTheme, ...rest } = this.props;
2020-09-21 13:08:57 +00:00
if (
window.location.pathname === "/applications" ||
window.location.pathname.indexOf("/settings/") !== -1
) {
document.body.style.backgroundColor =
currentTheme.colors.homepageBackground;
} else {
2020-09-21 13:25:58 +00:00
document.body.style.backgroundColor = currentTheme.colors.appBackground;
2020-09-21 13:08:57 +00:00
}
2021-01-12 01:22:31 +00:00
return <SentryRoute {...rest} />;
}
2020-09-21 13:08:57 +00:00
}
const mapStateToProps = (state: AppState) => ({
currentTheme: getCurrentThemeDetails(state),
2020-09-21 13:08:57 +00:00
});
const mapDispatchToProps = (dispatch: any) => ({
setTheme: (mode: ThemeMode) => {
dispatch(setThemeMode(mode));
},
});
const AppRoute = connect(
mapStateToProps,
mapDispatchToProps,
)(AppRouteWithoutProps);
2019-09-02 14:50:01 +00:00
2020-09-21 13:08:57 +00:00
(AppRoute as any).whyDidYouRender = {
logOnDifferentValues: false,
};
2020-03-11 13:59:46 +00:00
export default AppRoute;