Fix some type errors

This commit is contained in:
Jon Staab
2025-02-03 15:40:00 -08:00
parent cfbff94b4c
commit 08ee07d157
7 changed files with 65 additions and 71 deletions
+37 -37
View File
@@ -18,18 +18,6 @@
const signUp = () => pushModal(SignUp) const signUp = () => pushModal(SignUp)
const withLoading =
(s: string, cb: (...args: any[]) => any) =>
async (...args: any[]) => {
loading = s
try {
await cb(...args)
} finally {
loading = undefined
}
}
const onSuccess = async (session: Session, relays: string[] = []) => { const onSuccess = async (session: Session, relays: string[] = []) => {
await loadUserData(session.pubkey, {relays}) await loadUserData(session.pubkey, {relays})
@@ -39,32 +27,44 @@
clearModals() clearModals()
} }
const loginWithNip07 = withLoading("nip07", async () => { const loginWithNip07 = async () => {
const pubkey = await getNip07()?.getPublicKey() loading = 'nip07'
if (pubkey) { try {
await onSuccess({method: "nip07", pubkey}) const pubkey = await getNip07()?.getPublicKey()
} else {
pushToast({ if (pubkey) {
theme: "error", await onSuccess({method: "nip07", pubkey})
message: "Something went wrong! Please try again.", } else {
}) pushToast({
theme: "error",
message: "Something went wrong! Please try again.",
})
}
} finally {
loading = undefined
} }
}) }
const loginWithNip55 = withLoading("nip55", async (app: any) => { const loginWithNip55 = async (app: any) => {
const signer = new Nip55Signer(app.packageName) loading = 'nip55'
const pubkey = await signer.getPubkey()
if (pubkey) { try {
await onSuccess({method: "nip55", pubkey, signer: app.packageName}) const signer = new Nip55Signer(app.packageName)
} else { const pubkey = await signer.getPubkey()
pushToast({
theme: "error", if (pubkey) {
message: "Something went wrong! Please try again.", await onSuccess({method: "nip55", pubkey, signer: app.packageName})
}) } else {
pushToast({
theme: "error",
message: "Something went wrong! Please try again.",
})
}
} finally {
loading = undefined
} }
}) }
const loginWithPassword = () => pushModal(LogInPassword) const loginWithPassword = () => pushModal(LogInPassword)
@@ -92,7 +92,7 @@
{#if getNip07()} {#if getNip07()}
<Button disabled={loading} on:click={loginWithNip07} class="btn btn-primary"> <Button disabled={loading} on:click={loginWithNip07} class="btn btn-primary">
{#if loading === "nip07"} {#if loading === "nip07"}
<span class="loading loading-spinner mr-3" /> <span class="loading loading-spinner mr-3"></span>
{:else} {:else}
<Icon icon="widget" /> <Icon icon="widget" />
{/if} {/if}
@@ -102,7 +102,7 @@
{#each signers as app} {#each signers as app}
<Button disabled={loading} class="btn btn-primary" on:click={() => loginWithNip55(app)}> <Button disabled={loading} class="btn btn-primary" on:click={() => loginWithNip55(app)}>
{#if loading === "nip55"} {#if loading === "nip55"}
<span class="loading loading-spinner mr-3" /> <span class="loading loading-spinner mr-3"></span>
{:else} {:else}
<img src={app.iconUrl} alt={app.name} width="20" height="20" /> <img src={app.iconUrl} alt={app.name} width="20" height="20" />
{/if} {/if}
@@ -112,7 +112,7 @@
{#if BURROW_URL && !hasSigner} {#if BURROW_URL && !hasSigner}
<Button disabled={loading} on:click={loginWithPassword} class="btn btn-primary"> <Button disabled={loading} on:click={loginWithPassword} class="btn btn-primary">
{#if loading === "password"} {#if loading === "password"}
<span class="loading loading-spinner mr-3" /> <span class="loading loading-spinner mr-3"></span>
{:else} {:else}
<Icon icon="key" /> <Icon icon="key" />
{/if} {/if}
@@ -129,7 +129,7 @@
{#if BURROW_URL && hasSigner} {#if BURROW_URL && hasSigner}
<Button disabled={loading} on:click={loginWithPassword} class="btn"> <Button disabled={loading} on:click={loginWithPassword} class="btn">
{#if loading === "password"} {#if loading === "password"}
<span class="loading loading-spinner mr-3" /> <span class="loading loading-spinner mr-3"></span>
{:else} {:else}
<Icon icon="key" /> <Icon icon="key" />
{/if} {/if}
+6 -4
View File
@@ -50,10 +50,12 @@
component={ThunkStatusDetail} component={ThunkStatusDetail}
props={{url, message, status, retry}} props={{url, message, status, retry}}
params={{interactive: true}}> params={{interactive: true}}>
<span class="flex cursor-pointer items-center gap-1 text-error"> {#snippet children()}
<Icon icon="danger" size={3} /> <span class="flex cursor-pointer items-center gap-1 text-error">
<span>Failed to send!</span> <Icon icon="danger" size={3} />
</span> <span>Failed to send!</span>
</span>
{/snippet}
</Tippy> </Tippy>
</div> </div>
{:else if canCancel || isPending} {:else if canCancel || isPending}
+1 -1
View File
@@ -84,7 +84,7 @@ export const makeEditor = ({
editor: (this as any).editor, editor: (this as any).editor,
search: derived(profileSearch, s => s.searchValues), search: derived(profileSearch, s => s.searchValues),
getRelays: (pubkey: string) => ctx.app.router.FromPubkeys([pubkey]).getUrls(), getRelays: (pubkey: string) => ctx.app.router.FromPubkeys([pubkey]).getUrls(),
component: ProfileSuggestion as unknown as Component, component: ProfileSuggestion,
}), }),
] ]
}, },
+2 -2
View File
@@ -22,7 +22,7 @@ export const emitter = new Emitter()
export const modals = writable<Record<string, Modal>>({}) export const modals = writable<Record<string, Modal>>({})
export const pushModal = ( export const pushModal = (
component: Component, component: Component<any>,
props: Record<string, any> = {}, props: Record<string, any> = {},
options: ModalOptions = {}, options: ModalOptions = {},
) => { ) => {
@@ -37,7 +37,7 @@ export const pushModal = (
} }
export const pushDrawer = ( export const pushDrawer = (
component: Component, component: Component<any>,
props: Record<string, any> = {}, props: Record<string, any> = {},
options: ModalOptions = {}, options: ModalOptions = {},
) => pushModal(component, props, {...options, drawer: true}) ) => pushModal(component, props, {...options, drawer: true})
+1 -2
View File
@@ -1,5 +1,4 @@
<script lang="ts"> <script lang="ts">
import type {SvelteComponent} from "svelte"
import {readable} from "svelte/store" import {readable} from "svelte/store"
import {type Instance} from "tippy.js" import {type Instance} from "tippy.js"
import {identity} from "@welshman/lib" import {identity} from "@welshman/lib"
@@ -14,7 +13,7 @@
let input: Element let input: Element
let popover: Instance let popover: Instance
let instance: SvelteComponent let instance: any
const search = readable( const search = readable(
createSearch(options, { createSearch(options, {
+9 -14
View File
@@ -1,20 +1,15 @@
<script lang="ts"> <script lang="ts">
import "tippy.js/animations/shift-away.css" import "tippy.js/animations/shift-away.css"
import {onMount} from "svelte" import tippy from "tippy.js"
import type {Component, ComponentProps} from "svelte" import {onMount, mount, unmount} from "svelte"
import tippy, {type Instance, type Props} from "tippy.js"
export let component: Component let {component, children = undefined, props = {}, params = {}, popover = $bindable(), instance = $bindable(), ...restProps} = $props()
export let props: ComponentProps<any> = {}
export let params: Partial<Props> = {} let reactiveProps = $derived(props)
export let popover: Instance | undefined = undefined
export let instance: Component | undefined = undefined
let element: Element let element: Element
$: instance?.$set(props)
onMount(() => { onMount(() => {
if (element) { if (element) {
const target = document.createElement("div") const target = document.createElement("div")
@@ -26,16 +21,16 @@
...params, ...params,
}) })
instance = new component({target, props}) instance = mount(component, {target, props: reactiveProps})
return () => { return () => {
popover?.destroy() popover?.destroy()
instance?.$destroy() unmount(instance)
} }
} }
}) })
</script> </script>
<div bind:this={element} class={$$props.class}> <div bind:this={element} class={restProps.class}>
<slot /> {@render children?.()}
</div> </div>
+9 -11
View File
@@ -134,19 +134,17 @@
if (events) { if (events) {
for (const event of $events.toReversed()) { for (const event of $events.toReversed()) {
const {id, pubkey, created_at} = event if (seen.has(event.id)) {
if (seen.has(id)) {
continue continue
} }
const date = formatTimestampAsDate(created_at) const date = formatTimestampAsDate(event.created_at)
if ( if (
!newMessagesSeen && !newMessagesSeen &&
event.pubkey !== $pubkey && event.pubkey !== $pubkey &&
lastChecked && lastChecked &&
created_at > lastChecked event.created_at > lastChecked
) { ) {
elements.push({type: "new-messages", id: "new-messages"}) elements.push({type: "new-messages", id: "new-messages"})
newMessagesSeen = true newMessagesSeen = true
@@ -157,15 +155,15 @@
} }
elements.push({ elements.push({
id, id: event.id,
type: "note", type: "note",
value: event, value: event,
showPubkey: date !== previousDate || previousPubkey !== pubkey, showPubkey: date !== previousDate || previousPubkey !== event.pubkey,
}) })
previousDate = date previousDate = date
previousPubkey = pubkey previousPubkey = event.pubkey
seen.add(id) seen.add(event.id)
} }
} }
@@ -230,9 +228,9 @@
bind:this={newMessages} bind:this={newMessages}
class="flex items-center py-2 text-xs transition-colors" class="flex items-center py-2 text-xs transition-colors"
class:opacity-0={showFixedNewMessages}> class:opacity-0={showFixedNewMessages}>
<div class="h-px flex-grow bg-primary" /> <div class="h-px flex-grow bg-primary"></div>
<p class="rounded-full bg-primary px-2 py-1 text-primary-content">New Messages</p> <p class="rounded-full bg-primary px-2 py-1 text-primary-content">New Messages</p>
<div class="h-px flex-grow bg-primary" /> <div class="h-px flex-grow bg-primary"></div>
</div> </div>
{:else if type === "date"} {:else if type === "date"}
<Divider>{value}</Divider> <Divider>{value}</Divider>