Skip to content

Commit 4b977cf

Browse files
chore: improve web responsiveness
Signed-off-by: Henry Gressmann <[email protected]>
1 parent e20eddf commit 4b977cf

File tree

18 files changed

+188
-127
lines changed

18 files changed

+188
-127
lines changed

Cargo.lock

Lines changed: 62 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/licenses-npm.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/web/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ pub(crate) async fn start_webserver(app: Liwan, events: Sender<Event>) -> Result
6565
.appending("X-XSS-Protection", "1; mode=block")
6666
.appending("Content-Security-Policy", "default-src 'self' data: 'unsafe-inline'")
6767
.appending("Referrer-Policy", "same-origin")
68-
.appending("Feature-Policy", "geolocation 'none'; microphone 'none'; camera 'none'")
69-
.appending("Permissions-Policy", "geolocation=(), microphone=(), camera=(), interest-cohort=()");
68+
.appending("Permissions-Policy", "geolocation=(), microphone=(), camera=()");
7069

7170
let api_router = Route::new()
7271
.nest_no_strip("/event", handle_events)

src/web/webext.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,16 @@ impl<E: RustEmbed + Send + Sync> Endpoint for EmbeddedFilesEndpoint<E> {
137137

138138
// otherwise, return 200 with etag hash
139139
let body: Vec<u8> = content.data.into();
140-
let mime = mime_guess::from_path(path).first_or_octet_stream();
141-
Ok(Response::builder()
142-
.header(header::CONTENT_TYPE, mime.as_ref())
143-
.header(header::ETAG, hash)
144-
.body(body))
140+
let mime = mime_guess::from_path(&path).first_or_octet_stream();
141+
142+
let mut builder =
143+
Response::builder().header(header::CONTENT_TYPE, mime.as_ref()).header(header::ETAG, hash);
144+
145+
if path.starts_with("_astro/") {
146+
builder = builder.header(header::CACHE_CONTROL, "public, max-age=604800, immutable");
147+
}
148+
149+
Ok(builder.body(body))
145150
}
146151
None => Err(StatusCode::NOT_FOUND.into()),
147152
}

web/astro.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export default defineConfig({
2727
template: (dependencies) => JSON.stringify(dependencies),
2828
},
2929
},
30-
}),
30+
// biome-ignore lint/suspicious/noExplicitAny: type is correct
31+
}) as any,
3132
],
3233
},
3334
integrations: [react()],

web/bun.lockb

5.09 KB
Binary file not shown.

web/package.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
{
22
"name": "liwan-web",
3-
"type": "module",
43
"version": "0.0.1",
4+
"type": "module",
55
"scripts": {
6-
"dev": "bun run --bun astro dev",
76
"build": "bun run --bun astro build",
7+
"dev": "bun run --bun astro dev",
88
"preview": "bun run --bun astro preview",
99
"typecheck": "bun run --bun tsc --noEmit"
1010
},
1111
"dependencies": {
1212
"@astrojs/react": "^3.6.2",
1313
"@explodingcamera/css": "^0.0.4",
14-
"@fontsource-variable/figtree": "^5.0.21",
14+
"@fontsource-variable/figtree": "^5.0.22",
1515
"@icons-pack/react-simple-icons": "^10.0.0",
16-
"@nivo/geo": "^0.87.0",
1716
"@nivo/line": "^0.87.0",
1817
"@picocss/pico": "^2.0.6",
1918
"@radix-ui/react-dialog": "^1.1.1",
2019
"@radix-ui/react-tabs": "^1.1.0",
21-
"@react-spring/web": "^9.7.4",
2220
"@scaleway/use-query-params": "^5.0.5",
23-
"@tanstack/react-query": "^5.51.23",
24-
"@types/react": "^18.3.3",
25-
"@types/react-dom": "^18.3.0",
26-
"@types/react-simple-maps": "^3.0.6",
21+
"@tanstack/react-query": "^5.52.0",
2722
"@uidotdev/usehooks": "^2.4.1",
28-
"astro": "^4.14.2",
2923
"date-fns": "^3.6.0",
3024
"fets": "^0.8.3",
3125
"lightningcss": "^1.26.0",
32-
"lucide-react": "^0.428.0",
26+
"lucide-react": "^0.429.0",
3327
"react": "^18.3.1",
34-
"react-countup": "^6.5.3",
3528
"react-dom": "^18.3.1",
3629
"react-simple-maps": "^3.0.0",
3730
"react-tag-autocomplete": "^7.3.0",
38-
"react-tooltip": "^5.28.0",
39-
"rollup-plugin-license": "^3.5.2",
40-
"typescript": "^5.5.4"
31+
"react-tooltip": "^5.28.0"
4132
},
4233
"devDependencies": {
4334
"@biomejs/biome": "1.8.3",
44-
"bun-types": "^1.1.24"
35+
"@types/react": "^18.3.4",
36+
"@types/react-dom": "^18.3.0",
37+
"@types/react-simple-maps": "^3.0.6",
38+
"astro": "^4.14.3",
39+
"bun-types": "^1.1.25",
40+
"rollup-plugin-license": "^3.5.2",
41+
"typescript": "^5.5.4"
4542
},
46-
"trustedDependencies": ["@biomejs/biome", "esbuild", "sharp"]
43+
"trustedDependencies": [
44+
"@biomejs/biome",
45+
"esbuild",
46+
"sharp"
47+
]
4748
}
File renamed without changes.

web/src/components/graph.tsx renamed to web/src/components/graph/graph.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,8 @@ import { useMemo } from "react";
22
import styles from "./graph.module.css";
33

44
import { ResponsiveLine, type SliceTooltipProps } from "@nivo/line";
5-
import { addMonths, differenceInSeconds } from "date-fns";
6-
7-
import type { Metric } from "../api";
8-
9-
export type DataPoint = {
10-
x: Date;
11-
y: number;
12-
};
13-
14-
export const toDataPoints = (data: number[], range: { start: number; end: number }, metric: Metric): DataPoint[] => {
15-
const step = differenceInSeconds(range.end, range.start) / data.length;
16-
return data.map((value, i) => ({
17-
x: new Date(range.start + i * step * 1000 + 1000),
18-
y: metric === "avg_views_per_session" ? value / 1000 : value,
19-
}));
20-
};
5+
import { addMonths } from "date-fns";
6+
import type { DataPoint } from ".";
217

228
export type GraphRange = "year" | "month" | "day" | "hour";
239

web/src/components/graph/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { differenceInSeconds } from "date-fns";
2+
import "./graph.module.css";
3+
4+
import { lazy } from "react";
5+
import type { Metric } from "../../api";
6+
7+
export const LineGraph = lazy(() => import("./graph.tsx").then(({ LineGraph }) => ({ default: LineGraph })));
8+
9+
export type DataPoint = {
10+
x: Date;
11+
y: number;
12+
};
13+
14+
export const toDataPoints = (data: number[], range: { start: number; end: number }, metric: Metric): DataPoint[] => {
15+
const step = differenceInSeconds(range.end, range.start) / data.length;
16+
return data.map((value, i) => ({
17+
x: new Date(range.start + i * step * 1000 + 1000),
18+
y: metric === "avg_views_per_session" ? value / 1000 : value,
19+
}));
20+
};

0 commit comments

Comments
 (0)