commit 76d10ec12e0e65fbf9c02eae0f8d505d1f6c928a
parent 41b8d90e22d7b6cdd1974cf9108abb979451cb41
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Sun, 1 Sep 2024 14:47:13 +0000
Update model location_gcs routes, update model trade_product routes, edit models utils, edit conf
Diffstat:
11 files changed, 165 insertions(+), 102 deletions(-)
diff --git a/src/lib/conf.ts b/src/lib/conf.ts
@@ -1,10 +1,10 @@
-import { PUBLIC_PREF_NOSTR_KEY_ACTIVE } from "$env/static/public";
-
export const _cf = {
app: {
+ root_symbol: "»--`--,---",
title: `Radroots`,
description: `Creating networks between farmers, communities and small businesses that give customers greater access to natural foods and grow circular economies where profits are more fairly distributed. Radroots is built on the Nostr protocol and released under a copyleft open source license to provide transparency and give users the option to offer feedback and add or request new features.`
},
- root_symbol: "»--`--,---",
- pref_key_active: PUBLIC_PREF_NOSTR_KEY_ACTIVE,
+ pref: {
+ key_active: `nostr:key:active`
+ },
};
\ No newline at end of file
diff --git a/src/lib/utils/models.ts b/src/lib/utils/models.ts
@@ -15,6 +15,10 @@ export const location_gcs_add = async (): Promise<boolean> => {
input_placeholder: `Enter location name`,
});
if (loc_gcs_label === false) return false;
+ else if (!loc_gcs_label) {
+ await lc.dialog.alert(`A location name is required.`);
+ return false;
+ }
const { lat, lng } = loc_gcs;
const geohash = location_geohash(
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte
@@ -16,6 +16,11 @@
let buttons: { route: string; label: string; key: GlyphKey }[] = [
{
+ route: `/models/location-gcs`,
+ label: `Locations`,
+ key: `globe`,
+ },
+ {
route: `/models/trade-product`,
label: `Post Goods`,
key: `handbag-simple`,
diff --git a/src/routes/(app)/models/location-gcs/+page.svelte b/src/routes/(app)/models/location-gcs/+page.svelte
@@ -10,6 +10,7 @@
import { onMount } from "svelte";
let models_list: LocationGcs[] = [];
+ let loading_models = false;
onMount(async () => {
try {
@@ -22,85 +23,97 @@
const fetch_models = async (): Promise<void> => {
try {
+ loading_models = true;
const res = await lc.db.location_gcs_get({
list: [`all`],
});
if (typeof res !== `string`) models_list = res;
} catch (e) {
console.log(`(error) fetch_models `, e);
+ } finally {
+ loading_models = false;
}
};
</script>
<LayoutView>
<LayoutTrellis>
- <Trellis
- basis={{
- args: {
- layer: 1,
- title: {
- value: `Location GCS`,
- },
- list: [
- {
- touch: {
- label: {
- left: [
- {
- value: `Add Current Location`,
- classes: `capitalize`,
+ {#if models_list.length}
+ {#each models_list as li}
+ <Trellis
+ basis={{
+ args: {
+ layer: 1,
+ title: {
+ value: `Your Locations`,
+ },
+ list: [
+ {
+ hide_active: true,
+ touch: {
+ label: {
+ left: [
+ {
+ value: `Location:`,
+ classes: `capitalize`,
+ },
+ ],
+ right: [
+ {
+ value: li.label,
+ },
+ ],
},
- ],
+ callback: async () => {},
+ },
},
- callback: async () => {
- const res = await location_gcs_add();
- if (res === true) await fetch_models();
+ {
+ hide_active: true,
+ touch: {
+ label: {
+ left: [
+ {
+ value: `Coordinates:`,
+ classes: `capitalize`,
+ },
+ ],
+ right: [
+ {
+ value: `${li.lat.toFixed(3)} ${li.lng.toFixed(3)}`,
+ },
+ ],
+ },
+ callback: async () => {},
+ },
},
- },
+ ],
},
- models_list.length
- ? {
- touch: {
- label: {
- left: [
- {
- value: `Edit Saved Location`,
- classes: `capitalize`,
- },
- ],
- },
- callback: async () => {
- alert(`Todo!`);
- },
- },
- }
- : undefined,
- ].filter((i) => !!i),
- },
- }}
- />
- <div class={`flex flex-col justify-center items-center pt-4 px-4`}>
- {#if models_list.length > 0}
- <p class={`font-sans font-[400] text-layer-0-glyph text-xs`}>
- {"Your locations:"}
+ }}
+ />
+ {/each}
+ {:else if !loading_models}
+ <div
+ class={`flex flex-col w-full justify-center items-center px-4 gap-3`}
+ >
+ <p class={`font-sans font-[400] text-layer-2-glyph`}>
+ {`No items to display.`}
</p>
- {#each models_list as li}
- <div class={`flex flex-col justify-center items-center`}>
- <pre
- class={`font-sans font-[400] text-layer-0-glyph text-xs`}>{JSON.stringify(
- li,
- null,
- 4,
- )}
- </pre>
- </div>
- {/each}
- {:else}
- <p class={`font-sans font-[400] text-layer-0-glyph text-xs`}>
- {"No locations saved"}
- </p>
- {/if}
- </div>
+
+ <button
+ class={`flex flex-row justify-center items-center`}
+ on:click={async () => {
+ const res = await location_gcs_add();
+ if (res === true) await fetch_models();
+ }}
+ >
+ <p
+ class={`font-sans font-[400] text-layer-2-glyph-hl text-sm`}
+ >
+ {`Click to add a new location`}
+ </p>
+ </button>
+ </div>
+ {/if}
</LayoutTrellis>
</LayoutView>
<Nav
@@ -112,15 +125,17 @@
title: {
label: `Locations`,
},
- option: {
- glyph: {
- key: `arrow-counter-clockwise`,
- dim: `md`,
- classes: `text-layer-1-glyph-hl tap-scale`,
- },
- callback: async () => {
- await fetch_models();
- },
- },
+ option: models_list.length
+ ? {
+ label: {
+ value: `Add`,
+ classes: `tap-color`,
+ },
+ callback: async () => {
+ const res = await location_gcs_add();
+ if (res === true) await fetch_models();
+ },
+ }
+ : undefined,
}}
/>
diff --git a/src/routes/(app)/models/trade-product/+page.svelte b/src/routes/(app)/models/trade-product/+page.svelte
@@ -14,6 +14,7 @@
import { onMount } from "svelte";
let models_list: TradeProduct[] = [];
+ let loading_models = false;
onMount(async () => {
try {
@@ -26,12 +27,15 @@
const fetch_models = async (): Promise<void> => {
try {
+ loading_models = true;
const res = await lc.db.trade_product_get({
list: [`all`],
});
if (typeof res !== `string`) models_list = res;
} catch (e) {
console.log(`(error) fetch_models `, e);
+ } finally {
+ loading_models = false;
}
};
</script>
@@ -132,7 +136,7 @@
}}
/>
{/each}
- {:else}
+ {:else if !loading_models}
<div
class={`flex flex-col w-full justify-center items-center px-4 gap-3`}
>
diff --git a/src/routes/(app)/models/trade-product/add/+page.svelte b/src/routes/(app)/models/trade-product/add/+page.svelte
@@ -40,16 +40,17 @@
let loading_location = false;
let ls_model_location_gcs: LocationGcs[] = [];
- let val_model_location_gcs_selected = ``;
- let val_model_trade_good_key = ``;
+ let sel_model_location_gcs_id = ``;
+ let sel_model_trade_good_key = ``;
$: {
- if (ls_model_location_gcs.length && !val_model_location_gcs_selected)
- val_model_location_gcs_selected = ls_model_location_gcs[0].id;
+ if (ls_model_location_gcs.length && !sel_model_location_gcs_id)
+ sel_model_location_gcs_id = ls_model_location_gcs[0].id;
}
onMount(async () => {
try {
+ sel_model_trade_good_key = trade_keys[0];
await fetch_models_location_gcs();
} catch (e) {
} finally {
@@ -82,6 +83,27 @@
const submit = async (): Promise<void> => {
try {
loading = true;
+
+ if (!sel_model_location_gcs_id) {
+ await lc.dialog.alert(`The product location is missing.`);
+ return;
+ }
+
+ const db_location_gcs = await lc.db.location_gcs_get({
+ id: sel_model_location_gcs_id,
+ });
+
+ if (
+ typeof db_location_gcs === `string` ||
+ db_location_gcs.length !== 1
+ ) {
+ await lc.dialog.alert(
+ `There was an error finding the selected location`,
+ );
+ await goto(`/`);
+ return;
+ }
+
const vals = trade_product_form_vals;
for (const [k, field] of Object.entries(
trade_product_form_fields,
@@ -91,7 +113,7 @@
const field_id = fmt_id(field_k);
const field_val =
field_k === `key`
- ? val_model_trade_good_key
+ ? sel_model_trade_good_key
: await $kv.get(field_id);
if (
@@ -108,11 +130,22 @@
}
vals[field_k] = field_val;
}
- const res = await lc.db.trade_product_add(vals);
- if (typeof res !== `string` && !Array.isArray(res)) {
+ const db_add = await lc.db.trade_product_add(vals);
+ if (typeof db_add !== `string` && !Array.isArray(db_add)) {
+ const { id: trade_product_id } = db_add;
+ const db_rel = await lc.db.set_trade_product_location({
+ trade_product_id,
+ location_gcs_id: db_location_gcs[0].id,
+ });
+ if (typeof db_rel === `string`) {
+ // @todo
+ }
await goto(`/models/trade-product`);
} else {
- await lc.dialog.alert(`There was an error: ${res.toString()}`);
+ // @todo
+ await lc.dialog.alert(
+ `There was an error: ${db_add.toString()}`,
+ );
}
} catch (e) {
console.log(`(error) submit `, e);
@@ -142,8 +175,8 @@
</p>
</div>
<select
- class={`form-select-e w-full bg-layer-1-surface rounded-xl text-layer-2-glyph`}
- bind:value={val_model_trade_good_key}
+ class={`form-select-e w-full bg-layer-1-surface rounded-xl text-layer-1-glyph/70`}
+ bind:value={sel_model_trade_good_key}
on:change={async ({ currentTarget: el }) => {
const val = el.value;
console.log(`val `, val);
@@ -176,12 +209,12 @@
</div>
{:else}
<select
- class={`form-select-e w-full bg-layer-1-surface rounded-xl text-layer-2-glyph`}
- bind:value={val_model_location_gcs_selected}
+ class={`form-select-e w-full bg-layer-1-surface rounded-xl text-layer-1-glyph/70`}
+ bind:value={sel_model_location_gcs_id}
on:change={async ({ currentTarget: el }) => {
const val = el.value;
if (val === texts_key.opt_lcs_add) {
- val_model_location_gcs_selected = ``;
+ sel_model_location_gcs_id = ``;
await add_model_location_gcs();
}
}}
@@ -189,7 +222,7 @@
{#if ls_model_location_gcs.length}
{#each ls_model_location_gcs as li}
<option value={li.id}>
- {li.label}
+ {`${li.label}`}
</option>
{/each}
{:else}
@@ -216,7 +249,9 @@
{`Product - ${texts_kv[field_k] || field_k}`}
</p>
</div>
- <div class={`form-line-e bg-layer-1-surface rounded-xl`}>
+ <div
+ class={`form-line-e bg-layer-1-surface text-layer-1-glyph/70 rounded-xl`}
+ >
<InputForm
basis={{
id: fmt_id(field_k),
diff --git a/src/routes/(app)/nostr/keys/+page.svelte b/src/routes/(app)/nostr/keys/+page.svelte
@@ -12,7 +12,7 @@
onMount(async () => {
try {
- const public_key = await lc.preferences.get(_cf.pref_key_active);
+ const public_key = await lc.preferences.get(_cf.pref.key_active);
if (public_key) nostr_public_key = public_key;
const secret_key = await lc.keystore.get(`nostr:key:${public_key}`);
if (secret_key) nostr_secret_key = secret_key;
diff --git a/src/routes/(app)/settings/+page.svelte b/src/routes/(app)/settings/+page.svelte
@@ -77,7 +77,7 @@
},
callback: async () => {
const public_key = await lc.preferences.get(
- _cf.pref_key_active,
+ _cf.pref.key_active,
);
await lc.dialog.alert(
`Hi! This is your nostr public key ${public_key}`,
@@ -102,7 +102,7 @@
},
callback: async () => {
const public_key = await lc.preferences.get(
- _cf.pref_key_active,
+ _cf.pref.key_active,
);
console.log(`public_key `, public_key);
const secret_key = await lc.keystore.get(
@@ -148,14 +148,14 @@
if (confirm) {
const nostr_public_key =
await lc.preferences.get(
- _cf.pref_key_active,
+ _cf.pref.key_active,
);
if (nostr_public_key) {
await lc.keystore.remove(
`nostr:key:${nostr_public_key}`,
);
await lc.preferences.remove(
- _cf.pref_key_active,
+ _cf.pref.key_active,
);
await restart();
} else {
@@ -252,7 +252,7 @@
},
callback: async () => {
const public_key = await lc.preferences.get(
- _cf.pref_key_active,
+ _cf.pref.key_active,
);
const npub = lc.nostr.lib.npub(public_key);
const url = `https://primal.net/p/${npub}`;
diff --git a/src/routes/(conf)/+layout.ts b/src/routes/(conf)/+layout.ts
@@ -5,7 +5,7 @@ import type { LayoutLoad, LayoutLoadEvent } from '../$types';
export const load: LayoutLoad = async ({ url }: LayoutLoadEvent) => {
try {
- const key_active = await lc.preferences.get(_cf.pref_key_active);
+ const key_active = await lc.preferences.get(_cf.pref.key_active);
if (key_active) {
const ks_keys = await lc.keystore.keys();
const active_nostr_key = ks_keys?.find(
diff --git a/src/routes/(conf)/conf/nostr/+page.svelte b/src/routes/(conf)/conf/nostr/+page.svelte
@@ -16,7 +16,7 @@
sk_hex,
);
if (new_key_added) {
- await lc.preferences.set(_cf.pref_key_active, pk_hex);
+ await lc.preferences.set(_cf.pref.key_active, pk_hex);
await sleep(500);
await restart(true);
}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
@@ -119,7 +119,7 @@
if (!app_config) return;
app_sqlite.set(!!(await lc.db.connect(PUBLIC_DATABASE_NAME)));
const active_nostr_pk = await lc.preferences.get(
- _cf.pref_key_active,
+ _cf.pref.key_active,
);
console.log(`active_nostr_pk `, active_nostr_pk);
const active_nostr_sk = await lc.keystore.get(
@@ -133,7 +133,7 @@
)
app_nostr_key.set(active_nostr_pk);
else {
- await lc.preferences.remove(_cf.pref_key_active);
+ await lc.preferences.remove(_cf.pref.key_active);
await goto(`/conf/nostr`);
}
} catch (e) {