web


git clone https://radroots.dev/git/web.git
Log | Files | Refs | Submodules | README | LICENSE

commit 546149adff45c7512dbcabfbd26b49670d8cd270
parent 10e5f3e47c96dc59ef6ac3976bc46a15c3e22c3b
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Mon,  9 Dec 2024 07:01:22 +0000

Add `/notifications` page basis. Edit routes, components, utils.

Diffstat:
Msrc/lib/components/search_result_display.svelte | 4++--
Msrc/lib/util/client.ts | 6++++++
Dsrc/lib/util/error.ts | 9---------
Msrc/lib/util/fetch-radroots-profile.ts | 2+-
Asrc/lib/util/fetch-radroots-upload.ts | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/lib/util/fetch.ts | 66++++++------------------------------------------------------------
Msrc/lib/util/models-media-upload.ts | 18+++++++++---------
Msrc/lib/util/nostr-sync.ts | 2+-
Msrc/routes/(app)/models/trade-product/add/+page.svelte | 2+-
Asrc/routes/(app)/notifications/+page.svelte | 36++++++++++++++++++++++++++++++++++++
Msrc/routes/(app)/settings/profile/+page.svelte | 2+-
11 files changed, 115 insertions(+), 84 deletions(-)

diff --git a/src/lib/components/search_result_display.svelte b/src/lib/components/search_result_display.svelte @@ -1,9 +1,9 @@ <script lang="ts"> - import type { ClientSearchResult } from "$lib/util/client-search"; import { ascii, Glyph, ls, route } from "@radroots/svelte-lib"; + import type { SearchServiceResult } from "@radroots/utils"; import SearchResultContainer from "./search_result_container.svelte"; - export let basis: ClientSearchResult; + export let basis: SearchServiceResult; </script> {#if `location_gcs` in basis && basis.location_gcs.id} diff --git a/src/lib/util/client.ts b/src/lib/util/client.ts @@ -81,3 +81,8 @@ export const el_focus = async (id: string, callback: () => Promise<void>, layer: await catch_err(e, `el_focus`); } }; + +export const throw_err = (param: string | ErrorMessage<string>): undefined => { + if (typeof param === `string`) throw new Error(param); + else throw new Error(param.err); +}; +\ No newline at end of file diff --git a/src/lib/util/error.ts b/src/lib/util/error.ts @@ -1,9 +0,0 @@ -import type { ErrorMessage } from "@radroots/utils"; - -export const throw_err = (param: string | ErrorMessage<string>): undefined => { - if (typeof param === `string`) throw new Error(param); - else throw new Error(param.err); -}; - - - diff --git a/src/lib/util/fetch-radroots-profile.ts b/src/lib/util/fetch-radroots-profile.ts @@ -3,7 +3,7 @@ import { http, nostr } from "$lib/client"; import { cfg } from "$lib/conf"; import { catch_err, get_store, ls, } from "@radroots/svelte-lib"; import { err_msg, type ErrorMessage } from "@radroots/utils"; -import { throw_err } from "./error"; +import { throw_err } from "./client"; export const fetch_radroots_profile_validate = async (opts: { profile_name: string; diff --git a/src/lib/util/fetch-radroots-upload.ts b/src/lib/util/fetch-radroots-upload.ts @@ -0,0 +1,52 @@ +import { fs, http, keystore } from "$lib/client"; +import { ks } from "$lib/conf"; +import type { IClientHttpResponseError } from "@radroots/client"; +import { app_nostr_key, catch_err, get_store } from "@radroots/svelte-lib"; +import { err_msg, err_res, nostr_event_sign_attest, type ErrorMessage, type ErrorResponse, type FilePath } from "@radroots/utils"; + +export const fetch_radroots_upload = async (opts: { + url: string; + file_path: FilePath; +}): Promise<{ + res_base: string; + res_path: string; +} | ErrorResponse<IClientHttpResponseError> | ErrorMessage<string>> => { + try { + const nostr_public_key = get_store(app_nostr_key); + const secret_key = await keystore.get( + ks.keys.nostr_secretkey(nostr_public_key), + ); + if (`err` in secret_key) return err_msg(`error.client.keystore_nostr_secretkey`); + const { url, file_path } = opts; + const file_data = await fs.read_bin(file_path.file_path); + if (!file_data) return err_msg(`error.client.file_path_read_bin_undefined`);; + const res = await http.fetch({ + url, + method: `put`, + headers: { + "Content-Type": file_path.mime_type, + "X-Nostr-Event": JSON.stringify(nostr_event_sign_attest(secret_key.result)), + }, + authorization: nostr_public_key, + data_bin: file_data, + }); + if (`err` in res) err_msg(`error.client.request_failure`); + else if (res.error) return err_res(res.error); + else if ( + res.status === 200 && + res.data && + `pass` in res.data && + `res_base` in res.data && + typeof res.data.res_base === `string` && + `res_path` in res.data && + typeof res.data.res_path === `string` + ) return { + res_base: res.data.res_base, + res_path: res.data.res_path, + }; + return err_msg(`error.client.request_unhandled`); + } catch (e) { + await catch_err(e, `fetch_radroots_upload`); + return err_msg(`error.client.network_failure`); + } +}; diff --git a/src/lib/util/fetch.ts b/src/lib/util/fetch.ts @@ -1,60 +1,9 @@ -import { db, fs, http, keystore } from "$lib/client"; -import { cfg, ks } from "$lib/conf"; -import type { IClientHttpResponseError } from "@radroots/client"; +import { db, http } from "$lib/client"; +import { cfg } from "$lib/conf"; import { parse_nostr_relay_form_keys, type NostrRelayFormFields } from "@radroots/models"; import { app_nostr_key, catch_err, get_store, nostr_relays_connected, nostr_relays_poll_documents, nostr_relays_poll_documents_count } from "@radroots/svelte-lib"; -import { err_msg, err_res, nostr_event_sign_attest, parse_nostr_relay_information_document_fields, type ErrorMessage, type ErrorResponse, type FilePath } from "@radroots/utils"; - -export const fetch_put_upload = async (opts: { - url: string; - file_path: FilePath; -}): Promise<{ - res_base: string; - res_path: string; -} | ErrorResponse<IClientHttpResponseError> | ErrorMessage<string>> => { - try { - const nostr_public_key = get_store(app_nostr_key); - const secret_key = await keystore.get( - ks.keys.nostr_secretkey(nostr_public_key), - ); - if (`err` in secret_key) return err_msg(`error.client.keystore_nostr_secretkey`); - const { url, file_path } = opts; - const file_data = await fs.read_bin(file_path.file_path); - if (!file_data) return err_msg(`error.client.file_path_read_bin_undefined`);; - const res = await http.fetch({ - url, - method: `put`, - headers: { - "Content-Type": file_path.mime_type, - "X-Nostr-Event": JSON.stringify(nostr_event_sign_attest(secret_key.result)), - }, - authorization: nostr_public_key, - data_bin: file_data, - }); - if (`err` in res) err_msg(`error.client.request_failure`); - else if (res.error) { - return err_res(res.error); - } - else if ( - res.status === 200 && - res.data && - `pass` in res.data && - `res_base` in res.data && - typeof res.data.res_base === `string` && - `res_path` in res.data && - typeof res.data.res_path === `string` - ) { - return { - res_base: res.data.res_base, - res_path: res.data.res_path, - }; - } - return err_msg(`error.client.request_unhandled`); - } catch (e) { - await catch_err(e, `fetch_put_upload`); - return err_msg(`error.client.network_failure`); - } -}; +import { parse_nostr_relay_information_document_fields } from "@radroots/utils"; +import { throw_err } from "./client"; export const fetch_relay_documents = async (): Promise<void> => { try { @@ -74,14 +23,11 @@ export const fetch_relay_documents = async (): Promise<void> => { const nostr_relays = await db.nostr_relay_get({ list: [`on_profile`, { public_key: $app_nostr_key }], }); - if (`err` in nostr_relays) throw new Error(nostr_relays.err); + if (`err` in nostr_relays) return throw_err(nostr_relays.err); const unconnected_relays = nostr_relays.results.filter( (i) => !$nostr_relays_connected.includes(i.id), ); - if (unconnected_relays.length === 0) { - nostr_relays_poll_documents.set(false); - return; - } + if (unconnected_relays.length === 0) return void nostr_relays_poll_documents.set(false); for (const nostr_relay of unconnected_relays) { const res = await http.fetch({ url: nostr_relay.url.replace(`ws://`, `http://`), diff --git a/src/lib/util/models-media-upload.ts b/src/lib/util/models-media-upload.ts @@ -5,7 +5,7 @@ import type { IClientHttpResponseError } from "@radroots/client"; import { catch_err, ls } from "@radroots/svelte-lib"; import { parse_file_path, type FilePath, type ResultsList } from "@radroots/utils"; import { get } from "svelte/store"; -import { fetch_put_upload } from "./fetch"; +import { fetch_radroots_upload } from "./fetch-radroots-upload"; export const model_media_upload_add_list = async (opts: { photo_paths: string[]; @@ -33,25 +33,25 @@ export const model_media_upload_add_list = async (opts: { console.log(JSON.stringify(file_path, null, 4), `file_path`) if (!file_path) continue; const url = `${PUBLIC_RADROOTS_URL}/public/upload/image`; //@todo - const put_upload = await fetch_put_upload({ + const radroots_upload = await fetch_radroots_upload({ url, file_path, }); - console.log(JSON.stringify(put_upload, null, 4), `put_upload`) - if (`err` in put_upload) { + console.log(JSON.stringify(radroots_upload, null, 4), `radroots_upload`) + if (`err` in radroots_upload) { photo_path_uploads_err.push({ file_path, - err_msg: put_upload.err, + err_msg: radroots_upload.err, }); continue; - } else if (`error` in put_upload) { - photo_path_uploads_error.push(put_upload.error); + } else if (`error` in radroots_upload) { + photo_path_uploads_error.push(radroots_upload.error); continue; } photo_path_uploads.push({ file_path, - res_base: put_upload.res_base, - res_path: put_upload.res_path, + res_base: radroots_upload.res_base, + res_path: radroots_upload.res_path, }); } diff --git a/src/lib/util/nostr-sync.ts b/src/lib/util/nostr-sync.ts @@ -7,7 +7,7 @@ import { } from "@radroots/svelte-lib"; import { fmt_tags_basis_nip99, ndk_event, ndk_event_metadata, nevent_encode, num_str } from "@radroots/utils"; import { get as get_store } from "svelte/store"; -import { throw_err } from "./error"; +import { throw_err } from "./client"; export const nostr_sync_metadata = async (): Promise<void> => { try { diff --git a/src/routes/(app)/models/trade-product/add/+page.svelte b/src/routes/(app)/models/trade-product/add/+page.svelte @@ -522,7 +522,7 @@ const file_path = parse_file_path(photo_path); if (!file_path) continue; const url = `${PUBLIC_RADROOTS_URL}/public/upload/image`; //@todo - const put_upload = await fetch_put_upload({ + const put_upload = await fetch_radroots_upload({ url, file_path, }); diff --git a/src/routes/(app)/notifications/+page.svelte b/src/routes/(app)/notifications/+page.svelte @@ -0,0 +1,36 @@ +<script lang="ts"> + import { + LayoutView, + ls, + NavToolbar, + PageHeader, + TabsFloat, + } from "@radroots/svelte-lib"; + + let notifications: any[] = []; +</script> + +<LayoutView> + <NavToolbar /> + <PageHeader + basis={{ + label: `${$ls(`common.notifications`)} (${notifications.length})`, + }} + ></PageHeader> + <div class={`flex flex-col w-full px-4 gap-6 justify-center items-center`}> + {#if notifications.length} + {#each notifications as li} + <div class={`flex flex-row w-full justify-center items-center`}> + {li} + </div> + {/each} + {:else} + <div class={`flex flex-row w-full justify-center items-center`}> + <p class={`font-sans font-[500] text-layer-0-glyph capitalize`}> + {`${$ls(`icu.no_*`, { value: `${$ls(`common.notifications`)}` })}`} + </p> + </div> + {/if} + </div> +</LayoutView> +<TabsFloat /> diff --git a/src/routes/(app)/settings/profile/+page.svelte b/src/routes/(app)/settings/profile/+page.svelte @@ -1,7 +1,7 @@ <script lang="ts"> import { db, dialog, fs } from "$lib/client"; import ImageUploadAddPhoto from "$lib/components/image_upload_add_photo.svelte"; - import { throw_err } from "$lib/util/error"; + import { throw_err } from "$lib/util/client"; import { kv_init_page } from "$lib/util/kv"; import { model_media_upload_add_list } from "$lib/util/models-media-upload"; import { nostr_sync_metadata } from "$lib/util/nostr-sync";