farms.svelte (3065B)
1 <script lang="ts"> 2 import ButtonGlyphSimple from "$lib/components/button/button-glyph-simple.svelte"; 3 import ButtonLabelDashed from "$lib/components/button/button-label-dashed.svelte"; 4 import FarmsPreviewCard from "$lib/components/farm/farms-preview-card.svelte"; 5 import LayoutPage from "$lib/components/layout/layout-page.svelte"; 6 import LayoutView from "$lib/components/layout/layout-view.svelte"; 7 import PageToolbar from "$lib/components/navigation/page-toolbar.svelte"; 8 import type { LibContext } from "$lib/types/context"; 9 import type { IViewBasis } from "$lib/types/views"; 10 import type { IViewFarmsData } from "$lib/types/views/farms"; 11 import { idb_kv_init_page } from "$lib/utils/keyval"; 12 import { 13 Fade, 14 get_context, 15 type CallbackRoute, 16 } from "@radroots/apps-lib"; 17 import { 18 handle_err, 19 type CallbackPromise, 20 type CallbackPromiseGeneric, 21 } from "@radroots/utils"; 22 import { onMount } from "svelte"; 23 24 const { ls } = get_context<LibContext>(`lib`); 25 26 let { 27 basis, 28 }: { 29 basis: IViewBasis<{ 30 data?: IViewFarmsData; 31 callback_route?: CallbackRoute<string>; 32 on_handle_farm_add: CallbackPromise; 33 on_handle_farm_view: CallbackPromiseGeneric<string>; 34 }>; 35 } = $props(); 36 37 onMount(async () => { 38 try { 39 if (!basis.kv_init_prevent) await idb_kv_init_page(); 40 } catch (e) { 41 handle_err(e, `on_mount`); 42 } 43 }); 44 </script> 45 46 <LayoutView> 47 <PageToolbar 48 basis={{ 49 header: { 50 label: `${$ls(`common.farms`)}`, 51 callback_route: basis.callback_route, 52 }, 53 }} 54 > 55 {#snippet header_option()} 56 {#if basis.data?.list.length} 57 <Fade> 58 <ButtonGlyphSimple 59 basis={{ 60 label: `${$ls(`icu.add_*`, { 61 value: `${$ls(`common.farm`)}`, 62 })}`, 63 callback: async () => { 64 await basis.on_handle_farm_add(); 65 }, 66 }} 67 /> 68 </Fade> 69 {/if} 70 {/snippet} 71 </PageToolbar> 72 <LayoutPage> 73 {#if basis.data} 74 {#if basis.data?.list.length} 75 {#each basis.data?.list || [] as li} 76 <FarmsPreviewCard 77 basis={li} 78 on_handle_farm_view={basis.on_handle_farm_view} 79 /> 80 {/each} 81 {:else} 82 <ButtonLabelDashed 83 basis={{ 84 label: `Add farm`, 85 callback: async () => { 86 await basis.on_handle_farm_add(); 87 }, 88 }} 89 /> 90 {/if} 91 {/if} 92 </LayoutPage> 93 </LayoutView>