Show a loading state on settings save buttons (#387)
Co-authored-by: Coracle-Bot <npub1klq6260@nostr.local>
This commit is contained in:
parent
b4c36c2108
commit
ee5d71dc1d
3 changed files with 38 additions and 15 deletions
|
|
@ -10,6 +10,7 @@
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Card from "@lib/components/Card.svelte"
|
import Card from "@lib/components/Card.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import PageContent from "@lib/components/PageContent.svelte"
|
import PageContent from "@lib/components/PageContent.svelte"
|
||||||
import ProfileMultiSelect from "@app/components/ProfileMultiSelect.svelte"
|
import ProfileMultiSelect from "@app/components/ProfileMultiSelect.svelte"
|
||||||
import {blossomServerLists, deriveUserItem, muteLists} from "@app/core"
|
import {blossomServerLists, deriveUserItem, muteLists} from "@app/core"
|
||||||
|
|
@ -31,16 +32,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const onsubmit = preventDefault(async () => {
|
const onsubmit = preventDefault(async () => {
|
||||||
await publishSettings($settings)
|
loading = true
|
||||||
|
|
||||||
await $muteLists.setMutes({publicTags: mutedPubkeys.map(pubkey => ["p", pubkey])}).then(publish)
|
try {
|
||||||
|
await publishSettings($settings)
|
||||||
|
|
||||||
await $blossomServerLists.setUrls($state.snapshot(blossomServers)).then(publish)
|
await $muteLists
|
||||||
|
.setMutes({publicTags: mutedPubkeys.map(pubkey => ["p", pubkey])})
|
||||||
|
.then(publish)
|
||||||
|
|
||||||
pushToast({message: "Your settings have been saved!"})
|
await $blossomServerLists.setUrls($state.snapshot(blossomServers)).then(publish)
|
||||||
|
|
||||||
|
pushToast({message: "Your settings have been saved!"})
|
||||||
|
} finally {
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const settings = createSettingsForm()
|
const settings = createSettingsForm()
|
||||||
|
let loading = $state(false)
|
||||||
let mutedPubkeys = $state($userMuteList?.pubkeys() ?? [])
|
let mutedPubkeys = $state($userMuteList?.pubkeys() ?? [])
|
||||||
let blossomServers = $state($userBlossomServerList?.urls() ?? [])
|
let blossomServers = $state($userBlossomServerList?.urls() ?? [])
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -128,8 +138,11 @@
|
||||||
</Field>
|
</Field>
|
||||||
</Card>
|
</Card>
|
||||||
<Card class="sticky -bottom-3 shadow-md flex flex-row items-center justify-between gap-4">
|
<Card class="sticky -bottom-3 shadow-md flex flex-row items-center justify-between gap-4">
|
||||||
<Button class="button button-neutral" onclick={reset}>Discard Changes</Button>
|
<Button class="button button-neutral" onclick={reset} disabled={loading}
|
||||||
<Button class="button button-primary" type="submit">Save Changes</Button>
|
>Discard Changes</Button>
|
||||||
|
<Button class="button button-primary" type="submit" disabled={loading}>
|
||||||
|
<Spinner {loading}>Save Changes</Spinner>
|
||||||
|
</Button>
|
||||||
</Card>
|
</Card>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const send = async () => {
|
const send = async () => {
|
||||||
loading = true
|
sendingLogs = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const thunk = await sendLogs()
|
const thunk = await sendLogs()
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
pushToast({message: "Your logs have been sent. Thank you!"})
|
pushToast({message: "Your logs have been sent. Thank you!"})
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
loading = false
|
sendingLogs = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,13 +44,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const onsubmit = preventDefault(async () => {
|
const onsubmit = preventDefault(async () => {
|
||||||
await publishSettings($settings)
|
loading = true
|
||||||
|
|
||||||
pushToast({message: "Your settings have been saved!"})
|
try {
|
||||||
|
await publishSettings($settings)
|
||||||
|
|
||||||
|
pushToast({message: "Your settings have been saved!"})
|
||||||
|
} finally {
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const settings = createSettingsForm()
|
const settings = createSettingsForm()
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
|
let sendingLogs = $state(false)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form {onsubmit}>
|
<form {onsubmit}>
|
||||||
|
|
@ -89,8 +96,8 @@
|
||||||
<p>Something went wrong?</p>
|
<p>Something went wrong?</p>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet input()}
|
{#snippet input()}
|
||||||
<Button class="button button-neutral" onclick={send} disabled={loading}>
|
<Button class="button button-neutral" onclick={send} disabled={sendingLogs}>
|
||||||
<Spinner {loading}>Send Logs</Spinner>
|
<Spinner loading={sendingLogs}>Send Logs</Spinner>
|
||||||
</Button>
|
</Button>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet info()}
|
{#snippet info()}
|
||||||
|
|
@ -101,8 +108,11 @@
|
||||||
</FieldInline>
|
</FieldInline>
|
||||||
</Card>
|
</Card>
|
||||||
<Card class="sticky -bottom-3 shadow-md flex flex-row items-center justify-between gap-4">
|
<Card class="sticky -bottom-3 shadow-md flex flex-row items-center justify-between gap-4">
|
||||||
<Button class="button button-neutral" onclick={reset}>Discard Changes</Button>
|
<Button class="button button-neutral" onclick={reset} disabled={loading}
|
||||||
<Button class="button button-primary" type="submit">Save Changes</Button>
|
>Discard Changes</Button>
|
||||||
|
<Button class="button button-primary" type="submit" disabled={loading}>
|
||||||
|
<Spinner {loading}>Save Changes</Spinner>
|
||||||
|
</Button>
|
||||||
</Card>
|
</Card>
|
||||||
</PageContent>
|
</PageContent>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@
|
||||||
<SignerStatus />
|
<SignerStatus />
|
||||||
{#if pomadeEmail}
|
{#if pomadeEmail}
|
||||||
<div class="flex flex-col lg:flex-row gap-4 lg:gap-2 justify-end">
|
<div class="flex flex-col lg:flex-row gap-4 lg:gap-2 justify-end">
|
||||||
<Button class="button button-neutral" onclick={startPasswordReset}>
|
<Button class="button button-neutral" onclick={startPasswordReset} disabled={loading}>
|
||||||
<Spinner {loading}>Update your password</Spinner>
|
<Spinner {loading}>Update your password</Spinner>
|
||||||
</Button>
|
</Button>
|
||||||
<Button class="button button-primary" onclick={startRecovery}
|
<Button class="button button-primary" onclick={startRecovery}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue