Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

chore: add Dark mode + some rewrites #248

Merged
merged 31 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
34d2f93
chore: start on scss rewrite
koen1711 Apr 23, 2024
337925e
Merge branch 'main' into theme-rewrite
koen1711 Apr 23, 2024
bb1378a
chore: rewrite done, added themes
koen1711 Apr 23, 2024
462a968
chore: almost done with themes
koen1711 Apr 23, 2024
2bfc12f
chore: almost done with themes....
koen1711 Apr 24, 2024
0cd11e4
chore: finished themes
koen1711 Apr 24, 2024
1c22702
Merge branch 'main' into theme-rewrite
koen1711 Apr 24, 2024
7a2b319
chore: fix other merge conflicts
koen1711 Apr 24, 2024
220048a
fix: make CONNECT_PYTHON_ROBOT button primary
koen1711 Apr 24, 2024
98f1921
chore: prettier
koen1711 Apr 24, 2024
c44ac12
chore: fix some mistakes
koen1711 Apr 24, 2024
b8f5897
chore: fix select color
koen1711 Apr 24, 2024
f6c2199
chore: fix all issues
koen1711 Apr 24, 2024
8fa7d34
chore: fix last issues
koen1711 Apr 24, 2024
6c487d8
chore: prettier
koen1711 Apr 24, 2024
8717f70
fix: oops
koen1711 Apr 24, 2024
e693b40
chore: fix last issues... (again)
koen1711 Apr 25, 2024
40a8731
chore: prettier
koen1711 Apr 25, 2024
417cdb1
fix: more contrast to file explorer names
koen1711 Apr 25, 2024
f98175c
chore: fix color of second selection screen
koen1711 Apr 25, 2024
cb1150d
chore: last header border color
koen1711 Apr 25, 2024
8f8a478
chore: last few styling issues
koen1711 Apr 25, 2024
b0ec423
chore: prettier
koen1711 Apr 25, 2024
8db6691
fix: oops
koen1711 Apr 25, 2024
e6dc7bb
fix: modal -> dialog
koen1711 Apr 25, 2024
076a021
chore: remove change of color on file explorer
koen1711 Apr 25, 2024
35a7317
fix: background overrides all props, also when none
koen1711 Apr 26, 2024
22a12a1
fix: duplicate keys
koen1711 Apr 26, 2024
6661b9a
chore: fix last styling issue
koen1711 Apr 26, 2024
32bb3fd
chore: prettier
koen1711 Apr 26, 2024
1c72627
fix: change text color of upload log
koen1711 Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/app/effects/app.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MatDialog } from "@angular/material/dialog";
import { ChangeLogDialog } from "../modules/core/dialogs/change-log/change-log.dialog";
import showdown from "showdown";
import { WorkspaceService } from "../services/workspace.service";
import { BlocklyEditorEffects } from "./blockly-editor.effects";

@Injectable({
providedIn: "root",
Expand All @@ -21,7 +22,29 @@ export class AppEffects {
private localStorage: LocalStorageService,
private dialog: MatDialog,
private workspaceService: WorkspaceService,
private blocklyEffects: BlocklyEditorEffects,
) {
this.appState.selectedTheme = localStorage.fetch("theme") || "light";

this.appState.selectedTheme$
.pipe(filter((theme) => !!theme))
.subscribe((theme) => {
document
.getElementsByTagName("body")[0]
.setAttribute("data-theme", theme);

document
.getElementsByTagName("body")[0]
.setAttribute("data-bs-theme", theme);

localStorage.store("theme", theme);
if (
this.appState.selectedCodeEditor == CodeEditorType.Beginner
) {
this.blocklyEffects.loadTheme();
}
});

// Use the current language to translate the angular strings
this.appState.currentLanguage$
.pipe(filter((language) => !!language))
Expand Down Expand Up @@ -137,7 +160,6 @@ export class AppEffects {
this.localStorage.store("releaseVersion", releaseVersion);

const robotId = this.localStorage.fetch("changedLanguage");
console.log(robotId);
if (robotId) {
this.localStorage.store("changedLanguage", "");
this.workspaceService
Expand Down
151 changes: 81 additions & 70 deletions src/app/effects/blockly-editor.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import {
blocks,
CATEGORIES,
EXTENSIONS,
THEME,
translations,
} from "@leaphy-robotics/leaphy-blocks";
import { LeaphyCategory } from "../services/toolbox/category";
import { LeaphyToolbox } from "../services/toolbox/toolbox";
import { LeaphyCategory } from "../services/blockly/category";
import { LeaphyToolbox } from "../services/blockly/toolbox";
import { CodeEditorState } from "../state/code-editor.state";
import {
genericRobotType,
Expand All @@ -28,6 +27,7 @@ import { RobotType } from "../domain/robot.type";
import { WorkspaceService } from "../services/workspace.service";
import { LocalStorageService } from "../services/localstorage.service";
import PinSelectorField from "../domain/blockly-fields";
import getTheme from "../services/blockly/theme";

@Injectable({
providedIn: "root",
Expand All @@ -36,6 +36,72 @@ import PinSelectorField from "../domain/blockly-fields";
// Defines the effects on the Blockly Editor that different state changes have
export class BlocklyEditorEffects {
private firstRun = true;
private startWorkspaceXml = ``;
private baseToolboxXml = ``;
private leaphyToolboxXml = ``;

private readonly darkTheme = getTheme("dark");
private readonly lightTheme = getTheme("light");

public async loadTheme() {
const workspace = this.blocklyState.workspace;
const darkMode =
document
.getElementsByTagName("body")[0]
.getAttribute("data-theme") === "dark";
const blocklyTheme = darkMode ? this.darkTheme : this.lightTheme;
workspace.setTheme(blocklyTheme);
workspace.refreshTheme();
}

public async loadBlockly(
element,
robotType: RobotType,
config: Blockly.BlocklyOptions,
) {
const translation = translations[this.appState.currentLanguageCode];
if (robotType === leaphyFlitzNanoRobotType)
translation.ARD_SERVO_WRITE = translation.ARD_SERVO_ARM_WRITE;
else translation.ARD_SERVO_WRITE = translation.ARD_SERVO_REGULAR_WRITE;

Blockly.setLocale(translation);

PinSelectorField.processPinMappings(robotType);
if (this.firstRun) {
this.firstRun = false;
Blockly.defineBlocksWithJsonArray(blocks);
}

const toolboxXmlString = this.loadToolBox(robotType);
config.toolbox = toolboxXmlString;
// @ts-ignore
const workspace = Blockly.inject(element, config);
const darkMode =
document
.getElementsByTagName("body")[0]
.getAttribute("data-theme") === "dark";
const blocklyTheme = darkMode ? this.darkTheme : this.lightTheme;
workspace.setTheme(blocklyTheme);
const toolbox = workspace.getToolbox();
workspace.registerToolboxCategoryCallback("LISTS", CATEGORIES.LISTS);
toolbox.getFlyout().autoClose = false;
const xml = Blockly.utils.xml.textToDom(this.startWorkspaceXml);
Blockly.Xml.domToWorkspace(xml, workspace);
this.blocklyState.workspace = workspace;
this.blocklyState.toolboxXml = toolboxXmlString;
if (this.appState.currentEditor == CodeEditorType.Beginner) {
this.workspaceService.restoreWorkspaceTemp().then(() => {});
}
toolbox.selectItemByPosition(0);
toolbox.refreshTheme();

setTimeout(
() =>
(this.blocklyState.isSideNavOpen =
robotType.features.showCodeOnStart),
200,
);
}

constructor(
private blocklyState: BlocklyEditorState,
Expand All @@ -45,6 +111,10 @@ export class BlocklyEditorEffects {
private workspaceService: WorkspaceService,
private localStorage: LocalStorageService,
) {
this.getXmlContent("./assets/blockly/leaphy-start.xml").subscribe(
(xml) => (this.startWorkspaceXml = xml),
);

Blockly.defineBlocksWithJsonArray(blocks);
Blockly.fieldRegistry.register("field_pin_selector", PinSelectorField);
Blockly.registry.register(
Expand Down Expand Up @@ -119,68 +189,17 @@ export class BlocklyEditorEffects {
withLatestFrom(
this.getXmlContent("./assets/blockly/base-toolbox.xml"),
this.getXmlContent("./assets/blockly/leaphy-toolbox.xml"),
this.getXmlContent("./assets/blockly/leaphy-start.xml"),
),
)
.subscribe(
([
async ([
[[element, config], robotType],
baseToolboxXml,
leaphyToolboxXml,
startWorkspaceXml,
]) => {
const translation =
translations[this.appState.currentLanguageCode];
if (robotType === leaphyFlitzNanoRobotType)
translation.ARD_SERVO_WRITE =
translation.ARD_SERVO_ARM_WRITE;
else
translation.ARD_SERVO_WRITE =
translation.ARD_SERVO_REGULAR_WRITE;

Blockly.setLocale(translation);

PinSelectorField.processPinMappings(robotType);
config.theme = Blockly.Theme.defineTheme("leaphy", {
blockStyles: THEME.defaultBlockStyles,
categoryStyles: THEME.categoryStyles,
componentStyles: THEME.componentStyles,
name: "leaphy",
});
const toolboxXmlString = this.loadToolBox(
baseToolboxXml,
leaphyToolboxXml,
robotType,
);
config.toolbox = toolboxXmlString;
// @ts-ignore
const workspace = Blockly.inject(element, config);
const toolbox = workspace.getToolbox();
workspace.registerToolboxCategoryCallback(
"LISTS",
CATEGORIES.LISTS,
);
toolbox.getFlyout().autoClose = false;
const xml = Blockly.utils.xml.textToDom(startWorkspaceXml);
Blockly.Xml.domToWorkspace(xml, workspace);
this.blocklyState.workspace = workspace;
this.blocklyState.toolboxXml = toolboxXmlString;
if (
this.appState.currentEditor == CodeEditorType.Beginner
) {
this.workspaceService
.restoreWorkspaceTemp()
.then(() => {});
}
toolbox.selectItemByPosition(0);
toolbox.refreshTheme();

setTimeout(
() =>
(this.blocklyState.isSideNavOpen =
robotType.features.showCodeOnStart),
200,
);
this.baseToolboxXml = baseToolboxXml;
this.leaphyToolboxXml = leaphyToolboxXml;
await this.loadBlockly(element, robotType, config);
},
);

Expand Down Expand Up @@ -209,11 +228,7 @@ export class BlocklyEditorEffects {
leaphyToolboxXml,
startWorkspaceXml,
]) => {
this.blocklyState.toolboxXml = this.loadToolBox(
baseToolboxXml,
leaphyToolboxXml,
robotType,
);
this.blocklyState.toolboxXml = this.loadToolBox(robotType);

workspace.clear();
const xml = Blockly.utils.xml.textToDom(startWorkspaceXml);
Expand Down Expand Up @@ -338,19 +353,15 @@ export class BlocklyEditorEffects {
return category;
}

private loadToolBox(
baseToolboxXml: string,
leaphyToolboxXml: string,
robotType: RobotType,
): string {
private loadToolBox(robotType: RobotType): string {
const parser = new DOMParser();
const toolboxXmlDoc = parser.parseFromString(
baseToolboxXml,
this.baseToolboxXml,
"text/xml",
);
const toolboxElement = toolboxXmlDoc.getElementById("easyBloqsToolbox");
const leaphyCategories = parser.parseFromString(
leaphyToolboxXml,
this.leaphyToolboxXml,
"text/xml",
);
const leaphyRobotCategory = leaphyCategories.getElementById(
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/blockly-editor/blockly-editor.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

.sidenav-container {
flex: 1 1 auto;
background: #eee;
background: var(--leaphy-background-color);
}

#sidenav {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
height: 100%;
margin: 0;
overflow-x: scroll;
// set the scrollbar color to #9c9a9a
scrollbar-color: #ccc #9c9a9a;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ import { CodeEditorState } from "../../../../state/code-editor.state";
styleUrls: ["./code-view.component.scss"],
})
export class CodeViewComponent {
editorOptions = {
editorOptions: any = {
koen1711 marked this conversation as resolved.
Show resolved Hide resolved
language: "cpp",
readOnly: true,
automaticLayout: true,
};

constructor(public codeEditor: CodeEditorState) {}
constructor(public codeEditor: CodeEditorState) {
// check if we are currently in dark mode
const isDarkMode =
document
.getElementsByTagName("body")[0]
.getAttribute("data-theme") === "dark";
if (isDarkMode) {
this.editorOptions = {
...this.editorOptions,
theme: "vs-dark",
};
}
}
}
29 changes: 27 additions & 2 deletions src/app/modules/code-editor-cpp/code-editor-cpp.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SharedModule } from "../shared/shared.module";
import { CoreModule } from "../core/core.module";
import { WorkspaceService } from "../../services/workspace.service";
import { MonacoEditorModule } from "ngx-monaco-editor-v2";
import { AppState } from "../../state/app.state";

@Component({
standalone: true,
Expand All @@ -14,15 +15,39 @@ import { MonacoEditorModule } from "ngx-monaco-editor-v2";
imports: [CommonModule, SharedModule, CoreModule, MonacoEditorModule],
})
export class CodeEditorCppPage implements AfterViewInit {
editorOptions = {
editorOptions: any = {
koen1711 marked this conversation as resolved.
Show resolved Hide resolved
language: "cpp",
automaticLayout: true,
};

constructor(
public codeEditorState: CodeEditorState,
private workspaceService: WorkspaceService,
) {}
private appState: AppState,
) {
// check if we are currently in dark mode
const isDarkMode = appState.selectedTheme === "dark";
if (isDarkMode) {
this.editorOptions = {
...this.editorOptions,
theme: "vs-dark",
};
}

appState.selectedTheme$.subscribe((theme) => {
if (theme === "dark") {
this.editorOptions = {
...this.editorOptions,
theme: "vs-dark",
};
} else {
this.editorOptions = {
...this.editorOptions,
theme: "vs",
};
}
});
}

ngAfterViewInit(): void {
window.addEventListener("beforeunload", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
height: calc(100% - 64px);
width: 100%;
overflow: hidden;
background-color: var(--leaphy-background-color);
}

.sidenav-container {
Expand Down
Loading
Loading