Skip to content

Commit

Permalink
fix: store the current state of the ListCard in localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 12, 2020
1 parent a8ce36c commit ed6d7c1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
7 changes: 6 additions & 1 deletion packages/dapp-svelte-wallet/ui/lib/ListCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// true iff new items should start expanded
export let expandDefault = false;
let expandState = [];
export let storeKey = '';
let expandState = storeKey ? JSON.parse(localStorage.getItem(`ListCard.${storeKey}`) || '[]') : [];
$: isExpanded = id => expandState.includes(id) !== expandDefault;
Expand All @@ -25,6 +27,9 @@
} else {
expandState = [...expandState, id];
}
if (storeKey) {
localStorage.setItem(`ListCard.${storeKey}`, JSON.stringify(expandState));
}
};
</script>

Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/Contacts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { contacts, walletP } from './store';
</script>

<ListCard items={$contacts}>
<ListCard storeKey="contacts" items={$contacts}>
<div slot="title">
<Card.Title
title="Contacts"
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/Dapps.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
export let expandDefault = true;
</script>

<ListCard items={$dapps} expandDefault={expandDefault}>
<ListCard items={$dapps} storeKey="dapps-{expandDefault}" {expandDefault}>
<div slot="title">
<Card.Title title="Dapps" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/Issuers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { issuers, walletP } from './store';
</script>

<ListCard items={$issuers}>
<ListCard items={$issuers} storeKey="issuers">
<div slot="title">
<Card.Title
title="Issuers"
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/Payments.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Card from "smelte/src/components/Card";
$: paymentItems = $payments.filter(pmt => pmt.status !== 'deposited');
</script>

<ListCard items={paymentItems} expandDefault={true}>
<ListCard items={paymentItems} storeKey="payments.true" expandDefault={true}>
<div slot="title">
<Card.Title title="Incoming Payments" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/Purses.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { purses } from './store';
</script>

<ListCard items={$purses}>
<ListCard items={$purses} storeKey="purses">
<div slot="title">
<Card.Title title="Purses" />
</div>
Expand Down
6 changes: 5 additions & 1 deletion packages/dapp-svelte-wallet/ui/src/Transactions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
</script>

<!-- filter out the history -->
<ListCard items={($inbox || []).filter(({ status }) => status === undefined || status === 'pending')} expandDefault={true}>
<ListCard
items={($inbox || []).filter(({ status }) => status === undefined || status === 'pending')}
storeKey="inbox"
expandDefault={true}
>
<div slot="title">
<Card.Title title="Offers" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/ui/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function makeCapTPConnection(makeConnection, { onReset }) {
// Throw away our state.
bootPK = makePromiseKit();
onReset(bootPK.promise.then(_ => true));
abort();
abort && abort();
}

// Stable identity for the connection handler.
Expand Down

0 comments on commit ed6d7c1

Please sign in to comment.