fix(email): pick the only recipient when none is starred

Creating a recipient never makes it the default, so a single-Kindle setup
opened the send sheet with nobody ticked and Send disabled. Tick the lone
recipient in that case; a starred default still wins.

Ref #1443
This commit is contained in:
neon
2026-10-20 15:47:19 +00:00
parent 2e454cc846
commit 192c205299
2 changed files with 34 additions and 2 deletions
@@ -106,8 +106,7 @@ watch(
loaded.value = false loaded.value = false
await Promise.all([fetchRecipients(), fetchGroups(), fetchProviders(), fetchTemplates(), fetchPreferences()].map((p) => p.catch(() => undefined))) await Promise.all([fetchRecipients(), fetchGroups(), fetchProviders(), fetchTemplates(), fetchPreferences()].map((p) => p.catch(() => undefined)))
loaded.value = true loaded.value = true
const defaultRecipient = preferences.value?.defaultRecipientId selectedIds.value = initialRecipientIds()
selectedIds.value = defaultRecipient && recipients.value.some((r) => r.id === defaultRecipient) ? [defaultRecipient] : []
providerId.value = preferences.value?.defaultProviderId ?? providers.value[0]?.id ?? null providerId.value = preferences.value?.defaultProviderId ?? providers.value[0]?.id ?? null
}, },
{ immediate: true }, { immediate: true },
@@ -115,6 +114,14 @@ watch(
onBeforeUnmount(stopPolling) onBeforeUnmount(stopPolling)
/** The starred recipient, or the only one when nobody starred it: creating a recipient never makes it the default. */
function initialRecipientIds(): number[] {
const defaultId = preferences.value?.defaultRecipientId
if (defaultId && recipients.value.some((r) => r.id === defaultId)) return [defaultId]
const [only, ...rest] = recipients.value
return only && rest.length === 0 ? [only.id] : []
}
/** What each picked recipient gets, and the line a row shows when that differs from the rest. */ /** What each picked recipient gets, and the line a row shows when that differs from the rest. */
function exceptionFor(recipient: EmailRecipient): { text: string; warn: boolean } | null { function exceptionFor(recipient: EmailRecipient): { text: string; warn: boolean } | null {
if (singleBookId.value === null || files.value.length === 0) return null if (singleBookId.value === null || files.value.length === 0) return null
@@ -120,6 +120,31 @@ describe('SendBookDialog', () => {
expect(mockState.sendBook).toHaveBeenCalledWith({ bookIds: [12], recipientIds: [10], providerId: 3, templateId: undefined, fileId: undefined }) expect(mockState.sendBook).toHaveBeenCalledWith({ bookIds: [12], recipientIds: [10], providerId: 3, templateId: undefined, fileId: undefined })
}) })
it('picks the only recipient when nobody starred one', async () => {
recipients.value = recipients.value.slice(0, 1)
groups.value = []
preferences.value = null
mountSheet()
await flushPromises()
expect(recipientRow('Kindle Paperwhite').getAttribute('aria-checked')).toBe('true')
buttonByText('Send').click()
await flushPromises()
expect(mockState.sendBook).toHaveBeenCalledWith(expect.objectContaining({ recipientIds: [10], providerId: 3 }))
})
it('leaves the choice open when several recipients exist and none is starred', async () => {
preferences.value = null
mountSheet()
await flushPromises()
expect(recipientRow('Kindle Paperwhite').getAttribute('aria-checked')).toBe('false')
expect(recipientRow('Ana Beck').getAttribute('aria-checked')).toBe('false')
expect(buttonByText('Send').disabled).toBe(true)
})
it('says what a recipient gets only when it differs from the rest', async () => { it('says what a recipient gets only when it differs from the rest', async () => {
mountSheet() mountSheet()
await flushPromises() await flushPromises()