Apps
A full mail client: folders, labels, threads, a floating composer and keyboard shortcuts. The reference app for plugging in a backend.
Email is the reference app: if you understand how it loads, filters and saves data, you understand all of them. Messages that share a threadId form one conversation: the list shows one row per conversation, actions apply to the whole conversation and the reader shows the thread with older messages collapsed and an inline reply.
Every app follows the same pattern: typed models in types/models/, demo data in mocks/, state and actions in a composable under composables/apps/, page-only components in components/pages/<app>/ and UI strings in locales/<code>/apps.json. Read the apps overview once and every app looks familiar.
Files
File | Role |
|---|---|
pages/email.vue | The page: split view, selection and keyboard shortcuts. |
composables/apps/useEmail.ts | State, filters, conversations and actions. |
types/models/email.ts | Messages, conversations, folders, labels and the provider. |
config/email.config.ts | Folders, labels and the default reading pane. |
mocks/email.mock.ts | Demo messages and createEmailMockProvider(). |
components/pages/email/ | EmailFolderNav, EmailList, EmailListItem, EmailReader, EmailThreadMessage, EmailComposer, EmailRecipientField. |
Data and provider
export interface EmailMessage {
id: string
threadId: string
folder: string
from: EmailSender
to: string
cc?: string
subject: string
body: string[]
sentAt: string
read: boolean
starred: boolean
labels: string[]
attachments: EmailAttachment[]
}
export interface EmailProvider {
list: () => Promise<EmailMessage[]>
update: (ids: string[], patch: EmailMessagePatch) => Promise<void>
send: (message: EmailMessage) => Promise<void>
}
Connect your backend
The page calls useEmail() with the mock provider. Write a provider that calls your API with useApi() and pass it in the page. The composable loads it through useAsyncData and applies every change optimistically, so the interface does not wait for the server.
import type { EmailMessage, EmailProvider } from '~/types/models/email'
export function createEmailApiProvider(): EmailProvider {
const api = useApi()
return {
list: () => api<EmailMessage[]>('/messages'),
update: (ids, patch) => api('/messages', { method: 'PATCH', body: { ids, patch } }),
send: (message) => api('/messages', { method: 'POST', body: message }),
}
}
<script setup lang="ts">
import { createEmailApiProvider } from '~/providers/email'
const { ... } = useEmail({ provider: createEmailApiProvider() })
</script>
Keep ids in your data and labels in the locales: folders, labels and tags resolve their names through apps.<app>.* unless you give them a raw title. See Connect your API for the token, validation errors and the actions the demo only fakes.
Configuration
EMAIL_FOLDERS
Folders as data: icon, count (unread or total) and an optional filter for virtual folders such as Starred.
const EMAIL_FOLDERS: EmailFolderConfig[]
EMAIL_LABELS
Labels with their color and an optional raw title; otherwise the name comes from apps.email.labels.<id>.
const EMAIL_LABELS: EmailLabelConfig[]
EMAIL_DEFAULT_VIEW
The reading pane the first time: right, none or drawer. The user’s choice persists in the email-view cookie.
const EMAIL_DEFAULT_VIEW: EmailViewSettings
How it works
- The page is a
BaseSplitView: folders innav(lg+), the list, the reader indetail. On phones the reader replaces the list. - Compose is the floating
EmailComposer, not a dialog. Recipients are chips fromEmailRecipientField, aBaseComboboxthat suggestscontactsand validates each address. - List rows switch to a one-line layout through the
email-listcontainer query when the list is at least 720px wide. - Times come from
useRelativeDay()and stay empty until mount, so a server in another time zone cannot cause a hydration mismatch. - Attachments render with
BaseAttachment.
Keyboard shortcuts
Registered with useHotkey in pages/email.vue and shown in the tooltips of their buttons.
Key | Action |
|---|---|
j / k | Next / previous conversation |
e | Archive |
s | Star |
u | Mark as unread |
r | Reply |
c | Compose |
/ | Search |
esc | Close the conversation |