fix: handle undefined accounts
This commit is contained in:
parent
7d1d8cf8c0
commit
344345dbae
3 changed files with 5 additions and 5 deletions
|
@ -298,7 +298,7 @@ export function AccountsTab() {
|
|||
return accounts()
|
||||
}
|
||||
|
||||
return accounts().filter((account) => {
|
||||
return accounts()?.filter((account) => {
|
||||
return account.name.toLowerCase().includes(query) || account.telegramId.toString().includes(query)
|
||||
})
|
||||
})
|
||||
|
@ -306,7 +306,7 @@ export function AccountsTab() {
|
|||
return (
|
||||
<>
|
||||
<Show
|
||||
when={accounts().length !== 0}
|
||||
when={accounts()?.length !== 0}
|
||||
fallback={(
|
||||
<div class="flex h-full flex-col items-center justify-center gap-4 text-muted-foreground">
|
||||
No accounts yet
|
||||
|
|
|
@ -25,7 +25,7 @@ export function TdataImportDialog(props: {
|
|||
const [error, setError] = createSignal<string | undefined>('')
|
||||
const [loading, setLoading] = createSignal(false)
|
||||
|
||||
const accountExists = (id: number) => $accounts.get().some(it => it.telegramId === id)
|
||||
const accountExists = (id: number) => $accounts.get()?.some(it => it.telegramId === id)
|
||||
|
||||
let abortController: AbortController | undefined
|
||||
const handleSubmit = async () => {
|
||||
|
|
|
@ -2,13 +2,13 @@ import type { TelegramAccount } from 'mtcute-repl-worker/client'
|
|||
import { computed } from 'nanostores'
|
||||
import { linkedAtom } from './link.ts'
|
||||
|
||||
export const $accounts = linkedAtom<TelegramAccount[]>('accounts')
|
||||
export const $accounts = linkedAtom<TelegramAccount[] | undefined>('accounts')
|
||||
export const $activeAccountId = linkedAtom<string | undefined>('activeAccountId')
|
||||
|
||||
export const $activeAccount = computed([$accounts, $activeAccountId], (accounts, activeAccountId) => {
|
||||
if (!activeAccountId) return null
|
||||
|
||||
const account = accounts.find(account => account.id === activeAccountId)
|
||||
const account = accounts?.find(account => account.id === activeAccountId)
|
||||
if (!account) return null
|
||||
|
||||
return account
|
||||
|
|
Loading…
Reference in a new issue