Skip to content

Commit 7ca2182

Browse files
committed
[frontend] add results from google autocomplete api
1 parent da42193 commit 7ca2182

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

frontend/src/Omnibox.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import iconShield from "@ktibow/iconset-material-symbols/shield";
1010
import iconStar from "@ktibow/iconset-material-symbols/star";
1111
import iconSearch from "@ktibow/iconset-material-symbols/search";
1212
import { createMenu } from "./Menu";
13+
import { client } from "./main";
1314

1415
export const Spacer: Component = function (cx) {
1516
return <div></div>;
@@ -23,13 +24,41 @@ Spacer.css = `
2324
export const UrlInput: Component<
2425
{},
2526
{
27+
value: string;
2628
active: boolean;
2729
input: HTMLInputElement;
2830

2931
overflowItems: string[];
3032
}
3133
> = function (cx) {
34+
this.value = "";
3235
this.overflowItems = ["test", "test2", "test3", "test4", "test5"];
36+
const fetchSuggestions = async () => {
37+
console.log("fetched");
38+
let resp = await client.fetch(
39+
`http://suggestqueries.google.com/complete/search?client=firefox&q=${encodeURIComponent(this.input.value)}`
40+
);
41+
let json = await resp.json();
42+
console.log(json);
43+
this.overflowItems = json[1].slice(0, 5);
44+
};
45+
let currentTimeout: number | null = null;
46+
let ratelimiting = false;
47+
let interval = 100;
48+
use(this.value).listen(() => {
49+
if (ratelimiting) {
50+
if (currentTimeout) return;
51+
// TODO: why is it using the node types here
52+
currentTimeout = setTimeout(() => {
53+
ratelimiting = false;
54+
fetchSuggestions();
55+
currentTimeout = null;
56+
}, interval);
57+
} else {
58+
ratelimiting = true;
59+
fetchSuggestions();
60+
}
61+
});
3362
return (
3463
<div
3564
on:click={(e: MouseEvent) => {
@@ -61,7 +90,13 @@ export const UrlInput: Component<
6190
</div>
6291
<div class="realbar">
6392
<IconButton icon={iconShield}></IconButton>
64-
<input this={use(this.input).bind()}></input>
93+
<input
94+
this={use(this.input).bind()}
95+
value={use(this.value).bind()}
96+
on:input={(e: InputEvent) => {
97+
this.value = (e.target as HTMLInputElement).value;
98+
}}
99+
></input>
65100

66101
<IconButton icon={iconStar}></IconButton>
67102
</div>

frontend/src/main.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import "./style.css";
33
import { createBrowser } from "./browser";
44
import { createMenu } from "./Menu";
55
let app = document.getElementById("app")!;
6+
import { BareMuxConnection, BareClient } from "@mercuryworkshop/bare-mux";
7+
8+
let connection = new BareMuxConnection("/baremux/worker.js");
9+
connection.setTransport("/epoxy/index.mjs", [{ wisp: "wss://anura.pro" }]);
10+
export let client = new BareClient();
11+
console.log(client);
612

713
let browser = createBrowser();
814
(self as any).browser = browser;

frontend/vite.config.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { defineConfig } from "vite";
2+
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
3+
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
4+
console.log(epoxyPath, baremuxPath);
25

36
export default defineConfig({
4-
// plugins: [
5-
// {
6-
// name: "dreamland",
7-
// handleHotUpdate(ctx) {
8-
// console.log(ctx.modules);
9-
// ctx.server.ws.send({
10-
// type: "custom",
11-
// event: "special-update",
12-
// data: {
13-
// file: ctx.file,
14-
// },
15-
// });
16-
// return [];
17-
// },
18-
// },
19-
// ],
7+
plugins: [
8+
{
9+
name: "static-files",
10+
configureServer(server) {
11+
server.middlewares.use((req, res, next) => {
12+
if (req.url.startsWith("/epoxy/")) {
13+
req.url = req.url.replace("/epoxy/", epoxyPath + "/");
14+
} else if (req.url.startsWith("/baremux/")) {
15+
req.url = req.url.replace("/baremux/", baremuxPath + "/");
16+
}
17+
next();
18+
});
19+
},
20+
},
21+
],
2022
});

0 commit comments

Comments
 (0)