Skip to content

Commit b44b2c5

Browse files
committed
[frontend] show bookmarks only on newtab and fix context menu event bug
1 parent 06ad7b2 commit b44b2c5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

frontend/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export const App: Component = function (cx) {
2222
}}
2323
/>
2424
<Omnibox tab={use(browser.activetab)} />
25-
<BookmarksStrip />
25+
{use(browser.activetab.url)
26+
.map((u) => u.href === "puter://newtab")
27+
.andThen(<BookmarksStrip />)}
2628
{cx.children}
2729
</div>
2830
);

frontend/src/components/Menu.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ export const Menu: Component<{
66
y: number;
77
items: { label: string; action?: () => void }[];
88
}> = function (cx) {
9-
const close = (e: MouseEvent) => {
9+
const close = () => {
1010
cx.root.remove();
1111
browser.unfocusframes = false;
12+
};
13+
14+
const ev = (e: MouseEvent) => {
15+
// Don't close if the click is over the menu
16+
if (cx.root.contains(e.target as Node)) {
17+
return;
18+
}
1219

20+
close();
1321
e.stopImmediatePropagation();
1422
e.preventDefault();
1523
};
@@ -23,8 +31,8 @@ export const Menu: Component<{
2331
if (this.x > maxX) this.x = maxX;
2432
if (this.y > maxY) this.y = maxY;
2533

26-
window.addEventListener("click", close, { once: true, capture: true });
27-
window.addEventListener("contextmenu", close, {
34+
window.addEventListener("click", ev, { once: true, capture: true });
35+
window.addEventListener("contextmenu", ev, {
2836
once: true,
2937
capture: true,
3038
});
@@ -39,7 +47,7 @@ export const Menu: Component<{
3947
<button
4048
on:click={(e: MouseEvent) => {
4149
item.action?.();
42-
close(e);
50+
close();
4351
e.stopPropagation();
4452
}}
4553
>

0 commit comments

Comments
 (0)