web


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

commit f944e43d1d39b9308932aba1d443cdeb3feba267
parent c0447d401fbadab854e67523756a24e77b17fd27
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Mon,  7 Oct 2024 05:22:51 +0000

Edit `/models/trade-product/add`, move stores to `@radroots/svelte-lib`, edit components, utils

Diffstat:
Msrc/lib/components/map_choose_location.svelte | 7+++++--
Msrc/lib/stores.ts | 6------
Msrc/lib/utils/location_gcs.ts | 15+++++++--------
Msrc/routes/(app)/+layout.svelte | 2+-
Msrc/routes/(app)/+page.svelte | 2+-
Msrc/routes/(app)/map/+page.svelte | 3+--
Msrc/routes/(app)/map/choose-location/+page.svelte | 3+--
Msrc/routes/(app)/models/nostr-profile/view/+page.svelte | 2+-
Msrc/routes/(app)/models/nostr-relay/+page.svelte | 2+-
Msrc/routes/(app)/models/trade-product/+page.svelte | 1-
Msrc/routes/(app)/models/trade-product/add/+page.svelte | 174++++++++++++++++++++++++++++++++++++++-----------------------------------------
Msrc/routes/(app)/nostr/keys/+page.svelte | 2+-
Msrc/routes/(app)/nostr/notes/+page.svelte | 2+-
Msrc/routes/(app)/nostr/profile/+page.svelte | 2+-
Msrc/routes/(app)/settings/+page.svelte | 2+-
Msrc/routes/+layout.svelte | 10++++------
16 files changed, 109 insertions(+), 126 deletions(-)

diff --git a/src/lib/components/map_choose_location.svelte b/src/lib/components/map_choose_location.svelte @@ -1,9 +1,12 @@ <script lang="ts"> import { geoc } from "$lib/client"; import { _conf } from "$lib/conf"; - import { app_thc } from "$lib/stores"; import type { GeocoderReverseResult } from "@radroots/geocoder"; - import { Loading, type CallbackPromise } from "@radroots/svelte-lib"; + import { + app_thc, + Loading, + type CallbackPromise, + } from "@radroots/svelte-lib"; import { MapLibre, Marker, Popup } from "@radroots/svelte-maplibre"; import type { GeolocationCoordinatesPoint } from "@radroots/utils"; import MapMarkerDot from "./map_marker_dot.svelte"; diff --git a/src/lib/stores.ts b/src/lib/stores.ts @@ -1,13 +1,7 @@ -import type { ColorMode, ThemeKey } from "@radroots/theme"; import { type NumberTuple } from "@radroots/utils"; import { writable } from "svelte/store"; export const app_tok = writable<string>(''); -export const app_thc = writable<ColorMode>(`dark`); -export const app_th = writable<ThemeKey>(`os`); - -export const app_nostr_key = writable<string>(``); -export const app_pwa_polyfills = writable<boolean>(false); export const map_full_center = writable<NumberTuple>([0, 0]); export const map_full_zoom = writable<number>(4); diff --git a/src/lib/utils/location_gcs.ts b/src/lib/utils/location_gcs.ts @@ -1,12 +1,12 @@ import { geoc, lc } from "$lib/client"; import type { GeocoderReverseResult } from "@radroots/geocoder"; import type { LocationGcsFormFields } from "@radroots/models"; -import { location_geohash } from "@radroots/utils"; +import { err_msg, location_geohash, type ErrorMessage, type ResultId } from "@radroots/utils"; export const location_gcs_add_geoc = async (opts: { geoc: GeocoderReverseResult; label?: string; -}): Promise<{ id: string } | undefined> => { +}): Promise<ResultId | ErrorMessage<string>> => { try { const { geoc } = opts; const fields: LocationGcsFormFields = { @@ -25,14 +25,13 @@ export const location_gcs_add_geoc = async (opts: { const res = await lc.db.location_gcs_add(fields); if (`id` in res) return res; - else if (`err` in res && res.err === `*-location-gcs-geohash-unique` - ) { - await lc.dialog.alert( - `This location has already been added.`, - ); - } + if (`err` in res && res.err === `*-location-gcs-geohash-unique`) + return err_msg(`This location has already been added.`); + + return err_msg(`There was an error`) } catch (e) { console.log(`(error) location_gcs_add_geoc `, e); + return err_msg(``) } }; diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte @@ -1,13 +1,13 @@ <script lang="ts"> import { lc } from "$lib/client"; import { _conf } from "$lib/conf"; - import { app_nostr_key } from "$lib/stores"; import { nostr_sync_models_trade_product } from "$lib/utils/nostr"; import { type NostrRelayFormFields, parse_nostr_relay_form_keys, } from "@radroots/models"; import { + app_nostr_key, LayoutWindow, ndk, ndk_user, diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte @@ -1,6 +1,6 @@ <script lang="ts"> - import { app_nostr_key } from "$lib/stores"; import { + app_nostr_key, type CallbackPromise, EnvelopeLower, Glyph, diff --git a/src/routes/(app)/map/+page.svelte b/src/routes/(app)/map/+page.svelte @@ -4,8 +4,7 @@ import MapMarkerDot from "$lib/components/map_marker_dot.svelte"; import MapPopupLocationInfo from "$lib/components/map_popup_location_info.svelte"; import { _conf } from "$lib/conf"; - import { app_thc } from "$lib/stores"; - import { LoadingView, route, sleep } from "@radroots/svelte-lib"; + import { app_thc, LoadingView, route, sleep } from "@radroots/svelte-lib"; import { MapLibre, Marker, Popup } from "@radroots/svelte-maplibre"; import { type GeolocationCoordinatesPoint } from "@radroots/utils"; import { onMount } from "svelte"; diff --git a/src/routes/(app)/map/choose-location/+page.svelte b/src/routes/(app)/map/choose-location/+page.svelte @@ -4,9 +4,8 @@ import MapMarkerDot from "$lib/components/map_marker_dot.svelte"; import MapPopupLocationInfo from "$lib/components/map_popup_location_info.svelte"; import { _conf } from "$lib/conf"; - import { app_thc } from "$lib/stores"; import { location_gcs_add_current } from "$lib/utils/location_gcs"; - import { LoadingView, route, sleep } from "@radroots/svelte-lib"; + import { app_thc, LoadingView, route, sleep } from "@radroots/svelte-lib"; import { MapLibre, Marker, Popup } from "@radroots/svelte-maplibre"; import { type GeolocationCoordinatesPoint } from "@radroots/utils"; import { onMount } from "svelte"; diff --git a/src/routes/(app)/models/nostr-profile/view/+page.svelte b/src/routes/(app)/models/nostr-profile/view/+page.svelte @@ -1,9 +1,9 @@ <script lang="ts"> import { lc } from "$lib/client"; import { _conf } from "$lib/conf"; - import { app_nostr_key } from "$lib/stores"; import type { NostrProfile, NostrRelay } from "@radroots/models"; import { + app_nostr_key, app_notify, app_submit_route, as_glyph_key, diff --git a/src/routes/(app)/models/nostr-relay/+page.svelte b/src/routes/(app)/models/nostr-relay/+page.svelte @@ -1,8 +1,8 @@ <script lang="ts"> import { lc } from "$lib/client"; - import { app_nostr_key } from "$lib/stores"; import type { NostrRelay } from "@radroots/models"; import { + app_nostr_key, app_notify, GlyphCircle, LayoutTrellis, diff --git a/src/routes/(app)/models/trade-product/+page.svelte b/src/routes/(app)/models/trade-product/+page.svelte @@ -32,7 +32,6 @@ const trade_products = await lc.db.trade_product_get({ list: [`all`], }); - console.log(`trade_products `, trade_products); if (`err` in trade_products) { app_notify.set(`Error loading page`); return; diff --git a/src/routes/(app)/models/trade-product/add/+page.svelte b/src/routes/(app)/models/trade-product/add/+page.svelte @@ -3,7 +3,10 @@ import { lc } from "$lib/client"; import MapChooseLocation from "$lib/components/map_choose_location.svelte"; import { _conf } from "$lib/conf"; - import { location_gcs_add_current } from "$lib/utils/location_gcs"; + import { + location_gcs_add_current, + location_gcs_add_geoc, + } from "$lib/utils/location_gcs"; import { trade_product_kv_init, validate_trade_product_vals, @@ -24,6 +27,7 @@ Fill, fmt_id, Glyph, + InputElement, InputForm, InputSelect, int_step, @@ -34,7 +38,6 @@ locale, Nav, NotifyGlyph, - sleep, t, TextareaElement, view_effect, @@ -101,16 +104,19 @@ view_effect<View>(view); } - $: { - if (view === `map`) { - (async () => { - try { - loading_map = true; - await sleep(500); - loading_map = false; - } catch (e) {} - })(); - } + $: if (view === `map`) { + (async () => { + try { + loading_map = true; + const geoloc = await lc.geo.current(); + if (`err` in geoloc) return; + else { + map_point_location_gcs = geoloc; + map_point_location_gcs_select = geoloc; + } + loading_map = false; + } catch (e) {} + })(); } let show_sel_trade_product_key_other = false; @@ -178,55 +184,44 @@ ) : fmt_trade_quantity_val(trade_quantities[trade_key_default][0]); - $: { - if (ls_models_location_gcs.length && !sel_location_gcs_id) { - sel_location_gcs_id = ls_models_location_gcs[0].id; - } + $: if (ls_models_location_gcs.length && !sel_location_gcs_id) { + sel_location_gcs_id = ls_models_location_gcs[0].id; } - $: { - if (sel_location_gcs_id) { - (async () => { - try { - await kv.set( - fmt_id(`location_gcs_id`), - sel_location_gcs_id, - ); - } catch (e) {} - })(); - } + $: if (sel_location_gcs_id) { + (async () => { + try { + await kv.set(fmt_id(`location_gcs_id`), sel_location_gcs_id); + } catch (e) {} + })(); } - $: { - if (sel_trade_product_qty_tup) { - (async () => { - try { - const mass_tup = parse_trade_mass_tuple( - sel_trade_product_qty_tup, - ); - if (mass_tup) { - await kv.set(fmt_id(`qty_amt`), mass_tup[0].toString()); - await kv.set(fmt_id(`qty_unit`), mass_tup[1]); - await kv.set(fmt_id(`qty_label`), mass_tup[2]); - //@note - await kv.set(fmt_id(`qty_avail`), `1`); - } - } catch (e) {} - })(); - } + $: if (sel_trade_product_qty_tup) { + (async () => { + try { + const mass_tup = parse_trade_mass_tuple( + sel_trade_product_qty_tup, + ); + if (mass_tup) { + await kv.set(fmt_id(`qty_amt`), mass_tup[0].toString()); + await kv.set(fmt_id(`qty_unit`), mass_tup[1]); + await kv.set(fmt_id(`qty_label`), mass_tup[2]); + //@note + await kv.set(fmt_id(`qty_avail`), `1`); + } + } catch (e) {} + })(); } - $: { - if (sel_trade_product_price_currency) { - (async () => { - try { - await kv.set( - fmt_id(`price_currency`), - sel_trade_product_price_currency, - ); - } catch (e) {} - })(); - } + $: if (sel_trade_product_price_currency) { + (async () => { + try { + await kv.set( + fmt_id(`price_currency`), + sel_trade_product_price_currency, + ); + } catch (e) {} + })(); } onMount(async () => { @@ -298,7 +293,7 @@ }); if (`err` in vals_init) { await lc.dialog.alert( - `${$t(`trade.product.fields.${vals_init}.err_invalid`, { default: `${$t(`icu.invalid_*`, { value: vals_init.err })}` })}`, + `${$t(`trade.product.fields.${vals_init.err}.err_invalid`, { default: `${$t(`icu.invalid_*`, { value: vals_init.err })}` })}`, ); return; } @@ -440,18 +435,39 @@ } }; - const add_model_location_gcs = async (): Promise<void> => { + const handle_add_current_location = async (): Promise<void> => { try { loading_location_gcs = true; await location_gcs_add_current(); await fetch_models_models_location_gcs(); } catch (e) { - console.log(`(error) add_model_location_gcs `, e); + console.log(`(error) handle_add_current_location `, e); } finally { loading_location_gcs = false; } }; + const handle_add_map_location = async (): Promise<void> => { + try { + if (!map_point_location_gcs_select_geoc) { + await lc.dialog.alert(`No location selected`); + return; + } + const res = await location_gcs_add_geoc({ + geoc: map_point_location_gcs_select_geoc, + }); + if (`err` in res) { + await lc.dialog.alert(res.err || `There was an error`); + return; + } + + sel_location_gcs_id = res.id; + await fetch_models_models_location_gcs(); + } catch (e) { + console.log(`(error) handle_add_map_location `, e); + } + }; + const submit = async (): Promise<void> => { try { loading_submit = true; @@ -567,7 +583,7 @@ sync: true, sync_init: false, classes: `font-mono-display`, - placeholder: `Enter price`, + placeholder: `${$t(`icu.enter_*`, { value: `${$t(`common.price`)}` })}`, field: { charset: trade_product_form_fields.price_amt @@ -680,7 +696,7 @@ id: fmt_id(`qty_amt`), layer: false, sync: true, - placeholder: `Enter number of ${$t(`measurement.mass.unit.${sel_trade_product_price_qty_unit}_ab`, { default: sel_trade_product_price_qty_unit })} per order`, + placeholder: `${$t(`icu.enter_number_of_*_per_order`, { value: `${$t(`measurement.mass.unit.${sel_trade_product_price_qty_unit}_ab`, { default: sel_trade_product_price_qty_unit })}` })}`, field: { charset: trade_product_form_fields @@ -1157,7 +1173,7 @@ }, }} > - <InputForm + <InputElement basis={{ id: fmt_id(`title`), sync: true, @@ -1223,7 +1239,7 @@ label: `${i.label}`, })), { - value: `add-new`, + value: `add-current`, label: `${$t(`common.add_current_location`)}`, }, { @@ -1239,7 +1255,7 @@ label: `${$t(`common.no_locations_saved`)}`, }, { - value: `add-new`, + value: `add-current`, label: `${$t(`common.add_current_location`)}`, }, { @@ -1248,13 +1264,12 @@ }, ], callback: async (val) => { - if (val === `add-new`) { + if (val === `add-current`) { sel_location_gcs_id = ``; - await add_model_location_gcs(); + await handle_add_current_location(); } else if (val === `add-map`) { sel_location_gcs_id = ``; view = `map`; - //await route(`/map/choose-location`); } }, }} @@ -1288,15 +1303,6 @@ <p class={`font-sans font-[400] text-layer-0-glyph`}> {`Location`} </p> - <div - class={`flex flex-row w-trellis_line justify-start items-start`} - > - <p - class={`font-sans font-[400] text-layer-0-glyph`} - > - {JSON.stringify(review_location_gcs, null, 4)} - </p> - </div> </div> </div> </div> @@ -1345,12 +1351,6 @@ if (view === `map`) { view = `form_1`; } else { - const geoloc = await lc.geo.current(); - if (`err` in geoloc) return; - else { - map_point_location_gcs = geoloc; - map_point_location_gcs_select = geoloc; - } view = `map`; } }, @@ -1372,16 +1372,8 @@ : undefined, }, callback: async () => { - if (view === `map`) { - console.log( - JSON.stringify( - map_point_location_gcs_select_geoc, - null, - 4, - ), - `map_point_location_gcs_select_geoc`, - ); - } else if ($carousel_index === $carousel_index_max) + if (view === `map`) await handle_add_map_location(); + else if ($carousel_index === $carousel_index_max) await submit(); else await handle_carousel_next(); }, diff --git a/src/routes/(app)/nostr/keys/+page.svelte b/src/routes/(app)/nostr/keys/+page.svelte @@ -1,7 +1,6 @@ <script lang="ts"> import { lc } from "$lib/client"; import { _conf } from "$lib/conf"; - import { app_nostr_key } from "$lib/stores"; import type { NostrProfile } from "@radroots/models"; import { Glyph, @@ -10,6 +9,7 @@ Nav, SelectElement, TrellisTitle, + app_nostr_key, app_notify, nav_prev, route, diff --git a/src/routes/(app)/nostr/notes/+page.svelte b/src/routes/(app)/nostr/notes/+page.svelte @@ -1,11 +1,11 @@ <script lang="ts"> - import { app_nostr_key } from "$lib/stores"; import { NDKEvent, NDKKind, type NDKFilter } from "@nostr-dev-kit/ndk"; import type { ExtendedBaseType, NDKEventStore, } from "@nostr-dev-kit/ndk-svelte"; import { + app_nostr_key, LayoutTrellis, LayoutView, locale, diff --git a/src/routes/(app)/nostr/profile/+page.svelte b/src/routes/(app)/nostr/profile/+page.svelte @@ -1,12 +1,12 @@ <script lang="ts"> import { lc } from "$lib/client"; - import { app_nostr_key } from "$lib/stores"; import { NDKEvent, NDKKind, type NDKFilter } from "@nostr-dev-kit/ndk"; import type { ExtendedBaseType, NDKEventStore, } from "@nostr-dev-kit/ndk-svelte"; import { + app_nostr_key, LayoutTrellis, LayoutView, Nav, diff --git a/src/routes/(app)/settings/+page.svelte b/src/routes/(app)/settings/+page.svelte @@ -1,9 +1,9 @@ <script lang="ts"> import { lc } from "$lib/client"; import { _conf } from "$lib/conf"; - import { app_thc } from "$lib/stores"; import { restart } from "$lib/utils"; import { + app_thc, LayoutTrellis, LayoutView, Nav, diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte @@ -2,19 +2,17 @@ import { browser } from "$app/environment"; import { geoc, lc } from "$lib/client"; import { _conf } from "$lib/conf"; - import { - app_nostr_key, - app_pwa_polyfills, - app_th, - app_thc, - } from "$lib/stores"; import { defineCustomElements as pwaElements } from "@ionic/pwa-elements/loader"; import { app_config, app_db, app_geoc, + app_nostr_key, app_notify, + app_pwa_polyfills, app_render, + app_th, + app_thc, AppControls, CssStatic, CssStyles,