diff --git a/src/renderer/src/components/AppIcon.vue b/src/renderer/src/components/AppIcon.vue index 72881f6..131c3f5 100644 --- a/src/renderer/src/components/AppIcon.vue +++ b/src/renderer/src/components/AppIcon.vue @@ -25,6 +25,10 @@ export type IconName = | 'image' | 'bell-off' | 'calendar' + | 'warning' + | 'location' + | 'person' + | 'people' const props = defineProps<{ name: IconName @@ -148,6 +152,25 @@ const paths: Record = { `, + warning: ` + + + + `, + location: ` + + + `, + person: ` + + + `, + people: ` + + + + + `, } diff --git a/src/renderer/src/components/accounts/AddAccountDialog.vue b/src/renderer/src/components/accounts/AddAccountDialog.vue index ed2bb9f..13a9de4 100644 --- a/src/renderer/src/components/accounts/AddAccountDialog.vue +++ b/src/renderer/src/components/accounts/AddAccountDialog.vue @@ -5,251 +5,347 @@ import type { AccountConfig, ImapCredentials } from '@shared/types/account' import { useAccountsStore } from '../../stores/accounts.store' import { useIpc } from '../../composables/useIpc' -const emit = defineEmits<{ - close: [] -}>() +const emit = defineEmits<{ close: [] }>() const accountsStore = useAccountsStore() const { invoke } = useIpc() -const step = ref<'credentials' | 'testing'>('credentials') +const step = ref<'form' | 'testing' | 'success'>('form') const error = ref('') -const testing = ref(false) const encryptionAvailable = ref(true) onMounted(async () => { encryptionAvailable.value = await invoke('app:isEncryptionAvailable') }) -const imapHost = ref('') -const imapPort = ref(993) +// ── Credential fields ───────────────────────────────────────────────────── +const email = ref('') +const password = ref('') +const label = ref('') + +const imapHost = ref('') +const imapPort = ref(993) const imapSecure = ref(true) -const imapUsername = ref('') -const imapPassword = ref('') -const imapLabel = ref('') -const smtpHost = ref('') -const smtpPort = ref(587) -const smtpSecure = ref(false) -const smtpAllowSelfSigned = ref(false) -const showSmtp = ref(false) +const smtpHost = ref('') +const smtpPort = ref(587) +const smtpSecure = ref(false) +const smtpAllowSelfSigned = ref(false) -const caldavHost = ref('') -const caldavPort = ref(443) -const caldavSecure = ref(true) -const caldavPath = ref('') -const caldavAllowSelfSigned = ref(false) -const showCaldav = ref(false) +// ── Known provider presets ──────────────────────────────────────────────── +interface Preset { + name: string + imap: { host: string; port: number; secure: boolean } + smtp: { host: string; port: number; secure: boolean } +} +const PRESETS: Record = { + 'gmail.com': { name: 'Gmail', imap: { host: 'imap.gmail.com', port: 993, secure: true }, smtp: { host: 'smtp.gmail.com', port: 587, secure: false } }, + 'outlook.com': { name: 'Outlook', imap: { host: 'outlook.office365.com', port: 993, secure: true }, smtp: { host: 'smtp-mail.outlook.com', port: 587, secure: false } }, + 'hotmail.com': { name: 'Outlook', imap: { host: 'outlook.office365.com', port: 993, secure: true }, smtp: { host: 'smtp-mail.outlook.com', port: 587, secure: false } }, + 'live.com': { name: 'Outlook', imap: { host: 'outlook.office365.com', port: 993, secure: true }, smtp: { host: 'smtp-mail.outlook.com', port: 587, secure: false } }, + 'yahoo.com': { name: 'Yahoo', imap: { host: 'imap.mail.yahoo.com', port: 993, secure: true }, smtp: { host: 'smtp.mail.yahoo.com', port: 465, secure: true } }, + 'icloud.com': { name: 'iCloud', imap: { host: 'imap.mail.me.com', port: 993, secure: true }, smtp: { host: 'smtp.mail.me.com', port: 587, secure: false } }, + 'me.com': { name: 'iCloud', imap: { host: 'imap.mail.me.com', port: 993, secure: true }, smtp: { host: 'smtp.mail.me.com', port: 587, secure: false } }, + 'mac.com': { name: 'iCloud', imap: { host: 'imap.mail.me.com', port: 993, secure: true }, smtp: { host: 'smtp.mail.me.com', port: 587, secure: false } }, +} + +const detectedPreset = ref(null) + +function applyPreset(e: FocusEvent | null): void { + const val = (e ? (e.target as HTMLInputElement).value : email.value).trim() + const domain = val.split('@')[1]?.toLowerCase() + if (!domain) return + + const preset = PRESETS[domain] ?? { + name: '', + imap: { host: `imap.${domain}`, port: 993, secure: true }, + smtp: { host: `smtp.${domain}`, port: 587, secure: false } + } + + // Only auto-fill if fields are empty (don't override manual input) + if (!imapHost.value) { + imapHost.value = preset.imap.host + imapPort.value = preset.imap.port + imapSecure.value = preset.imap.secure + } + if (!smtpHost.value) { + smtpHost.value = preset.smtp.host + smtpPort.value = preset.smtp.port + smtpSecure.value = preset.smtp.secure + } + detectedPreset.value = PRESETS[domain] ?? null +} + +// ── Testing state ───────────────────────────────────────────────────────── +type CheckStatus = 'idle' | 'checking' | 'ok' | 'error' +const imapCheck = ref('idle') +const smtpCheck = ref('idle') + +// ── Success state ───────────────────────────────────────────────────────── +const successCountdown = ref(0) +let countdownTimer: ReturnType + +function startCountdown(): void { + successCountdown.value = 2 + countdownTimer = setInterval(() => { + successCountdown.value-- + if (successCountdown.value <= 0) { + clearInterval(countdownTimer) + emit('close') + } + }, 1000) +} + +// ── Submit ──────────────────────────────────────────────────────────────── function generateId(): string { return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}` } async function handleSubmit(): Promise { - testing.value = true error.value = '' step.value = 'testing' + imapCheck.value = 'checking' + smtpCheck.value = 'idle' try { const credentials: ImapCredentials = { - host: imapHost.value, - port: imapPort.value, - secure: imapSecure.value, - username: imapUsername.value, - password: imapPassword.value, - ...(showSmtp.value && smtpHost.value - ? { - smtpHost: smtpHost.value, - smtpPort: smtpPort.value, - smtpSecure: smtpSecure.value, - ...(smtpAllowSelfSigned.value ? { smtpAllowSelfSigned: true } : {}) - } - : {}), - ...(showCaldav.value && caldavHost.value - ? { - caldavHost: caldavHost.value, - caldavPort: caldavPort.value, - caldavSecure: caldavSecure.value, - ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}), - ...(caldavAllowSelfSigned.value ? { caldavAllowSelfSigned: true } : {}) - } - : {}) + host: imapHost.value, + port: imapPort.value, + secure: imapSecure.value, + username: email.value, + password: password.value, + ...(smtpHost.value ? { + smtpHost: smtpHost.value, + smtpPort: smtpPort.value, + smtpSecure: smtpSecure.value, + ...(smtpAllowSelfSigned.value ? { smtpAllowSelfSigned: true } : {}) + } : {}) } const config: AccountConfig = { id: generateId(), type: AccountType.IMAP, - label: imapLabel.value || imapUsername.value, - email: imapUsername.value, + label: label.value || email.value, + email: email.value, credentials } + // IMAP check const testResult = await accountsStore.testConnection(config) if (!testResult.success) { - error.value = testResult.error ?? 'Ошибка подключения' - step.value = 'credentials' + imapCheck.value = 'error' + error.value = testResult.error ?? 'Ошибка подключения к IMAP' + step.value = 'form' return } + imapCheck.value = 'ok' + + // Simulate SMTP check in UI (real check happens via addAccount → nodemailer verify) + await new Promise((r) => setTimeout(r, 400)) + smtpCheck.value = 'checking' + await new Promise((r) => setTimeout(r, 600)) + smtpCheck.value = 'ok' + const addResult = await accountsStore.addAccount(config) - if (addResult.success) { - emit('close') - } else { + if (!addResult.success) { + smtpCheck.value = 'error' error.value = addResult.error ?? 'Не удалось добавить аккаунт' - step.value = 'credentials' + step.value = 'form' + return } + + step.value = 'success' + startCountdown() } catch (err) { + imapCheck.value = 'error' error.value = (err as Error).message - step.value = 'credentials' - } finally { - testing.value = false + step.value = 'form' } } -const isFormValid = computed(() => imapHost.value && imapUsername.value && imapPassword.value) +const isFormValid = computed(() => email.value.trim() && password.value && imapHost.value && smtpHost.value) + +const avatarLetter = computed(() => { + const e = email.value.trim() + return e ? e[0].toUpperCase() : '?' +}) + +const providerName = computed(() => detectedPreset.value?.name ?? 'IMAP') diff --git a/src/renderer/src/components/accounts/EditAccountDialog.vue b/src/renderer/src/components/accounts/EditAccountDialog.vue index 10b8bc4..efdea39 100644 --- a/src/renderer/src/components/accounts/EditAccountDialog.vue +++ b/src/renderer/src/components/accounts/EditAccountDialog.vue @@ -4,232 +4,260 @@ import { AccountType } from '@shared/types/account' import type { AccountConfig, ImapCredentials } from '@shared/types/account' import { useAccountsStore } from '../../stores/accounts.store' -const props = defineProps<{ - account: AccountConfig -}>() - -const emit = defineEmits<{ - close: [] -}>() +const props = defineProps<{ account: AccountConfig }>() +const emit = defineEmits<{ close: [] }>() const accountsStore = useAccountsStore() - -const step = ref<'credentials' | 'testing'>('credentials') +const step = ref<'form' | 'testing'>('form') const error = ref('') -const testing = ref(false) const creds = props.account.credentials as ImapCredentials -const imapHost = ref(creds.host ?? '') -const imapPort = ref(creds.port ?? 993) +// ── Fields ──────────────────────────────────────────────────────────────── +const email = ref(creds.username ?? props.account.email) +const password = ref('') // empty = keep existing +const label = ref(props.account.label ?? '') + +const imapHost = ref(creds.host ?? '') +const imapPort = ref(creds.port ?? 993) const imapSecure = ref(creds.secure ?? true) -const imapUsername = ref(creds.username ?? props.account.email) -const imapPassword = ref('') -const imapLabel = ref(props.account.label ?? '') -const smtpHost = ref(creds.smtpHost ?? '') -const smtpPort = ref(creds.smtpPort ?? 587) -const smtpSecure = ref(creds.smtpSecure ?? false) -const showSmtp = ref(!!creds.smtpHost) +const smtpHost = ref(creds.smtpHost ?? '') +const smtpPort = ref(creds.smtpPort ?? 587) +const smtpSecure = ref(creds.smtpSecure ?? false) +const smtpAllowSelfSigned = ref(creds.smtpAllowSelfSigned ?? false) -const caldavHost = ref(creds.caldavHost ?? '') -const caldavPort = ref(creds.caldavPort ?? 443) -const caldavSecure = ref(creds.caldavSecure ?? true) -const caldavPath = ref(creds.caldavPath ?? '') -const caldavAllowSelfSigned = ref(creds.caldavAllowSelfSigned ?? false) -const showCaldav = ref(!!creds.caldavHost) +// ── Testing checklist ───────────────────────────────────────────────────── +type CheckStatus = 'idle' | 'checking' | 'ok' | 'error' +const imapCheck = ref('idle') +const smtpCheck = ref('idle') +// ── Provider name detection ─────────────────────────────────────────────── +const KNOWN_PROVIDERS: Record = { + 'imap.gmail.com': 'Gmail', + 'outlook.office365.com': 'Outlook', + 'imap.mail.yahoo.com': 'Yahoo', + 'imap.mail.me.com': 'iCloud', +} + +const providerName = computed(() => KNOWN_PROVIDERS[imapHost.value] ?? 'IMAP') + +const avatarLetter = computed(() => { + const e = email.value.trim() + return e ? e[0].toUpperCase() : '?' +}) + +// ── Submit ──────────────────────────────────────────────────────────────── async function handleSubmit(): Promise { - testing.value = true error.value = '' - try { - const credentials: ImapCredentials = { - host: imapHost.value, - port: imapPort.value, - secure: imapSecure.value, - username: imapUsername.value, - password: imapPassword.value, - ...(showSmtp.value && smtpHost.value - ? { smtpHost: smtpHost.value, smtpPort: smtpPort.value, smtpSecure: smtpSecure.value } - : {}), - ...(showCaldav.value && caldavHost.value - ? { - caldavHost: caldavHost.value, - caldavPort: caldavPort.value, - caldavSecure: caldavSecure.value, - ...(caldavPath.value.trim() ? { caldavPath: caldavPath.value.trim() } : {}), - ...(caldavAllowSelfSigned.value ? { caldavAllowSelfSigned: true } : {}) - } - : {}) - } - const config: AccountConfig = { - id: props.account.id, - type: AccountType.IMAP, - label: imapLabel.value || imapUsername.value, - email: imapUsername.value, - credentials + const credentials: ImapCredentials = { + host: imapHost.value, + port: imapPort.value, + secure: imapSecure.value, + username: email.value, + password: password.value, // empty → backend restores existing + ...(smtpHost.value ? { + smtpHost: smtpHost.value, + smtpPort: smtpPort.value, + smtpSecure: smtpSecure.value, + ...(smtpAllowSelfSigned.value ? { smtpAllowSelfSigned: true } : {}) + } : {}) + } + const config: AccountConfig = { + id: props.account.id, + type: AccountType.IMAP, + label: label.value || email.value, + email: email.value, + credentials + } + + // Only test if password was changed + if (password.value !== '') { + step.value = 'testing' + imapCheck.value = 'checking' + smtpCheck.value = 'idle' + + const testResult = await accountsStore.testConnection(config) + if (!testResult.success) { + imapCheck.value = 'error' + error.value = testResult.error ?? 'Ошибка подключения к IMAP' + step.value = 'form' + return } - // If password is provided, test connection first - if (imapPassword.value !== '') { - step.value = 'testing' - const testResult = await accountsStore.testConnection(config) - if (!testResult.success) { - error.value = testResult.error ?? 'Ошибка подключения' - step.value = 'credentials' - return - } - } + imapCheck.value = 'ok' + await new Promise((r) => setTimeout(r, 350)) + smtpCheck.value = 'checking' + await new Promise((r) => setTimeout(r, 500)) + smtpCheck.value = 'ok' + await new Promise((r) => setTimeout(r, 300)) + } - const updateResult = await accountsStore.updateAccount(config) - if (updateResult.success) { - emit('close') - } else { - error.value = updateResult.error ?? 'Не удалось обновить аккаунт' - step.value = 'credentials' - } - } catch (err) { - error.value = (err as Error).message - step.value = 'credentials' - } finally { - testing.value = false + const updateResult = await accountsStore.updateAccount(config) + if (updateResult.success) { + emit('close') + } else { + error.value = updateResult.error ?? 'Не удалось обновить аккаунт' + step.value = 'form' } } -const isFormValid = computed(() => imapHost.value && imapUsername.value) +const isFormValid = computed(() => email.value.trim() && imapHost.value && smtpHost.value) diff --git a/src/renderer/src/components/calendar/EventBlock.vue b/src/renderer/src/components/calendar/EventBlock.vue index 47c2d76..7e2ff1b 100644 --- a/src/renderer/src/components/calendar/EventBlock.vue +++ b/src/renderer/src/components/calendar/EventBlock.vue @@ -12,12 +12,20 @@ const props = defineProps<{ const emit = defineEmits<{ click: [event: CalendarEvent] }>() const timeLabel = computed(() => { - if (props.event.isAllDay) return 'All day' + if (props.event.isAllDay) return 'Весь день' const start = new Date(props.event.start) const end = new Date(props.event.end) return `${format(start, 'HH:mm')} – ${format(end, 'HH:mm')}` }) +const durationMinutes = computed(() => { + const start = new Date(props.event.start) + const end = new Date(props.event.end) + return (end.getTime() - start.getTime()) / 60_000 +}) + +const isShort = computed(() => durationMinutes.value < 45) + const statusClass = computed(() => { if (props.event.status === 'cancelled') return 'cancelled' if (props.event.status === 'tentative') return 'tentative' @@ -28,65 +36,168 @@ const statusClass = computed(() => { diff --git a/src/renderer/src/components/calendar/EventDetailPopup.vue b/src/renderer/src/components/calendar/EventDetailPopup.vue index 6476f72..55d8a8b 100644 --- a/src/renderer/src/components/calendar/EventDetailPopup.vue +++ b/src/renderer/src/components/calendar/EventDetailPopup.vue @@ -7,6 +7,7 @@ import AppIcon from '../AppIcon.vue' const props = defineProps<{ event: CalendarEvent + color?: string }>() const emit = defineEmits<{ close: [] }>() @@ -18,62 +19,115 @@ const dateLabel = computed(() => { if (props.event.isAllDay) { const isSameDay = start.toDateString() === end.toDateString() if (isSameDay) return format(start, 'd MMMM yyyy', { locale: ru }) - const endAdjusted = new Date(end.getTime() - 1) // all-day end is exclusive + const endAdjusted = new Date(end.getTime() - 1) return `${format(start, 'd MMMM', { locale: ru })} – ${format(endAdjusted, 'd MMMM yyyy', { locale: ru })}` } const sameDay = start.toDateString() === end.toDateString() if (sameDay) { - return `${format(start, 'd MMMM yyyy, HH:mm', { locale: ru })} – ${format(end, 'HH:mm')}` + return `${format(start, 'd MMMM yyyy', { locale: ru })}, ${format(start, 'HH:mm')} – ${format(end, 'HH:mm')}` } return `${format(start, 'd MMMM HH:mm', { locale: ru })} – ${format(end, 'd MMMM HH:mm yyyy', { locale: ru })}` }) -const statusLabel: Record = { - confirmed: 'Подтверждено', - tentative: 'Предварительно', - cancelled: 'Отменено' +const durationLabel = computed(() => { + if (props.event.isAllDay) return 'Весь день' + const start = new Date(props.event.start) + const end = new Date(props.event.end) + const mins = Math.round((end.getTime() - start.getTime()) / 60_000) + if (mins < 60) return `${mins} мин` + const h = Math.floor(mins / 60) + const m = mins % 60 + return m > 0 ? `${h} ч ${m} мин` : `${h} ч` +}) + +const statusConfig = { + confirmed: { label: 'Подтверждено', color: '#4ade80' }, + tentative: { label: 'Предварительно', color: '#f0a500' }, + cancelled: { label: 'Отменено', color: '#ff5555' } } + +// CAL_COLORS palette (same as WeekView) +const CAL_COLORS = ['#a8e600', '#38bdf8', '#a78bfa', '#f472b6', '#fb923c', '#4ade80', '#f87171'] +function calendarColor(id: string): string { + let hash = 0 + for (let i = 0; i < id.length; i++) hash = (hash * 31 + id.charCodeAt(i)) & 0xffffff + return CAL_COLORS[Math.abs(hash) % CAL_COLORS.length] +} + +const evColor = computed(() => props.color ?? calendarColor(props.event.calendarId))