From d792cec873c52e8203cd053e32afef340dee5227 Mon Sep 17 00:00:00 2001 From: grngxd <36968271+grngxd@users.noreply.github.com> Date: Sun, 8 Jun 2025 13:07:24 +0100 Subject: [PATCH] nanostores hook & upload btn --- bun.lock | 3 +++ package.json | 3 ++- src/components/Controlbar.tsx | 33 +++++++++++++++++++++++++++++---- src/components/Icons.tsx | 7 +++++++ src/hooks/nanostores.ts | 17 +++++++++++++++++ 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/components/Icons.tsx create mode 100644 src/hooks/nanostores.ts diff --git a/bun.lock b/bun.lock index 0f6eaba..a5363c1 100644 --- a/bun.lock +++ b/bun.lock @@ -5,6 +5,7 @@ "name": "my-qwik-empty-starter", "dependencies": { "ky": "^1.8.1", + "nanostores": "^1.0.1", }, "devDependencies": { "@builder.io/qwik": "^1.14.1", @@ -751,6 +752,8 @@ "nanoid": ["nanoid@3.3.11", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w=="], + "nanostores": ["nanostores@1.0.1", "", {}, "sha512-kNZ9xnoJYKg/AfxjrVL4SS0fKX++4awQReGqWnwTRHxeHGZ1FJFVgTqr/eMrNQdp0Tz7M7tG/TDaX8QfHDwVCw=="], + "natural-compare": ["natural-compare@1.4.0", "", {}, "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw=="], "nth-check": ["nth-check@2.1.1", "", { "dependencies": { "boolbase": "^1.0.0" } }, "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w=="], diff --git a/package.json b/package.json index 4783e19..e437461 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "vite-tsconfig-paths": "^4.2.1" }, "dependencies": { - "ky": "^1.8.1" + "ky": "^1.8.1", + "nanostores": "^1.0.1" } } diff --git a/src/components/Controlbar.tsx b/src/components/Controlbar.tsx index b665482..7f4478c 100644 --- a/src/components/Controlbar.tsx +++ b/src/components/Controlbar.tsx @@ -1,10 +1,35 @@ -import { component$ } from "@builder.io/qwik"; +import { component$, useSignal } from "@builder.io/qwik"; +import { atom } from "nanostores"; +import { SolarUploadLinear } from "./Icons"; + +const a = atom(0); -// TODO: add upload button and other stuff fr export default component$(() => { + const fileInputRef = useSignal(); + return ( -
- hi +
+ {/* Hidden file input */} + { + // You can handle the selected file here or emit an event + const files = (e.target as HTMLInputElement).files; + if (files && files.length > 0) { + console.log("File selected:", files[0]); + } + }} + /> + + {/* Button that triggers the file dialog */} +
) }) \ No newline at end of file diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx new file mode 100644 index 0000000..8bc6dc0 --- /dev/null +++ b/src/components/Icons.tsx @@ -0,0 +1,7 @@ +import { QwikIntrinsicElements } from "@builder.io/qwik"; + +export function SolarUploadLinear(props: QwikIntrinsicElements['svg'], key: string) { + return ( + + ) +} \ No newline at end of file diff --git a/src/hooks/nanostores.ts b/src/hooks/nanostores.ts new file mode 100644 index 0000000..c5b6eb8 --- /dev/null +++ b/src/hooks/nanostores.ts @@ -0,0 +1,17 @@ +import { isServer, noSerialize, useSignal, type NoSerialize } from '@builder.io/qwik'; +import type { ReadableAtom } from 'nanostores'; + +export function useNanostore(atom: ReadableAtom) { + if (isServer) return + + const state = useSignal(atom.get()); + const store = useSignal> | undefined>(undefined); + + store.value = noSerialize(atom); + const unsubscribe = atom.subscribe((value) => { + state.value = value; + }); + + window.addEventListener('beforeunload', () => unsubscribe()); + return state; +} \ No newline at end of file