pinafore/src/routes/_components/AccountsListPage.html

75 lines
1.7 KiB
HTML
Raw Normal View History

<div class="accounts-page">
{#if loading}
<LoadingPage />
{:elseif accounts && accounts.length}
<ul class="accounts-results">
{#each accounts as account}
<AccountSearchResult
{account}
actions={accountActions}
on:click="onClickAction(event)"
/>
{/each}
</ul>
{/if}
</div>
<style>
.accounts-page {
padding: 20px 20px;
position: relative;
}
.accounts-results {
list-style: none;
box-sizing: border-box;
border: 1px solid var(--main-border);
border-radius: 2px;
}
@media (max-width: 767px) {
.accounts-page {
padding: 20px 10px;
}
}
</style>
<script>
import { store } from '../_store/store'
import LoadingPage from './LoadingPage.html'
import AccountSearchResult from './search/AccountSearchResult.html'
2018-12-22 23:37:51 +00:00
import { toast } from './toast/toast'
import { on } from '../_utils/eventBus'
// TODO: paginate
export default {
2018-04-20 04:38:01 +00:00
async oncreate () {
try {
await this.refreshAccounts()
} catch (e) {
toast.say('Error: ' + (e.name || '') + ' ' + (e.message || ''))
} finally {
this.set({ loading: false })
}
on('refreshAccountsList', this, () => this.refreshAccounts())
},
data: () => ({
loading: true,
accounts: [],
2019-08-20 02:08:59 +00:00
accountActions: undefined
}),
store: () => store,
components: {
LoadingPage,
AccountSearchResult
},
methods: {
onClickAction (event) {
2019-08-03 20:49:37 +00:00
const { action, accountId } = event
action.onclick(accountId)
},
async refreshAccounts () {
2019-08-03 20:49:37 +00:00
const { accountsFetcher } = this.get()
const accounts = await accountsFetcher()
this.set({ accounts: accounts })
}
}
}
</script>