web


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

commit 35d043c59c5467b5117cf5df8ae5964b3186a525
parent c4fda1760dea226f5faeb63d1a6b69ce7c0887a0
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Mon, 28 Apr 2025 18:26:39 +0000

Add `/farms/details` page, edit routes, utils.

Diffstat:
Mapp/src/lib/util/routes.ts | 2++
Mapp/src/routes/(app)/farms/+page.svelte | 63+++++++++++++++++++++++++++++++++++----------------------------
Aapp/src/routes/(app)/farms/details/+page.svelte | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcrates/tangle/icons/icon.icns | 0
4 files changed, 116 insertions(+), 28 deletions(-)

diff --git a/app/src/lib/util/routes.ts b/app/src/lib/util/routes.ts @@ -2,6 +2,7 @@ export type NavigationRoute = | "/" | "/farms" | "/farms/add" + | "/farms/details" | "/profile" | "/profile/edit" | "/init"; @@ -11,6 +12,7 @@ export function parse_route(route: string): NavigationRoute { case "/": case "/farms": case "/farms/add": + case "/farms/details": case "/profile": case "/profile/edit": case "/init": diff --git a/app/src/routes/(app)/farms/+page.svelte b/app/src/routes/(app)/farms/+page.svelte @@ -2,8 +2,13 @@ import { locale, ls } from "$lib/locale/i18n"; import { db, route } from "$lib/util"; import { lc_geocode } from "$lib/util/callback"; - import { Farms, handle_err, type IViewFarmsData } from "@radroots/lib-app"; - import { location_gcs_to_geolocation_basis } from "@radroots/util"; + import { + Farms, + handle_err, + type FarmBasis, + type IViewFarmsData, + } from "@radroots/lib-app"; + import { location_gcs_to_location_basis } from "@radroots/util"; import { onMount } from "svelte"; type LoadData = IViewFarmsData | undefined; @@ -16,35 +21,36 @@ const load_data = async (): Promise<LoadData> => { try { const tb_farms = await db.farm_read_list(); - if (`err` in tb_farms) return; return { - list: await Promise.all( - tb_farms.results.map(async (i) => { - const tb_loc_gcs = await db.location_gcs_read_list({ - table: [`on_farm`, { id: i.id }], - }); - console.log( - JSON.stringify(tb_loc_gcs, null, 4), - `tb_loc_gcs`, - ); - return { - farm: { - id: i.id, - name: i.name, - }, - geolocation: - `results` in tb_loc_gcs && tb_loc_gcs.results[0] - ? location_gcs_to_geolocation_basis( - tb_loc_gcs.results[0], - ) - : undefined, - }; - }), - ), - }; + list: + `results` in tb_farms + ? (await Promise.all( + tb_farms.results.map(async (i) => { + const tb_loc_gcs = + await db.location_gcs_read_list({ + table: [`on_farm`, { id: i.id }], + }); + return { + farm: { + id: i.id, + name: i.name, + area: i.area, + area_unit: i.area_unit, + }, + location: + `results` in tb_loc_gcs && + tb_loc_gcs.results[0] + ? location_gcs_to_location_basis( + tb_loc_gcs.results[0], + ) + : undefined, + } satisfies FarmBasis; + }), + )) || [] + : [], + } satisfies LoadData; } catch (e) { await handle_err(e, `load`); - } finally { } }; </script> @@ -65,6 +71,7 @@ }, lc_handle_farm_view: async (farm_id) => { try { + await route(`/farms/details`, [[`id`, farm_id]]); } catch (e) { await handle_err(e, `lc_handle_farm_view`); } diff --git a/app/src/routes/(app)/farms/details/+page.svelte b/app/src/routes/(app)/farms/details/+page.svelte @@ -0,0 +1,79 @@ +<script lang="ts"> + import { locale, ls } from "$lib/locale/i18n"; + import { db, route } from "$lib/util"; + import { lc_geocode } from "$lib/util/callback"; + import { + FarmsDetails, + handle_err, + qp_id, + type IViewFarmsDetailsData, + } from "@radroots/lib-app"; + import { location_gcs_to_location_basis } from "@radroots/util"; + import { onMount } from "svelte"; + + type LoadData = IViewFarmsDetailsData | undefined; + let data: LoadData = $state(undefined); + + onMount(async () => { + data = await load_data(); + }); + + const load_data = async (): Promise<LoadData> => { + try { + const tb_farm = await db.farm_read({ id: $qp_id || `` }); + if (`err` in tb_farm) return void route(`/farms`); + const tb_farm_location = await db.location_gcs_read_list({ + table: [`on_farm`, { id: tb_farm.result.id }], + }); + return { + farm: { + ...tb_farm.result, + }, + location: + `results` in tb_farm_location && tb_farm_location.results[0] + ? location_gcs_to_location_basis( + tb_farm_location.results[0], + ) + : undefined, + } satisfies LoadData; + } catch (e) { + await handle_err(e, `load_data`); + } + }; +</script> + +{#if data} + <FarmsDetails + {ls} + {locale} + basis={{ + data, + callback_route: { route: `/farms` }, + lc_geocode, + lc_handle_farm_lot_add: async (farm_id) => { + try { + // await route(`/farms/lots/add`, { farm_id }); + } catch (e) { + await handle_err(e, `lc_handle_farm_lot_add`); + } + }, + lc_handle_farm_products_view: async (farm_id) => { + try { + /* + if (data?.farm_lots?.every((i) => !i.farm_lot_products?.length)) + await route(`/farms/products/add`, { farm_id }); + else + */ + } catch (e) { + await handle_err(e, `lc_handle_farm_products_view`); + } + }, + lc_handle_farm_orders_view: async (farm_id) => { + try { + } catch (e) { + await handle_err(e, `lc_handle_farm_orders_view`); + } + }, + }} + /> +{/if} diff --git a/crates/tangle/icons/icon.icns b/crates/tangle/icons/icon.icns Binary files differ.