Skip to content

Commit 2a62489

Browse files
committed
bug: no clean state before rendering
1 parent 1182f2e commit 2a62489

File tree

6 files changed

+119
-45
lines changed

6 files changed

+119
-45
lines changed

src/components/vertical-nav/index.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import './styles.css';
22
import {trackBreadcrumbs} from "./breadcrumbs-nav.ts";
3+
import {EventBus} from "../../event-bus";
4+
import {Events} from "../../consts/events";
5+
import {handlers} from "../../consts/handlers";
36

47
import cdIcon from "/img/common/cd_icon_green.png";
58
import githubIcon from "./assets/github-icon.svg";
69
import linkedIcon from "./assets/linkedin-icon.svg";
710
import instagramIcon from "./assets/instagram-icon.svg";
11+
import {TankInfo, TankView} from "../../content/projects/tank";
12+
import {SpaceCompassInfo, SpaceCompassView} from "../../content/projects/space-compass";
13+
14+
const EVENT_BUS = new EventBus<Events>();
15+
EVENT_BUS.subscribe('breadcrumb_button', handlers.breadcrumb_button);
816

917
const navTitle = "CD-BASH";
1018
const githubProfile: string = "https://github.com/CD-BASH"
@@ -37,40 +45,41 @@ export function buildVerticalNav() {
3745
navBox.appendChild(header());
3846
navBox.appendChild(navWrapper);
3947
navWrapper.appendChild(trackBreadcrumbs());
48+
navBox.appendChild(testButtons());
4049
navBox.appendChild(footer());
4150

4251
return navBox;
4352
}
4453

4554
export function renderNavInfo(infoFn: Function) {
46-
const wrapper = clearInfo();
55+
const navWrapper = clearInfo();
4756
const info = infoFn();
4857

49-
wrapper?.appendChild(info);
58+
navWrapper?.appendChild(info);
5059
}
5160

5261
//-----------------------------------------------------------------------
5362

5463
function header() {
5564
const container = document.createElement("div");
5665
const topTriangle = document.createElement("div");
57-
const info = document.createElement("div");
66+
const logo = document.createElement("div");
5867
const icon = document.createElement("img");
5968
const title = document.createElement("h5");
6069

6170
container.className = "header";
6271
topTriangle.className = "top-triangle";
6372

64-
info.className = "info";
73+
logo.className = "info";
6574
icon.className = "icon";
6675
icon.src = cdIcon;
6776

6877
title.textContent = navTitle;
6978

7079
container.appendChild(topTriangle);
71-
container.appendChild(info);
72-
info.appendChild(icon);
73-
info.appendChild(title);
80+
container.appendChild(logo);
81+
logo.appendChild(icon);
82+
logo.appendChild(title);
7483

7584
return container;
7685
}
@@ -112,7 +121,36 @@ function clearInfo() {
112121
const cleanInfo = document.getElementById('nav-wrapper');
113122
cleanInfo?.childNodes.forEach((childNode) => {
114123
cleanInfo.removeChild(childNode);
124+
console.log("hi");
115125
});
116126

127+
console.log(cleanInfo);
128+
117129
return cleanInfo;
130+
}
131+
132+
133+
134+
function testButtons() {
135+
const buttonContainer = document.createElement("div");
136+
const buttonA = document.createElement("button");
137+
const buttonB = document.createElement("button");
138+
139+
buttonContainer.className = "button-container";
140+
141+
buttonA.id = "button-a";
142+
buttonA.className = "button";
143+
buttonA.textContent = "Button A";
144+
buttonB.id = "button-b";
145+
buttonB.className = "button";
146+
buttonB.textContent = "Button B";
147+
148+
149+
buttonA.addEventListener('click', () => EVENT_BUS.dispatch('breadcrumb_button', {path: "Button A", projectName: "TANK", projectView: TankView, projectInfo: TankInfo}));
150+
buttonB.addEventListener('click', () => EVENT_BUS.dispatch('breadcrumb_button', {path: "Button B", projectName: "Space Compass", projectView: SpaceCompassView, projectInfo: SpaceCompassInfo}));
151+
152+
buttonContainer.appendChild(buttonA);
153+
buttonContainer.appendChild(buttonB);
154+
155+
return buttonContainer;
118156
}

src/consts/events/events.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
};
55

66
readonly breadcrumb_button: {
7-
7+
readonly path: string;
8+
readonly projectName: string;
9+
readonly projectView: Function;
10+
readonly projectInfo: Function;
811
}
912
};

src/consts/handlers/handlers.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,19 @@ export const handlers = {
44
button_test: (value: Events['button_test']): void => {
55
console.log(value);
66
},
7+
8+
breadcrumb_button: (value: Events['breadcrumb_button']): void => {
9+
console.log(value.projectName);
10+
11+
if (value.projectName == "TANK") {
12+
console.log("indeed this is tank");
13+
}
14+
15+
value.projectView();
16+
value.projectInfo();
17+
18+
if (value.projectName == "Space Compass") {
19+
console.log("this one is space compass");
20+
}
21+
}
722
};

src/content/projects/space-compass/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {projectView} from "../../../views/project-view";
22
import {ProjectContent} from "../../../views/project-view";
3+
import {AboutProject, projectInfo, RelatedLinks} from "../../../components/vertical-nav/project-nav.ts";
34

45
import WEBM_VIDEO from "./assets/spaceCompass-showcase.webm";
56
import MP4_VIDEO from "./assets/spaceCompass-showcase.mp4";
@@ -9,10 +10,11 @@ import SCREENSHOT_2 from "./assets/spaceCompass-screenshot-2.jpg"
910
import SCREENSHOT_3 from "./assets/spaceCompass-screenshot-3.jpg"
1011
import SCREENSHOT_4 from "./assets/spaceCompass-screenshot-4.jpg"
1112

13+
1214
const content: ProjectContent = {
1315
name: "Space Compass",
1416
tagline: "A 360 Odyssey",
15-
path: "www.charlesdouce.com/interactives/",
17+
path: "www.charlesdoucet.com/interactive/",
1618

1719
paragraphs: [
1820
"The core goal in the making of Space Compass was to end up with a playable game in short delays. A bit like a personal game jam! The game is a space shooter, where players’ movement is limited around a circle’s circumference. Player needs to dodge or destroy several asteroids, as well as some structures in the way.",
@@ -32,6 +34,23 @@ const content: ProjectContent = {
3234
]
3335
}
3436

35-
export function ProjectPage() {
37+
const aboutInfo: AboutProject = {
38+
release: "March 20, 2020",
39+
platforms: "Web, Windows, Mac",
40+
developer: "Charles Doucet"
41+
}
42+
43+
const relatedLinksInfo: RelatedLinks[] = [
44+
["Process Journal", "https://github.com/charlesDouc/CART-415/wiki"],
45+
["GitHub Project", "https://github.com/charlesDouc/CART-415/wiki"]
46+
]
47+
48+
//-----------------------------------------------------------------------
49+
50+
export function SpaceCompassView() {
3651
return projectView(content);
3752
}
53+
54+
export function SpaceCompassInfo() {
55+
return projectInfo(aboutInfo, relatedLinksInfo);
56+
}

src/event-bus/event-bus.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/event-bus/index.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
export * from "./event-bus";
1+
type EventMap = Record<string, unknown>;
2+
type EventKey<T extends EventMap> = keyof T;
3+
type EventHandler<T> = (value: T) => void;
4+
5+
export class EventBus<T extends EventMap> {
6+
private subscribers: Partial<Record<keyof T, EventHandler<any>[]>> = {};
7+
8+
subscribe<E extends EventKey<T>>(event: E, handler: EventHandler<T[E]>): void {
9+
if (!this.subscribers[event]) {
10+
this.subscribers[event] = [];
11+
}
12+
13+
this.subscribers[event].push(handler);
14+
}
15+
16+
unsubscribe<E extends EventKey<T>>(event: E, handler: EventHandler<T[E]>): void {
17+
if (!this.subscribers[event]) {
18+
return;
19+
}
20+
21+
this.subscribers[event] = this.subscribers[event]!.filter(
22+
(listener) => listener !== handler
23+
);
24+
}
25+
26+
dispatch<E extends EventKey<T>>(event: E, value: T[E]): void {
27+
if (!this.subscribers[event]) {
28+
return;
29+
}
30+
this.subscribers[event]!.forEach((listener) => {
31+
listener(value);
32+
});
33+
}
34+
}

0 commit comments

Comments
 (0)