diff --git a/src/lib/accounts/accountStore.ts b/src/lib/accounts/accountStore.ts index 4b77533..1cfda75 100644 --- a/src/lib/accounts/accountStore.ts +++ b/src/lib/accounts/accountStore.ts @@ -75,13 +75,15 @@ class AccountStore implements Readable { await this.identityFileDB.updateIdentityFile(identityFile); } - async createAccount(profile: BlahProfile, password: string) { + async createAccount(profile: BlahProfile, password: string): Promise { const idKeyPair = await BlahKeyPair.generate(true); const actKeyPair = await BlahKeyPair.generate(false); const identity = await BlahIdentity.create(idKeyPair, actKeyPair, profile); const encodedIdKeyPair = await idKeyPair.encode(password); await this.keyDB.addAccount(idKeyPair.id, actKeyPair, encodedIdKeyPair); await this.saveIdentityFile(identity); + await this.loadAccounts(); + return idKeyPair.id; } } diff --git a/src/lib/components/GroupedList/GroupedListItem.svelte b/src/lib/components/GroupedList/GroupedListItem.svelte index d1a7828..3918ade 100644 --- a/src/lib/components/GroupedList/GroupedListItem.svelte +++ b/src/lib/components/GroupedList/GroupedListItem.svelte @@ -8,12 +8,15 @@ {#if icon} { - if (!accountStore) { - accountStore = await openAccountStore(); - } - if (!idKeyId) return; - let currentAccount = $accountStore.find((account) => account.id_key === idKeyId); - if (!currentAccount && $accountStore.length > 0) { - currentAccount = $accountStore[0]; - $currentAccountStore = currentAccount.id_key; - } - return currentAccount; - } + onMount(() => { + openAccountStore().then((store) => { + accountStore = store; + }); + }); -{#await getAccount($currentAccountStore)} - -{:then currentAccount} +{#if accountStore} + {@const currentAccount = $accountStore.find((account) => account.id_key === $currentAccountStore)} -{/await} +{:else} + +{/if} diff --git a/src/routes/(app)/settings/SettingsAccountSections.svelte b/src/routes/(app)/settings/SettingsAccountSections.svelte new file mode 100644 index 0000000..3659dac --- /dev/null +++ b/src/routes/(app)/settings/SettingsAccountSections.svelte @@ -0,0 +1,71 @@ + + +{#if accountStore} + {@const currentAccount = $accountStore.find((acc) => acc.id_key === $currentAccountStore)} + {@const remainingAccounts = $accountStore + .filter((acc) => acc.id_key !== $currentAccountStore) + .toSorted((a, b) => a.profile.signee.payload.name.localeCompare(b.profile.signee.payload.name))} + {#if currentAccount} + {#key currentAccount.id_key} +
+
+ +
+

+ + {currentAccount.profile.signee.payload.name} + +

+

+ + {currentAccount.profile.signee.id_key.slice(0, 6) + + '...' + + currentAccount.profile.signee.id_key.slice(-6)} + +

+
+ {/key} + {/if} + + + {#each remainingAccounts as account (account.id_key)} +
+ switchToAccount(account)}> +
+ {account.profile.signee.payload.name} +
+
+ {/each} +
+{/if} + + + Sign in + Create Account + diff --git a/src/routes/(app)/settings/SettingsList.svelte b/src/routes/(app)/settings/SettingsList.svelte index 1ba6473..4e6c487 100644 --- a/src/routes/(app)/settings/SettingsList.svelte +++ b/src/routes/(app)/settings/SettingsList.svelte @@ -3,18 +3,17 @@ import { GroupedListSection, GroupedListItem } from '$lib/components/GroupedList'; import { tw } from '$lib/tw'; import { - ArrowRightEndOnRectangle, Bell, Cog, DevicePhoneMobile, InformationCircle, LockClosed, - QuestionMarkCircle, - UserPlus + QuestionMarkCircle } from 'svelte-hero-icons'; import { scale } from 'svelte/transition'; import SettingsListItem from './SettingsListItem.svelte'; import PageHeader from '$lib/components/PageHeader.svelte'; + import SettingsAccountSections from './SettingsAccountSections.svelte'; let className = ''; export { className as class }; @@ -30,18 +29,15 @@
- - - Sign in - - Create Account - + + General Notifications Privacy and Security Devices + About Blah & Weblah Ask a Question diff --git a/src/routes/(app)/settings/account/new/+page.svelte b/src/routes/(app)/settings/account/new/+page.svelte index 2465bc4..f877370 100644 --- a/src/routes/(app)/settings/account/new/+page.svelte +++ b/src/routes/(app)/settings/account/new/+page.svelte @@ -1,6 +1,6 @@