web


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

+layout.svelte (1657B)


      1 <script lang="ts">
      2     import { app_init, db, nostr_keys } from "$lib/utils/app";
      3     import { nostr_login_nip01 } from "@radroots/apps-nostr";
      4     import {
      5         nostr_context_default,
      6         nostr_relays_clear,
      7         nostr_relays_open,
      8     } from "@radroots/nostr";
      9     import { handle_err, throw_err } from "@radroots/utils";
     10     import { onMount } from "svelte";
     11     import type { LayoutProps } from "./$types";
     12 
     13     let { data, children }: LayoutProps = $props();
     14     const nostr_context = nostr_context_default();
     15 
     16     onMount(async () => {
     17         try {
     18             await app_init();
     19             await nostr_init();
     20         } catch (e) {
     21             handle_err(e, `on_mount`);
     22         } finally {
     23             //app_splash.set(false);
     24         }
     25     });
     26 
     27     const nostr_init = async (): Promise<void> => {
     28         if (!data.public_key) throw_err(`*-key_nostr`);
     29         const nostr_key = await nostr_keys.read(data.public_key);
     30         if ("err" in nostr_key) throw_err(nostr_key);
     31         const nostr_relays = await db.nostr_relay_find_many({
     32             rel: {
     33                 on_profile: {
     34                     public_key: data.public_key,
     35                 },
     36             },
     37         });
     38         if ("err" in nostr_relays) throw_err(nostr_relays);
     39         const relay_urls = nostr_relays.results.map(({ url }) => url);
     40         nostr_relays_clear(nostr_context);
     41         if (relay_urls.length) nostr_relays_open(nostr_context, relay_urls);
     42         if (relay_urls.length) console.log(`[replica] nostr relays opened`);
     43         nostr_login_nip01(nostr_key.secret_key);
     44         //nostr_ndk_configured.set(true);
     45     };
     46 </script>
     47 
     48 {@render children()}