web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit 90a8c095589670458935f8779eb2dae0598af546
parent 14897507a57ebf9a73500b5e5a19246f8d3f0593
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Fri, 13 Sep 2024 10:25:27 +0000

apps-lib: add vite environment variable configuration for ndk and kv

Diffstat:
Mapps-lib/src/lib/locales/en/common.json | 1+
Mapps-lib/src/lib/locales/en/trade.json | 2++
Mapps-lib/src/lib/stores/client.ts | 9+++++----
Mapps-lib/src/lib/stores/ndk.ts | 13+++++++++++--
4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/apps-lib/src/lib/locales/en/common.json b/apps-lib/src/lib/locales/en/common.json @@ -1,4 +1,5 @@ { + "optional": "Optional", "quantity": "Quantity", "per": "Per", "price": "Price", diff --git a/apps-lib/src/lib/locales/en/trade.json b/apps-lib/src/lib/locales/en/trade.json @@ -12,6 +12,8 @@ } }, "glossary": { + "profile": "Profile", + "lot": "Lot", "process": "Process" } } \ No newline at end of file diff --git a/apps-lib/src/lib/stores/client.ts b/apps-lib/src/lib/stores/client.ts @@ -2,13 +2,14 @@ import { type AppLayoutKey } from "$lib"; import { queryParameters } from "@radroots/sveltekit-search-params"; import { writable } from "svelte/store"; -export const app_qp = queryParameters(); +//@ts-ignore +const kv_name = import.meta.env.VITE_PUBLIC_KV_NAME; +if (!kv_name) throw new Error('Error: VITE_PUBLIC_KV_NAME is required'); -//export const kv = writable<Keyva>(); -//if (typeof window !== 'undefined') kv.set(new Keyva({ name: 'app-kv' })); +export const app_qp = queryParameters(); export let kv: Keyva; -if (typeof window !== 'undefined') kv = new Keyva({ name: 'app-kv' }); +if (typeof window !== 'undefined') kv = new Keyva({ name: kv_name }); export const app_layout = writable<AppLayoutKey>(`base`); diff --git a/apps-lib/src/lib/stores/ndk.ts b/apps-lib/src/lib/stores/ndk.ts @@ -3,12 +3,21 @@ import NDKCacheAdapterDexie from "@nostr-dev-kit/ndk-cache-dexie"; import NDKSvelte from "@nostr-dev-kit/ndk-svelte"; import { writable } from "svelte/store"; +//@ts-ignore +const ndk_cache_name = import.meta.env.VITE_PUBLIC_NDK_CACHE_NAME; +if (!ndk_cache_name) throw new Error('Error: VITE_PUBLIC_NDK_CACHE_NAME is required'); + +//@ts-ignore +const ndk_client_name = import.meta.env.VITE_PUBLIC_NDK_CLIENT_NAME; +if (!ndk_client_name) throw new Error('Error: VITE_PUBLIC_NDK_CLIENT_NAME is required'); + + let cacheAdapter: NDKCacheAdapter | undefined; -if (typeof window !== `undefined`) cacheAdapter = new NDKCacheAdapterDexie({ dbName: "-radroots-app-ndk" }); +if (typeof window !== `undefined`) cacheAdapter = new NDKCacheAdapterDexie({ dbName: ndk_cache_name }); const _ndk = new NDKSvelte({ cacheAdapter, - clientName: "ยป--`--,---", + clientName: ndk_client_name, }); export const ndk = writable<NDKSvelte>(_ndk);