From 537c46d3d7cfee5c036780cbe5a13dafbfaa9db7 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 14 Dec 2024 11:34:27 +0100 Subject: [PATCH] fix: minor type and ui fixes, fix solid reactivity warning --- src/components/ui/charts.tsx | 4 ++-- src/db.ts | 38 +++++++++++++++++++----------------- src/lib/db-cache.ts | 30 +++++++++++++++------------- src/pages/dm/dm-id.tsx | 10 +++++++++- 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/components/ui/charts.tsx b/src/components/ui/charts.tsx index 1f2ec54..6a9a215 100644 --- a/src/components/ui/charts.tsx +++ b/src/components/ui/charts.tsx @@ -191,8 +191,8 @@ function showTooltip(context: ChartContext) { const pos = context.chart.canvas.getBoundingClientRect(); el.style.opacity = "1"; el.style.position = "absolute"; - el.style.left = `${pos.left + window.scrollX + model.caretX}px`; - el.style.top = `${pos.top + window.scrollY + model.caretY}px`; + el.style.left = `${(pos.left + window.scrollX + model.caretX).toString()}px`; + el.style.top = `${(pos.top + window.scrollY + model.caretY).toString()}px`; el.style.pointerEvents = "none"; } diff --git a/src/db.ts b/src/db.ts index e5faa31..4919aed 100644 --- a/src/db.ts +++ b/src/db.ts @@ -1,4 +1,4 @@ -import { type Accessor, createEffect, createMemo, createSignal, DEV, type Setter } from "solid-js"; +import { type Accessor, createEffect, createMemo, createRoot, createSignal, DEV, type Setter } from "solid-js"; import { Kysely, type NotNull, sql } from "kysely"; import type { DB } from "kysely-codegen"; @@ -41,25 +41,27 @@ const sqlJsDialect = () => { } }; -createEffect(() => { - const db = rawDb(); +const kyselyDb = createRoot(() => { + createEffect(() => { + const db = rawDb(); - if (db) { - db.create_function("is_not_empty", (str: string | null) => { - return str !== null && str !== ""; + if (db) { + db.create_function("is_not_empty", (str: string | null) => { + return str !== null && str !== ""; + }); + } + }); + + return createMemo(() => { + const currentSqlJsDialect = sqlJsDialect(); + + if (!currentSqlJsDialect) { + throw new Error("no db selected!"); + } + + return new Kysely({ + dialect: currentSqlJsDialect, }); - } -}); - -const kyselyDb = createMemo(() => { - const currentSqlJsDialect = sqlJsDialect(); - - if (!currentSqlJsDialect) { - throw new Error("no db selected!"); - } - - return new Kysely({ - dialect: currentSqlJsDialect, }); }); diff --git a/src/lib/db-cache.ts b/src/lib/db-cache.ts index 5c92833..5546bc2 100644 --- a/src/lib/db-cache.ts +++ b/src/lib/db-cache.ts @@ -1,4 +1,4 @@ -import { createEffect, on } from "solid-js"; +import { createEffect, createRoot, on } from "solid-js"; const DATABASE_HASH_PREFIX = "database"; @@ -31,24 +31,26 @@ const HASH_STORE_KEY = "database_hash"; // cannot import `db` the normal way because this file is imported in ~/db.ts before the initialisation of `db` has happened queueMicrotask(() => { - void import("~/db").then(({ db }) => { - createEffect( - on(db, (currentDb) => { - if (currentDb) { - const newHash = hashString(new TextDecoder().decode(currentDb.export())).toString(); + createRoot(() => { + void import("~/db").then(({ db }) => { + createEffect( + on(db, (currentDb) => { + if (currentDb) { + const newHash = hashString(new TextDecoder().decode(currentDb.export())).toString(); - const oldHash = localStorage.getItem(HASH_STORE_KEY); + const oldHash = localStorage.getItem(HASH_STORE_KEY); - console.log(newHash, oldHash); + console.log(newHash, oldHash); - if (newHash !== oldHash) { - clearDbCache(); + if (newHash !== oldHash) { + clearDbCache(); - localStorage.setItem(HASH_STORE_KEY, newHash); + localStorage.setItem(HASH_STORE_KEY, newHash); + } } - } - }), - ); + }), + ); + }); }); }); diff --git a/src/pages/dm/dm-id.tsx b/src/pages/dm/dm-id.tsx index c27dde8..bc09754 100644 --- a/src/pages/dm/dm-id.tsx +++ b/src/pages/dm/dm-id.tsx @@ -1,4 +1,4 @@ -import { type Accessor, type Component, createEffect, createResource, Show } from "solid-js"; +import { type Accessor, type Component, createResource, Show } from "solid-js"; import type { RouteSectionProps } from "@solidjs/router"; import { type ChartData } from "chart.js"; @@ -175,6 +175,14 @@ export const DmId: Component = (props) => {