Skip to content

Commit

Permalink
Fix handling of theme change (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py authored Oct 22, 2024
1 parent 9fde6ed commit 6f4b7e2
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 25 deletions.
8 changes: 1 addition & 7 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { STLLoader } from 'three/examples/jsm/loaders/STLLoader';
import { ViewHelper } from 'three/examples/jsm/helpers/ViewHelper';

import { FloatingAnnotation } from '../annotation';
import { getCSSVariableColor, isLightTheme, throttle } from '../tools';
import { getCSSVariableColor, throttle } from '../tools';
import {
AxeHelper,
CameraSettings,
Expand Down Expand Up @@ -63,7 +63,6 @@ interface IStates {
id: string; // ID of the component, it is used to identify which component
//is the source of awareness updates.
loading: boolean;
lightTheme: boolean;
remoteUser?: User.IIdentity | null;
annotations: IDict<IAnnotation>;
firstLoad: boolean;
Expand Down Expand Up @@ -107,7 +106,6 @@ export class MainView extends React.Component<IProps, IStates> {

this.state = {
id: this._mainViewModel.id,
lightTheme: isLightTheme(),
loading: true,
annotations: {},
firstLoad: true,
Expand Down Expand Up @@ -1435,15 +1433,11 @@ export class MainView extends React.Component<IProps, IStates> {
}

private _handleThemeChange = (): void => {
const lightTheme = isLightTheme();

DEFAULT_MESH_COLOR.set(getCSSVariableColor(DEFAULT_MESH_COLOR_CSS));
DEFAULT_EDGE_COLOR.set(getCSSVariableColor(DEFAULT_EDGE_COLOR_CSS));
BOUNDING_BOX_COLOR.set(getCSSVariableColor(BOUNDING_BOX_COLOR_CSS));

this._clippingPlaneMeshControl.material.color = DEFAULT_MESH_COLOR;

this.setState(old => ({ ...old, lightTheme }));
};

private _handleWindowResize = (): void => {
Expand Down
13 changes: 0 additions & 13 deletions packages/base/src/panelview/objecttree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ interface IStates {
filePath?: string;
jcadObject?: IJCadModel;
options?: JSONObject;
lightTheme: boolean;
selectedNodes: string[];
clientId: number | null; // ID of the yjs client
id: string; // ID of the component, it is used to identify which component
Expand Down Expand Up @@ -142,13 +141,9 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
constructor(props: IProps) {
super(props);

const lightTheme =
document.body.getAttribute('data-jp-theme-light') === 'true';

this.state = {
filePath: this.props.cpModel.filePath,
jcadObject: this.props.cpModel.jcadModel?.getAllObject(),
lightTheme,
selectedNodes: [],
clientId: null,
id: uuid(),
Expand All @@ -160,13 +155,11 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
this.props.cpModel.documentChanged.connect((_, document) => {
if (document) {
this.props.cpModel.disconnect(this._sharedJcadModelChanged);
this.props.cpModel.disconnect(this._handleThemeChange);
this.props.cpModel.disconnect(this._onClientSharedStateChanged);

document.context.model.sharedObjectsChanged.connect(
this._sharedJcadModelChanged
);
document.context.model.themeChanged.connect(this._handleThemeChange);
document.context.model.clientStateChanged.connect(
this._onClientSharedStateChanged
);
Expand Down Expand Up @@ -231,12 +224,6 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
}
}

private _handleThemeChange = (): void => {
const lightTheme =
document.body.getAttribute('data-jp-theme-light') === 'true';
this.setState(old => ({ ...old, lightTheme }));
};

handleNodeClick = (objectId: string) => {
const object = this.getObjectFromName(objectId);

Expand Down
1 change: 0 additions & 1 deletion packages/base/src/sketcher/sketcherwidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,5 @@ export class SketcherReactWidget extends React.Component<IProps, IState> {
private _divRef = React.createRef<HTMLDivElement>();
private _canvasRef = React.createRef<HTMLCanvasElement>();
private _panZoom: PanZoom;
// private _lightTheme =
// document.body.getAttribute('data-jp-theme-light') === 'true';
}
4 changes: 0 additions & 4 deletions packages/base/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,3 @@ export async function requestAPI<T>(

return data;
}

export function isLightTheme(): boolean {
return document.body.getAttribute('data-jp-theme-light') === 'true';
}

0 comments on commit 6f4b7e2

Please sign in to comment.