Skip to content

Commit 6571b44

Browse files
committed
[frontend] clean up omnibox and new tab links
1 parent 89d2fce commit 6571b44

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

frontend/src/components/Omnibox.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Spacer.style = css`
3030

3131
type OmniboxResult = {
3232
kind: "search" | "history" | "bookmark" | "direct";
33-
title?: string;
34-
url: string;
33+
title?: string | null;
34+
url: URL;
3535
favicon?: string | null;
3636
};
3737

@@ -61,26 +61,23 @@ export const UrlInput: Component<
6161
for (const entry of browser.globalhistory) {
6262
if (!entry.url.href.includes(search) && !entry.title?.includes(search))
6363
continue;
64-
if (this.overflowItems.some((i) => i.url === entry.url.href)) continue;
64+
if (this.overflowItems.some((i) => i.url.href === entry.url.href))
65+
continue;
6566

6667
this.overflowItems.push({
6768
kind: "history",
6869
title: entry.title,
69-
url: entry.url.href,
70+
url: entry.url,
7071
favicon: entry.favicon,
7172
});
7273
}
7374
this.overflowItems = this.overflowItems.slice(0, 5);
7475

75-
if (
76-
search.startsWith("http:") ||
77-
search.startsWith("https:") ||
78-
search.startsWith("puter:")
79-
) {
76+
if (URL.canParse(search)) {
8077
this.overflowItems = [
8178
{
8279
kind: "direct",
83-
url: search,
80+
url: new URL(search),
8481
},
8582
...this.overflowItems,
8683
];
@@ -101,7 +98,9 @@ export const UrlInput: Component<
10198
this.overflowItems.push({
10299
kind: "search",
103100
title: item,
104-
url: `https://www.google.com/search?q=${encodeURIComponent(item)}`,
101+
url: new URL(
102+
`https://www.google.com/search?q=${encodeURIComponent(item)}`
103+
),
105104
favicon: scramjet.encodeUrl("https://www.google.com/favicon.ico"),
106105
});
107106
}
@@ -118,7 +117,6 @@ export const UrlInput: Component<
118117
}
119118
if (ratelimiting) {
120119
if (currentTimeout) return;
121-
// TODO: why is it using the node types here
122120
currentTimeout = setTimeout(() => {
123121
ratelimiting = false;
124122
fetchSuggestions();
@@ -171,7 +169,7 @@ export const UrlInput: Component<
171169
this.active = false;
172170
this.input.blur();
173171

174-
browser.activetab.pushNavigate(new URL(item.url));
172+
browser.activetab.pushNavigate(item.url);
175173
}}
176174
class:focused={use(this.focusindex).map(
177175
(i) => i - 1 === this.overflowItems.indexOf(item)
@@ -184,7 +182,7 @@ export const UrlInput: Component<
184182
/>
185183
{(item.title && <span class="description">{item.title} - </span>) ||
186184
""}
187-
<span class="url">{item.url}</span>
185+
<span class="url">{trimUrl(item.url)}</span>
188186
</div>
189187
))}
190188
</div>
@@ -212,9 +210,8 @@ export const UrlInput: Component<
212210
if (e.key === "Enter") {
213211
e.preventDefault();
214212
if (this.focusindex > 0) {
215-
// this.value = this.overflowItems[this.focusindex - 1].;
216213
browser.activetab.pushNavigate(
217-
new URL(this.overflowItems[this.focusindex - 1].url)
214+
this.overflowItems[this.focusindex - 1].url
218215
);
219216
this.active = false;
220217
this.input.blur();

frontend/src/pages/NewTabPage.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { css, type Component } from "dreamland/core";
22
import type { Tab } from "../Tab";
33
import { browser } from "../main";
4+
import { trimUrl } from "../components/Omnibox";
45

56
export const NewTabPage: Component<
67
{
@@ -27,7 +28,7 @@ export const NewTabPage: Component<
2728
<div class="circle">
2829
<img src={entry.favicon || "/vite.svg"} alt="favicon" />
2930
</div>
30-
<span class="title">{entry.title || entry.url.href}</span>
31+
<span class="title">{entry.title || trimUrl(entry.url)}</span>
3132
</div>
3233
))}
3334
</div>
@@ -53,10 +54,12 @@ NewTabPage.style = css`
5354
}
5455
5556
.suggestion {
57+
cursor: pointer;
5658
display: flex;
5759
flex-direction: column;
5860
align-items: center;
5961
gap: 0.5em;
62+
width: 6em;
6063
}
6164
.circle {
6265
width: 64px;
@@ -68,6 +71,13 @@ NewTabPage.style = css`
6871
justify-content: center;
6972
align-items: center;
7073
}
74+
.title {
75+
width: 100%;
76+
text-overflow: ellipsis;
77+
text-align: center;
78+
overflow: hidden;
79+
white-space: nowrap;
80+
}
7181
.suggestion img {
7282
width: 32px;
7383
height: 32px;

0 commit comments

Comments
 (0)