fix: handle undefined accounts

This commit is contained in:
alina 🌸 2025-01-24 07:41:52 +03:00
parent 7d1d8cf8c0
commit 344345dbae
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
3 changed files with 5 additions and 5 deletions

View file

@ -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

View file

@ -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 () => {

View file

@ -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