Skip to content

Commit 4449b25

Browse files
committed
[frontend] fix history (almost)
1 parent 7247d12 commit 4449b25

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

dreamlandjs

frontend/src/Tab.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export class Tab extends StatefulClass {
1919

2020
history: History;
2121

22+
canGoForward: boolean = false;
23+
canGoBack: boolean = false;
24+
2225
constructor(public url: URL = new URL("puter://newtab")) {
2326
super(createState(Object.create(Tab.prototype)));
2427

frontend/src/browser.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Browser extends StatefulClass {
4848
};
4949
}
5050

51-
newTab(title: string) {
51+
newTab() {
5252
let tab = new Tab();
5353
pushTab(tab);
5454
this.tabs = [...this.tabs, tab];
@@ -60,18 +60,15 @@ export class Browser extends StatefulClass {
6060
this.tabs = this.tabs.filter((t) => t !== tab);
6161
console.log(this.tabs);
6262
if (this.activetab === tab) {
63-
this.activetab = this.tabs[0] || this.newTab("New Tab");
63+
this.activetab = this.tabs[0] || this.newTab();
6464
}
65-
console.log(this.tabs);
66-
67-
console.log(this.activetab);
6865
popTab(tab);
6966
}
7067

7168
build(): HTMLElement {
7269
let shell = <Shell tabs={use(this.tabs)} activetab={use(this.activetab)} />;
7370

74-
let tab = this.newTab("title");
71+
let tab = this.newTab();
7572
this.activetab = tab;
7673
if (this.built) throw new Error("already built");
7774
this.built = true;
@@ -83,13 +80,14 @@ export class Browser extends StatefulClass {
8380
tabs={use(this.tabs).bind()}
8481
activetab={use(this.activetab).bind()}
8582
destroyTab={(tab) => this.destroyTab(tab)}
86-
addTab={() => this.newTab("title")}
83+
addTab={() => this.newTab()}
8784
/>
8885
<Omnibox
89-
tabUrl={use(this.activetab)
90-
.zip(use(this.activetab.url))
91-
.map(([a]) => use(a.url))}
86+
tabUrl={use(this.activetab.url)}
87+
canGoBack={use(this.activetab.canGoBack)}
88+
canGoForwards={use(this.activetab.canGoForward)}
9289
goBack={() => {
90+
console.log("WHAT");
9391
this.activetab.history.go(-1);
9492
}}
9593
goForwards={() => {

frontend/src/components/IconButton.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import { Icon } from "./Icon";
55
export const IconButton: Component<{
66
icon: IconifyIcon;
77
click?: (e: MouseEvent) => void;
8+
active?: boolean;
89
}> = function (cx) {
10+
this.active ??= true;
911
return (
10-
<button on:click={(e) => this.click?.(e)}>
12+
<button
13+
disabled={use(this.active).map((x) => (x ? undefined : true))}
14+
class:active={use(this.active)}
15+
on:click={(e) => this.click?.(e)}
16+
>
1117
<Icon icon={this.icon} />
1218
</button>
1319
);
@@ -19,8 +25,11 @@ IconButton.css = `
1925
outline: none;
2026
border: none;
2127
font-size: 1.25em;
22-
background: inerhit
23-
# background: var(--aboutbrowser-toolbar-bg);
28+
background: none;
29+
color: grey;
30+
}
31+
:scope.active {
2432
cursor: pointer;
33+
color: var(--aboutbrowser-active-tab-fg);
2534
}
2635
`;

frontend/src/components/Omnibox.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,21 @@ export const Omnibox: Component<{
236236
goBack: () => void;
237237
goForwards: () => void;
238238
refresh: () => void;
239+
canGoBack: boolean;
240+
canGoForwards: boolean;
239241
}> = function (cx) {
240242
return (
241243
<div>
242-
<IconButton click={this.goBack} icon={iconBack}></IconButton>
243-
<IconButton click={this.goForwards} icon={iconForwards}></IconButton>
244+
<IconButton
245+
active={use(this.canGoBack)}
246+
click={this.goBack}
247+
icon={iconBack}
248+
></IconButton>
249+
<IconButton
250+
active={use(this.canGoForwards)}
251+
click={this.goForwards}
252+
icon={iconForwards}
253+
></IconButton>
244254
<IconButton click={this.refresh} icon={iconRefresh}></IconButton>
245255
<Spacer></Spacer>
246256
<UrlInput tabUrl={use(this.tabUrl)} navigate={this.navigate}></UrlInput>

frontend/src/history.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type HistoryState = {
77
};
88

99
export class History {
10-
index: number = 0;
10+
index: number = -1;
1111
states: HistoryState[] = [];
1212

1313
constructor(private tab: Tab) {}
@@ -18,6 +18,9 @@ export class History {
1818

1919
if (navigate) this.tab.navigate(url);
2020

21+
this.tab.canGoBack = this.canGoBack();
22+
this.tab.canGoForward = this.canGoForward();
23+
2124
return this.states[this.index];
2225
}
2326
replace(url: URL, state: any, navigate: boolean = true): HistoryState {
@@ -29,6 +32,9 @@ export class History {
2932

3033
if (navigate) this.tab.navigate(url);
3134

35+
this.tab.canGoBack = this.canGoBack();
36+
this.tab.canGoForward = this.canGoForward();
37+
3238
return this.states[this.index];
3339
}
3440
go(delta: number, navigate: boolean = true): HistoryState {
@@ -41,6 +47,9 @@ export class History {
4147

4248
if (navigate) this.tab.navigate(this.states[this.index].url);
4349

50+
this.tab.canGoBack = this.canGoBack();
51+
this.tab.canGoForward = this.canGoForward();
52+
4453
return this.states[this.index];
4554
}
4655
canGoBack(): boolean {

0 commit comments

Comments
 (0)