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 6 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
1 change: 1 addition & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
} @else {
<app-start></app-start>
}

1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class AppComponent {
private matIconRegistry: MatIconRegistry,
private domSanitizer: DomSanitizer,
) {

this.matIconRegistry.addSvgIcon(
"block",
this.domSanitizer.bypassSecurityTrustResourceUrl(
Expand Down
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 { 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 @@
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.replace('"', ""),
Fixed Show fixed Hide fixed
);

document.getElementsByTagName("body")[0].setAttribute(
"data-bs-theme",
theme.replace('"', ""),
Fixed Show fixed Hide fixed
);

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 @@
this.localStorage.store("releaseVersion", releaseVersion);

const robotId = this.localStorage.fetch("changedLanguage");
console.log(robotId);
if (robotId) {
this.localStorage.store("changedLanguage", "");
this.workspaceService
Expand Down
180 changes: 98 additions & 82 deletions src/app/effects/blockly-editor.effects.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { Injectable } from "@angular/core";
import { BlocklyEditorState } from "../state/blockly-editor.state";
import { filter, pairwise, withLatestFrom } from "rxjs/operators";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { combineLatest, Observable } from "rxjs";
import { AppState } from "../state/app.state";
import { CodeEditorType } from "../domain/code-editor.type";
import {Injectable} from "@angular/core";
import {BlocklyEditorState} from "../state/blockly-editor.state";
import {filter, pairwise, withLatestFrom} from "rxjs/operators";
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {combineLatest, Observable} from "rxjs";
import {AppState} from "../state/app.state";
import {CodeEditorType} from "../domain/code-editor.type";
import * as Blockly from "blockly";
import "@blockly/field-bitmap";

import {
arduino,
CATEGORIES,
THEME,
constantBlocks,
EXTENSIONS,
translations,
arduino,
getBlocks,
constantBlocks,
translations,
} from "@leaphy-robotics/leaphy-blocks";
import { LeaphyCategory } from "../services/toolbox/category";
import { LeaphyToolbox } from "../services/toolbox/toolbox";
import { CodeEditorState } from "../state/code-editor.state";
import { genericRobotType, microPythonRobotType } from "../domain/robots";
import { RobotType } from "../domain/robot.type";
import { WorkspaceService } from "../services/workspace.service";
import { LocalStorageService } from "../services/localstorage.service";
import {LeaphyCategory} from "../services/blockly/category";
import {LeaphyToolbox} from "../services/blockly/toolbox";
import {CodeEditorState} from "../state/code-editor.state";
import {genericRobotType, microPythonRobotType} from "../domain/robots";
import {RobotType} from "../domain/robot.type";
import {WorkspaceService} from "../services/workspace.service";
import {LocalStorageService} from "../services/localstorage.service";
import getTheme from "../services/blockly/theme";

@Injectable({
providedIn: "root",
Expand All @@ -32,6 +32,69 @@ import { LocalStorageService } from "../services/localstorage.service";
// 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) {
let allBlocks = getBlocks(robotType.id).block;
if (this.firstRun) {
this.firstRun = false;
allBlocks = allBlocks.concat(constantBlocks);
}

Blockly.defineBlocksWithJsonArray(allBlocks);

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 @@ -41,6 +104,10 @@ export class BlocklyEditorEffects {
private workspaceService: WorkspaceService,
private localStorage: LocalStorageService,
) {
this.getXmlContent("./assets/blockly/leaphy-start.xml").subscribe(
(xml) => (this.startWorkspaceXml = xml),
);

Blockly.registry.register(
Blockly.registry.Type.TOOLBOX_ITEM,
Blockly.ToolboxCategory.registrationName,
Expand Down Expand Up @@ -120,65 +187,18 @@ 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(
([
[[element, config], robotType],
baseToolboxXml,
leaphyToolboxXml,
startWorkspaceXml,
]) => {
let allBlocks = getBlocks(robotType.id).block;
if (this.firstRun) {
this.firstRun = false;
allBlocks = allBlocks.concat(constantBlocks);
}

Blockly.defineBlocksWithJsonArray(allBlocks);
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,
);
},
);
async ([
[[element, config], robotType],
baseToolboxXml,
leaphyToolboxXml,
]) => {
this.baseToolboxXml = baseToolboxXml;
this.leaphyToolboxXml = leaphyToolboxXml;
await this.loadBlockly(element, robotType, config);
});

// When a new project is started, reset the blockly code
this.appState.selectedRobotType$
Expand All @@ -205,12 +225,9 @@ export class BlocklyEditorEffects {
leaphyToolboxXml,
startWorkspaceXml,
]) => {
const toolboxXmlString = this.loadToolBox(
baseToolboxXml,
leaphyToolboxXml,
this.blocklyState.toolboxXml = this.loadToolBox(
robotType,
);
this.blocklyState.toolboxXml = toolboxXmlString;

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


private loadToolBox(
baseToolboxXml: string,
leaphyToolboxXml: string,
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
3 changes: 2 additions & 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,8 @@

.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,20 @@ import { CodeEditorState } from "../../../../state/code-editor.state";
styleUrls: ["./code-view.component.scss"],
})
export class CodeViewComponent {
editorOptions = {
editorOptions : any = {
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",
};
}
}
}
31 changes: 29 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,41 @@ 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
Loading
Loading