feat: calendar view with CalDAV support for self-hosted Exchange
Adds a full week-view calendar that reads events from Exchange via CalDAV (the same IMAP host/credentials are reused — no extra config needed). Backend (main process): - CalDavProvider: HTTP PROPFIND/REPORT against standard CalDAV and Exchange-specific /EWS/Calendar/ endpoints with Basic auth; inline iCal parser handles VEVENT fields, UTC/local/all-day dates, attendees - CalendarHandler: IPC channels calendar:list and calendar:events - AccountManager: calendarProviders map with lazy connect/cache Renderer: - CalendarStore (Pinia): week navigation, per-calendar toggling, event loading - CalendarView: full-screen layout matching liquid-glass design system - WeekView: 7-column time grid, overlap layout, current-time indicator, scrolls to business hours on mount, all-day event row - EventBlock: positioned absolute event card with status variants - EventDetailPopup: full event details (time, location, organizer, attendees) - Router: /calendar route added - AccountSwitcher: mail / calendar nav icons with active-state highlight - AppIcon: added 'calendar' SVG icon Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b02e976fb1
commit
ba4a420209
14 changed files with 2107 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import { AccountManager } from './services/account-manager'
|
|||
import { registerAccountHandlers } from './ipc/accounts.handler'
|
||||
import { registerFolderHandlers } from './ipc/folders.handler'
|
||||
import { registerMessageHandlers } from './ipc/messages.handler'
|
||||
import { registerCalendarHandlers } from './ipc/calendar.handler'
|
||||
import type { ComposeSession } from '@shared/types/message'
|
||||
|
||||
const accountManager = new AccountManager()
|
||||
|
|
@ -142,6 +143,7 @@ app.whenReady().then(async () => {
|
|||
registerAccountHandlers(accountManager)
|
||||
registerFolderHandlers(accountManager)
|
||||
registerMessageHandlers(accountManager)
|
||||
registerCalendarHandlers(accountManager)
|
||||
|
||||
createWindow()
|
||||
|
||||
|
|
|
|||
12
src/main/ipc/calendar.handler.ts
Normal file
12
src/main/ipc/calendar.handler.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import type { AccountManager } from '../services/account-manager'
|
||||
import { registerHandler } from './registry'
|
||||
|
||||
export function registerCalendarHandlers(manager: AccountManager): void {
|
||||
registerHandler('calendar:list', ({ accountId }) =>
|
||||
manager.listCalendars(accountId)
|
||||
)
|
||||
|
||||
registerHandler('calendar:events', ({ accountId, calendarId, start, end }) =>
|
||||
manager.listCalendarEvents(accountId, calendarId, new Date(start), new Date(end))
|
||||
)
|
||||
}
|
||||
530
src/main/providers/caldav.provider.ts
Normal file
530
src/main/providers/caldav.provider.ts
Normal file
|
|
@ -0,0 +1,530 @@
|
|||
/**
|
||||
* CalDAV provider for Exchange (and any CalDAV-compliant server).
|
||||
*
|
||||
* Uses only Node.js built-in `https`/`http` — no extra npm deps.
|
||||
* Exchange 2013+ exposes CalDAV at /EWS/Calendar/; standard servers
|
||||
* advertise the principal via /.well-known/caldav (RFC 6764).
|
||||
*
|
||||
* Auth: HTTP Basic, same credentials as IMAP.
|
||||
*/
|
||||
|
||||
import https from 'node:https'
|
||||
import http from 'node:http'
|
||||
import type { IncomingMessage } from 'node:http'
|
||||
import type { AccountConfig, ImapCredentials } from '@shared/types/account'
|
||||
import type { CalendarInfo, CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
// ── HTTP helper ────────────────────────────────────────────────────────────────
|
||||
|
||||
interface RequestOptions {
|
||||
protocol: 'https' | 'http'
|
||||
hostname: string
|
||||
port: number
|
||||
path: string
|
||||
method: string
|
||||
headers: Record<string, string>
|
||||
body?: string
|
||||
allowSelfSigned?: boolean
|
||||
}
|
||||
|
||||
interface RequestResult {
|
||||
status: number
|
||||
headers: IncomingMessage['headers']
|
||||
body: string
|
||||
}
|
||||
|
||||
function request(opts: RequestOptions): Promise<RequestResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const module_ = opts.protocol === 'https' ? https : http
|
||||
const req = module_.request(
|
||||
{
|
||||
hostname: opts.hostname,
|
||||
port: opts.port,
|
||||
path: opts.path,
|
||||
method: opts.method,
|
||||
headers: opts.headers,
|
||||
rejectUnauthorized: !opts.allowSelfSigned,
|
||||
timeout: 15_000
|
||||
},
|
||||
(res) => {
|
||||
let data = ''
|
||||
res.setEncoding('utf8')
|
||||
res.on('data', (chunk) => { data += chunk })
|
||||
res.on('end', () => {
|
||||
resolve({ status: res.statusCode ?? 0, headers: res.headers, body: data })
|
||||
})
|
||||
}
|
||||
)
|
||||
req.on('timeout', () => { req.destroy(new Error('CalDAV request timed out')) })
|
||||
req.on('error', reject)
|
||||
if (opts.body) req.write(opts.body)
|
||||
req.end()
|
||||
})
|
||||
}
|
||||
|
||||
// ── Minimal iCal parser ────────────────────────────────────────────────────────
|
||||
|
||||
interface RawVEvent {
|
||||
uid: string
|
||||
summary: string
|
||||
dtstart: string
|
||||
dtStartParams: string
|
||||
dtend: string
|
||||
dtEndParams: string
|
||||
location: string
|
||||
description: string
|
||||
organizer: string
|
||||
attendees: string[]
|
||||
status: string
|
||||
}
|
||||
|
||||
/** RFC 5545 line-unfolding: CRLF followed by a space or tab is a continuation. */
|
||||
function unfoldLines(raw: string): string[] {
|
||||
return raw.replace(/\r\n[ \t]/g, '').replace(/\n[ \t]/g, '').split(/\r\n|\n/)
|
||||
}
|
||||
|
||||
function decodeICalText(value: string): string {
|
||||
return value.replace(/\\n/g, '\n').replace(/\\,/g, ',').replace(/\\;/g, ';').replace(/\\\\/g, '\\')
|
||||
}
|
||||
|
||||
function extractEmail(value: string): string {
|
||||
// ORGANIZER:mailto:user@example.com or ATTENDEE;CN=Name:mailto:user@example.com
|
||||
const match = value.match(/mailto:([^\s;,>]+)/i)
|
||||
return match ? match[1] : value
|
||||
}
|
||||
|
||||
function parseVEvents(icalText: string): RawVEvent[] {
|
||||
const events: RawVEvent[] = []
|
||||
const lines = unfoldLines(icalText)
|
||||
|
||||
let inEvent = false
|
||||
let props: Record<string, Array<{ value: string; params: string }>> = {}
|
||||
|
||||
for (const line of lines) {
|
||||
if (line === 'BEGIN:VEVENT') {
|
||||
inEvent = true
|
||||
props = {}
|
||||
continue
|
||||
}
|
||||
if (line === 'END:VEVENT') {
|
||||
inEvent = false
|
||||
|
||||
const get = (key: string) => props[key]?.[0]?.value ?? ''
|
||||
const getParams = (key: string) => props[key]?.[0]?.params ?? ''
|
||||
const getAll = (key: string) => (props[key] ?? []).map((x) => x.value)
|
||||
|
||||
events.push({
|
||||
uid: get('UID'),
|
||||
summary: decodeICalText(get('SUMMARY')),
|
||||
dtstart: get('DTSTART'),
|
||||
dtStartParams: getParams('DTSTART'),
|
||||
dtend: get('DTEND'),
|
||||
dtEndParams: getParams('DTEND'),
|
||||
location: decodeICalText(get('LOCATION')),
|
||||
description: decodeICalText(get('DESCRIPTION')),
|
||||
organizer: extractEmail(get('ORGANIZER')),
|
||||
attendees: getAll('ATTENDEE').map(extractEmail).filter(Boolean),
|
||||
status: get('STATUS').toLowerCase()
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
if (!inEvent) continue
|
||||
|
||||
const colonIdx = line.indexOf(':')
|
||||
if (colonIdx === -1) continue
|
||||
|
||||
const keyFull = line.substring(0, colonIdx)
|
||||
const value = line.substring(colonIdx + 1)
|
||||
const semicolonIdx = keyFull.indexOf(';')
|
||||
const key = semicolonIdx === -1 ? keyFull : keyFull.substring(0, semicolonIdx)
|
||||
const params = semicolonIdx === -1 ? '' : keyFull.substring(semicolonIdx + 1)
|
||||
|
||||
if (!props[key]) props[key] = []
|
||||
props[key].push({ value, params })
|
||||
}
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse iCal date/time string to a JS Date.
|
||||
* Handles: DATE (20240401), DATE-TIME UTC (20240401T090000Z),
|
||||
* DATE-TIME local (20240401T090000), with TZID param ignored (treated as local).
|
||||
*/
|
||||
function parseICalDate(value: string, params: string): { date: Date; isAllDay: boolean } {
|
||||
const isAllDay = params.includes('VALUE=DATE') || /^\d{8}$/.test(value)
|
||||
|
||||
if (isAllDay) {
|
||||
const y = parseInt(value.slice(0, 4), 10)
|
||||
const m = parseInt(value.slice(4, 6), 10) - 1
|
||||
const d = parseInt(value.slice(6, 8), 10)
|
||||
return { date: new Date(Date.UTC(y, m, d)), isAllDay: true }
|
||||
}
|
||||
|
||||
const isUTC = value.endsWith('Z')
|
||||
const clean = isUTC ? value.slice(0, -1) : value
|
||||
|
||||
const y = parseInt(clean.slice(0, 4), 10)
|
||||
const mo = parseInt(clean.slice(4, 6), 10) - 1
|
||||
const d = parseInt(clean.slice(6, 8), 10)
|
||||
const h = clean.length > 8 ? parseInt(clean.slice(9, 11), 10) : 0
|
||||
const mi = clean.length > 8 ? parseInt(clean.slice(11, 13), 10) : 0
|
||||
const s = clean.length > 8 ? parseInt(clean.slice(13, 15), 10) : 0
|
||||
|
||||
const date = isUTC
|
||||
? new Date(Date.UTC(y, mo, d, h, mi, s))
|
||||
: new Date(y, mo, d, h, mi, s)
|
||||
|
||||
return { date, isAllDay: false }
|
||||
}
|
||||
|
||||
// ── XML helpers ────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Extract all <C:calendar-data> (or namespaced equivalent) block contents from a multistatus XML response. */
|
||||
function extractCalendarData(xml: string): string[] {
|
||||
const results: string[] = []
|
||||
// Match both namespaced and un-namespaced calendar-data elements
|
||||
const re = /<(?:[^:\s>]+:)?calendar-data[^>]*>([\s\S]*?)<\/(?:[^:\s>]+:)?calendar-data>/g
|
||||
let match: RegExpExecArray | null
|
||||
while ((match = re.exec(xml)) !== null) {
|
||||
// CalDAV may XML-encode special chars inside calendar-data
|
||||
const raw = match[1]
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/ /g, '\r')
|
||||
.trim()
|
||||
if (raw.length > 0) results.push(raw)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
/** Extract calendar collections from a PROPFIND multistatus response. */
|
||||
interface CalDavCalendar {
|
||||
href: string
|
||||
displayName: string
|
||||
}
|
||||
|
||||
function extractCalendars(xml: string, baseUrl: string): CalDavCalendar[] {
|
||||
const calendars: CalDavCalendar[] = []
|
||||
|
||||
// Split by <response> blocks
|
||||
const responseRe = /<(?:[^:\s>]+:)?response[^>]*>([\s\S]*?)<\/(?:[^:\s>]+:)?response>/g
|
||||
let match: RegExpExecArray | null
|
||||
|
||||
while ((match = responseRe.exec(xml)) !== null) {
|
||||
const block = match[1]
|
||||
|
||||
// Must contain calendar resourcetype
|
||||
if (!/<(?:[^:\s>]+:)?calendar[^>]*\/>/.test(block) &&
|
||||
!/<(?:[^:\s>]+:)?calendar[^>]*>/.test(block)) continue
|
||||
|
||||
const hrefMatch = block.match(/<(?:[^:\s>]+:)?href[^>]*>([^<]+)<\/(?:[^:\s>]+:)?href>/)
|
||||
const nameMatch = block.match(/<(?:[^:\s>]+:)?displayname[^>]*>([^<]*)<\/(?:[^:\s>]+:)?displayname>/)
|
||||
|
||||
if (hrefMatch) {
|
||||
calendars.push({
|
||||
href: hrefMatch[1].trim(),
|
||||
displayName: nameMatch ? decodeICalText(nameMatch[1].trim()) : 'Calendar'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// If nothing found, treat the base path itself as the calendar
|
||||
if (calendars.length === 0 && baseUrl.length > 0) {
|
||||
calendars.push({ href: baseUrl, displayName: 'Calendar' })
|
||||
}
|
||||
|
||||
return calendars
|
||||
}
|
||||
|
||||
// ── CalDAV Provider ────────────────────────────────────────────────────────────
|
||||
|
||||
export class CalDavProvider {
|
||||
private readonly hostname: string
|
||||
private readonly protocol: 'https' | 'http'
|
||||
private readonly port: number
|
||||
private readonly username: string
|
||||
private readonly password: string
|
||||
private readonly allowSelfSigned: boolean
|
||||
private readonly authHeader: string
|
||||
|
||||
/** Resolved CalDAV base path (e.g. "/EWS/Calendar/") */
|
||||
private basePath: string | null = null
|
||||
|
||||
constructor(config: AccountConfig) {
|
||||
const creds = config.credentials as ImapCredentials
|
||||
|
||||
// Derive HTTPS endpoint from IMAP host; Exchange typically shares the hostname
|
||||
this.hostname = creds.host
|
||||
this.protocol = creds.secure ? 'https' : 'http'
|
||||
this.port = creds.secure ? 443 : 80
|
||||
this.username = creds.username
|
||||
this.password = creds.password
|
||||
this.allowSelfSigned = creds.smtpAllowSelfSigned ?? false
|
||||
|
||||
const encoded = Buffer.from(`${this.username}:${this.password}`).toString('base64')
|
||||
this.authHeader = `Basic ${encoded}`
|
||||
}
|
||||
|
||||
// ── Discovery ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Try to discover the CalDAV endpoint.
|
||||
* Priority: /.well-known/caldav (RFC 6764) → /EWS/Calendar/ (Exchange) → /caldav/ (generic)
|
||||
* Returns the resolved path or null if none found.
|
||||
*/
|
||||
async discoverBasePath(): Promise<string | null> {
|
||||
const candidates = [
|
||||
'/.well-known/caldav',
|
||||
'/EWS/Calendar/',
|
||||
`/EWS/Calendar/${this.username}/`,
|
||||
'/caldav/',
|
||||
`/caldav/${this.username}/`,
|
||||
'/dav/',
|
||||
]
|
||||
|
||||
for (const path of candidates) {
|
||||
try {
|
||||
const result = await this.req('PROPFIND', path, {
|
||||
Depth: '0',
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
})
|
||||
|
||||
// 207 Multi-Status = CalDAV responded, 301/302 = redirect → follow
|
||||
if (result.status === 207) return path
|
||||
if (result.status === 301 || result.status === 302) {
|
||||
const location = result.headers['location']
|
||||
if (location) {
|
||||
const u = new URL(location, `${this.protocol}://${this.hostname}`)
|
||||
return u.pathname
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Try next candidate
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
async connect(): Promise<void> {
|
||||
this.basePath = await this.discoverBasePath()
|
||||
if (!this.basePath) {
|
||||
throw new Error(
|
||||
`CalDAV endpoint not found on ${this.hostname}. ` +
|
||||
`Ensure Exchange CalDAV is enabled (Exchange 2013+).`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
isConnected(): boolean {
|
||||
return this.basePath !== null
|
||||
}
|
||||
|
||||
// ── List calendars ─────────────────────────────────────────────────────────
|
||||
|
||||
async listCalendars(accountId: string): Promise<CalendarInfo[]> {
|
||||
if (!this.basePath) throw new Error('CalDAV not connected')
|
||||
|
||||
const body = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<D:propfind xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<D:prop>
|
||||
<D:resourcetype/>
|
||||
<D:displayname/>
|
||||
</D:prop>
|
||||
</D:propfind>`
|
||||
|
||||
const result = await this.req('PROPFIND', this.basePath, {
|
||||
Depth: '1',
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
}, body)
|
||||
|
||||
if (result.status !== 207) {
|
||||
// Treat the base path as a single calendar on any other 2xx
|
||||
return [{
|
||||
id: this.basePath,
|
||||
name: 'Calendar',
|
||||
accountId
|
||||
}]
|
||||
}
|
||||
|
||||
const cals = extractCalendars(result.body, this.basePath)
|
||||
return cals.map((c) => ({
|
||||
id: c.href,
|
||||
name: c.displayName || 'Calendar',
|
||||
accountId
|
||||
}))
|
||||
}
|
||||
|
||||
// ── Fetch events ───────────────────────────────────────────────────────────
|
||||
|
||||
async listEvents(
|
||||
accountId: string,
|
||||
calendarId: string,
|
||||
start: Date,
|
||||
end: Date
|
||||
): Promise<CalendarEvent[]> {
|
||||
const startStr = toUtcString(start)
|
||||
const endStr = toUtcString(end)
|
||||
|
||||
const body = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<D:prop>
|
||||
<D:getetag/>
|
||||
<C:calendar-data/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="${startStr}" end="${endStr}"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>`
|
||||
|
||||
const result = await this.req('REPORT', calendarId, {
|
||||
Depth: '1',
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
}, body)
|
||||
|
||||
if (result.status !== 207) {
|
||||
// Exchange may not support time-range; fall back to PROPFIND + client-side filtering
|
||||
return this.fetchAllEventsAndFilter(accountId, calendarId, start, end)
|
||||
}
|
||||
|
||||
return this.parseMultistatusEvents(result.body, accountId, calendarId)
|
||||
}
|
||||
|
||||
/** Fallback: fetch all VEVENT objects and filter client-side by time range. */
|
||||
private async fetchAllEventsAndFilter(
|
||||
accountId: string,
|
||||
calendarId: string,
|
||||
start: Date,
|
||||
end: Date
|
||||
): Promise<CalendarEvent[]> {
|
||||
const body = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<D:prop>
|
||||
<D:getetag/>
|
||||
<C:calendar-data/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT"/>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>`
|
||||
|
||||
const result = await this.req('REPORT', calendarId, {
|
||||
Depth: '1',
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
}, body)
|
||||
|
||||
if (result.status !== 207) return []
|
||||
|
||||
const all = this.parseMultistatusEvents(result.body, accountId, calendarId)
|
||||
return all.filter((ev) => {
|
||||
const evEnd = new Date(ev.end)
|
||||
const evStart = new Date(ev.start)
|
||||
return evStart < end && evEnd > start
|
||||
})
|
||||
}
|
||||
|
||||
// ── Parsing ────────────────────────────────────────────────────────────────
|
||||
|
||||
private parseMultistatusEvents(
|
||||
xml: string,
|
||||
accountId: string,
|
||||
calendarId: string
|
||||
): CalendarEvent[] {
|
||||
const events: CalendarEvent[] = []
|
||||
const icalBlocks = extractCalendarData(xml)
|
||||
|
||||
for (const block of icalBlocks) {
|
||||
const raw = parseVEvents(block)
|
||||
for (const rv of raw) {
|
||||
if (!rv.dtstart) continue
|
||||
|
||||
const { date: startDate, isAllDay } = parseICalDate(rv.dtstart, rv.dtStartParams)
|
||||
let endDate: Date
|
||||
|
||||
if (rv.dtend) {
|
||||
endDate = parseICalDate(rv.dtend, rv.dtEndParams).date
|
||||
} else {
|
||||
// No DTEND: for all-day events default to +1 day, for timed +1 hour
|
||||
endDate = new Date(startDate)
|
||||
if (isAllDay) endDate.setUTCDate(endDate.getUTCDate() + 1)
|
||||
else endDate.setTime(endDate.getTime() + 60 * 60 * 1000)
|
||||
}
|
||||
|
||||
const id = `${calendarId}::${rv.uid || startDate.toISOString()}`
|
||||
|
||||
events.push({
|
||||
id,
|
||||
uid: rv.uid,
|
||||
calendarId,
|
||||
accountId,
|
||||
title: rv.summary || '(no title)',
|
||||
start: startDate.toISOString(),
|
||||
end: endDate.toISOString(),
|
||||
isAllDay,
|
||||
location: rv.location || undefined,
|
||||
description: rv.description || undefined,
|
||||
organizer: rv.organizer || undefined,
|
||||
attendees: rv.attendees,
|
||||
status: (rv.status as CalendarEvent['status']) || 'confirmed'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
// ── Internal HTTP helper ───────────────────────────────────────────────────
|
||||
|
||||
private async req(
|
||||
method: string,
|
||||
path: string,
|
||||
extraHeaders: Record<string, string> = {},
|
||||
body?: string
|
||||
): Promise<RequestResult> {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: this.authHeader,
|
||||
'User-Agent': 'AeroMail/1.0',
|
||||
...extraHeaders
|
||||
}
|
||||
if (body) {
|
||||
headers['Content-Length'] = Buffer.byteLength(body, 'utf8').toString()
|
||||
}
|
||||
|
||||
return request({
|
||||
protocol: this.protocol,
|
||||
hostname: this.hostname,
|
||||
port: this.port,
|
||||
path,
|
||||
method,
|
||||
headers,
|
||||
body,
|
||||
allowSelfSigned: this.allowSelfSigned
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ── Utility ────────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Format a Date as an iCal UTC string: 20240401T000000Z */
|
||||
function toUtcString(d: Date): string {
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return (
|
||||
d.getUTCFullYear().toString() +
|
||||
pad(d.getUTCMonth() + 1) +
|
||||
pad(d.getUTCDate()) +
|
||||
'T' +
|
||||
pad(d.getUTCHours()) +
|
||||
pad(d.getUTCMinutes()) +
|
||||
pad(d.getUTCSeconds()) +
|
||||
'Z'
|
||||
)
|
||||
}
|
||||
|
|
@ -3,7 +3,9 @@ import type { AccountConfig, ImapCredentials } from '@shared/types/account'
|
|||
import { AccountType } from '@shared/types/account'
|
||||
import type { IEmailProvider, FolderListResult, MessageListResult } from '@shared/types/provider'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, ComposeData } from '@shared/types/message'
|
||||
import type { CalendarInfo, CalendarEvent } from '@shared/types/calendar'
|
||||
import { ImapProvider } from '../providers/imap.provider'
|
||||
import { CalDavProvider } from '../providers/caldav.provider'
|
||||
import { CredentialStore } from './credential-store'
|
||||
import Store from 'electron-store'
|
||||
|
||||
|
|
@ -16,6 +18,7 @@ const RECONNECT_CODES = new Set(['NoConnection', 'ECONNRESET', 'ECONNREFUSED', '
|
|||
|
||||
export class AccountManager {
|
||||
private providers = new Map<string, IEmailProvider>()
|
||||
private calendarProviders = new Map<string, CalDavProvider>()
|
||||
private store: Store<AccountStoreSchema>
|
||||
private credentialStore: CredentialStore
|
||||
private mainWindow: BrowserWindow | null = null
|
||||
|
|
@ -72,6 +75,7 @@ export class AccountManager {
|
|||
await provider.disconnect()
|
||||
this.providers.delete(accountId)
|
||||
}
|
||||
this.calendarProviders.delete(accountId)
|
||||
await this.credentialStore.remove(accountId)
|
||||
|
||||
const accounts = this.store.get('accounts', [])
|
||||
|
|
@ -205,6 +209,48 @@ export class AccountManager {
|
|||
)
|
||||
}
|
||||
|
||||
// ── Calendar ────────────────────────────────────────────
|
||||
|
||||
async listCalendars(accountId: string): Promise<CalendarInfo[]> {
|
||||
const provider = await this.getOrCreateCalendarProvider(accountId)
|
||||
return provider.listCalendars(accountId)
|
||||
}
|
||||
|
||||
async listCalendarEvents(
|
||||
accountId: string,
|
||||
calendarId: string,
|
||||
start: Date,
|
||||
end: Date
|
||||
): Promise<CalendarEvent[]> {
|
||||
const provider = await this.getOrCreateCalendarProvider(accountId)
|
||||
return provider.listEvents(accountId, calendarId, start, end)
|
||||
}
|
||||
|
||||
private async getOrCreateCalendarProvider(accountId: string): Promise<CalDavProvider> {
|
||||
const existing = this.calendarProviders.get(accountId)
|
||||
if (existing?.isConnected()) return existing
|
||||
|
||||
const accounts = this.store.get('accounts', [])
|
||||
const accMeta = accounts.find((a) => a.id === accountId)
|
||||
if (!accMeta) throw new Error(`Account ${accountId} not found`)
|
||||
|
||||
const credRaw = this.credentialStore.get(accountId)
|
||||
if (!credRaw) throw new Error(`Credentials for ${accountId} not found`)
|
||||
|
||||
let credentials: AccountConfig['credentials']
|
||||
try {
|
||||
credentials = JSON.parse(credRaw)
|
||||
} catch {
|
||||
throw new Error('Corrupted credentials')
|
||||
}
|
||||
|
||||
const config: AccountConfig = { ...accMeta, credentials }
|
||||
const provider = new CalDavProvider(config)
|
||||
await provider.connect()
|
||||
this.calendarProviders.set(accountId, provider)
|
||||
return provider
|
||||
}
|
||||
|
||||
// ── Auto-reconnect ──────────────────────────────────────
|
||||
|
||||
private async withAutoReconnect<T>(accountId: string, fn: () => Promise<T>): Promise<T> {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export type IconName =
|
|||
| 'pdf'
|
||||
| 'image'
|
||||
| 'bell-off'
|
||||
| 'calendar'
|
||||
|
||||
const props = defineProps<{
|
||||
name: IconName
|
||||
|
|
@ -141,6 +142,12 @@ const paths: Record<IconName, string> = {
|
|||
<path d="M18 8a6 6 0 0 0-9.33-5"/>
|
||||
<line x1="1" y1="1" x2="23" y2="23"/>
|
||||
`,
|
||||
calendar: `
|
||||
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/>
|
||||
<line x1="16" y1="2" x2="16" y2="6"/>
|
||||
<line x1="8" y1="2" x2="8" y2="6"/>
|
||||
<line x1="3" y1="10" x2="21" y2="10"/>
|
||||
`,
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
92
src/renderer/src/components/calendar/EventBlock.vue
Normal file
92
src/renderer/src/components/calendar/EventBlock.vue
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { format } from 'date-fns'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
const props = defineProps<{
|
||||
event: CalendarEvent
|
||||
style?: Record<string, string>
|
||||
color?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ click: [event: CalendarEvent] }>()
|
||||
|
||||
const timeLabel = computed(() => {
|
||||
if (props.event.isAllDay) return 'All day'
|
||||
const start = new Date(props.event.start)
|
||||
const end = new Date(props.event.end)
|
||||
return `${format(start, 'HH:mm')} – ${format(end, 'HH:mm')}`
|
||||
})
|
||||
|
||||
const statusClass = computed(() => {
|
||||
if (props.event.status === 'cancelled') return 'cancelled'
|
||||
if (props.event.status === 'tentative') return 'tentative'
|
||||
return ''
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="event-block"
|
||||
:class="statusClass"
|
||||
:style="{ ...(style ?? {}), '--event-color': color ?? 'var(--accent)' }"
|
||||
@click.stop="emit('click', event)"
|
||||
>
|
||||
<div class="event-title">{{ event.title }}</div>
|
||||
<div class="event-time">{{ timeLabel }}</div>
|
||||
<div v-if="event.location" class="event-location">{{ event.location }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.event-block {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
right: 2px;
|
||||
border-radius: 6px;
|
||||
padding: 3px 6px;
|
||||
font-size: 11px;
|
||||
line-height: 1.3;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
background: color-mix(in srgb, var(--event-color) 22%, transparent);
|
||||
border-left: 3px solid var(--event-color);
|
||||
color: var(--text-primary);
|
||||
transition: filter var(--transition-fast), transform var(--transition-fast);
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.event-block:hover {
|
||||
filter: brightness(1.15);
|
||||
transform: scale(1.01);
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.event-block.cancelled {
|
||||
opacity: 0.45;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.event-block.tentative {
|
||||
border-left-style: dashed;
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.event-title {
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.event-time,
|
||||
.event-location {
|
||||
font-size: 10px;
|
||||
color: var(--text-secondary);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
200
src/renderer/src/components/calendar/EventDetailPopup.vue
Normal file
200
src/renderer/src/components/calendar/EventDetailPopup.vue
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
import AppIcon from '../AppIcon.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
event: CalendarEvent
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ close: [] }>()
|
||||
|
||||
const dateLabel = computed(() => {
|
||||
const start = new Date(props.event.start)
|
||||
const end = new Date(props.event.end)
|
||||
|
||||
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
|
||||
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 HH:mm', { locale: ru })} – ${format(end, 'd MMMM HH:mm yyyy', { locale: ru })}`
|
||||
})
|
||||
|
||||
const statusLabel: Record<string, string> = {
|
||||
confirmed: 'Подтверждено',
|
||||
tentative: 'Предварительно',
|
||||
cancelled: 'Отменено'
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="popup-backdrop" @click.self="emit('close')">
|
||||
<div class="popup">
|
||||
<div class="popup-header">
|
||||
<h3 class="popup-title">{{ event.title }}</h3>
|
||||
<button class="close-btn" @click="emit('close')">
|
||||
<AppIcon name="close" :size="14" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="popup-body">
|
||||
<div class="meta-row">
|
||||
<span class="meta-icon">📅</span>
|
||||
<span>{{ dateLabel }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.status && event.status !== 'confirmed'" class="meta-row status" :class="event.status">
|
||||
<span class="meta-icon">●</span>
|
||||
<span>{{ statusLabel[event.status] ?? event.status }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.location" class="meta-row">
|
||||
<span class="meta-icon">📍</span>
|
||||
<span>{{ event.location }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.organizer" class="meta-row">
|
||||
<span class="meta-icon">👤</span>
|
||||
<span>{{ event.organizer }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.attendees.length > 0" class="meta-row attendees">
|
||||
<span class="meta-icon">👥</span>
|
||||
<div class="attendee-list">
|
||||
<span v-for="a in event.attendees" :key="a" class="attendee-chip">{{ a }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="event.description" class="description">
|
||||
{{ event.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.popup-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.popup {
|
||||
width: 400px;
|
||||
max-width: 90vw;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
border-radius: var(--radius-xl);
|
||||
border: 1px solid var(--glass-border-strong);
|
||||
background:
|
||||
linear-gradient(160deg, rgba(255,255,255,0.09) 0%, rgba(255,255,255,0.03) 100%),
|
||||
rgba(14, 14, 22, 0.94);
|
||||
backdrop-filter: blur(48px) saturate(2);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255,255,255,0.14),
|
||||
var(--shadow-xl);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
flex: 1;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
flex-shrink: 0;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-muted);
|
||||
background: var(--glass-bg);
|
||||
border: 1px solid var(--glass-border);
|
||||
transition: background var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
background: var(--glass-bg-hover);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.popup-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.meta-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.meta-icon {
|
||||
flex-shrink: 0;
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.meta-row.tentative { color: var(--warning); }
|
||||
.meta-row.cancelled { color: var(--danger); }
|
||||
|
||||
.attendees {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.attendee-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.attendee-chip {
|
||||
font-size: 11px;
|
||||
padding: 2px 8px;
|
||||
border-radius: var(--radius-full);
|
||||
background: var(--glass-bg-raised);
|
||||
border: 1px solid var(--glass-border);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
white-space: pre-wrap;
|
||||
line-height: 1.5;
|
||||
border-top: 1px solid var(--glass-border);
|
||||
padding-top: 10px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
520
src/renderer/src/components/calendar/WeekView.vue
Normal file
520
src/renderer/src/components/calendar/WeekView.vue
Normal file
|
|
@ -0,0 +1,520 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { format, addDays, isSameDay, isToday } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import EventBlock from './EventBlock.vue'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
const props = defineProps<{
|
||||
weekStart: Date
|
||||
events: CalendarEvent[]
|
||||
loading?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ eventClick: [event: CalendarEvent] }>()
|
||||
|
||||
const scrollEl = ref<HTMLElement | null>(null)
|
||||
const HOUR_HEIGHT = 56 // px per hour
|
||||
const HOURS = Array.from({ length: 24 }, (_, i) => i)
|
||||
|
||||
// ── Days of the week ────────────────────────────────────────────────────────
|
||||
|
||||
const days = computed(() =>
|
||||
Array.from({ length: 7 }, (_, i) => {
|
||||
const date = addDays(props.weekStart, i)
|
||||
return {
|
||||
date,
|
||||
dayName: format(date, 'EEE', { locale: ru }),
|
||||
dayNum: format(date, 'd'),
|
||||
monthLabel: format(date, 'MMM', { locale: ru }),
|
||||
isToday: isToday(date)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
// ── Current time indicator ──────────────────────────────────────────────────
|
||||
|
||||
const now = ref(new Date())
|
||||
let timerId: ReturnType<typeof setInterval>
|
||||
|
||||
onMounted(() => {
|
||||
timerId = setInterval(() => { now.value = new Date() }, 60_000)
|
||||
// Scroll to business hours (8:00)
|
||||
scrollEl.value?.scrollTo({ top: 8 * HOUR_HEIGHT - 20, behavior: 'smooth' })
|
||||
})
|
||||
|
||||
// Re-scroll when week changes
|
||||
watch(() => props.weekStart, () => {
|
||||
scrollEl.value?.scrollTo({ top: 8 * HOUR_HEIGHT - 20, behavior: 'smooth' })
|
||||
})
|
||||
|
||||
import { onUnmounted } from 'vue'
|
||||
onUnmounted(() => clearInterval(timerId))
|
||||
|
||||
const nowTop = computed(() => {
|
||||
const h = now.value.getHours()
|
||||
const m = now.value.getMinutes()
|
||||
return (h + m / 60) * HOUR_HEIGHT
|
||||
})
|
||||
|
||||
const todayColumnIndex = computed(() =>
|
||||
days.value.findIndex((d) => d.isToday)
|
||||
)
|
||||
|
||||
// ── Event layout ────────────────────────────────────────────────────────────
|
||||
|
||||
interface LayoutEvent {
|
||||
event: CalendarEvent
|
||||
dayIndex: number
|
||||
top: number
|
||||
height: number
|
||||
column: number
|
||||
totalColumns: number
|
||||
}
|
||||
|
||||
const allDayEvents = computed(() => {
|
||||
return props.events.filter((e) => e.isAllDay)
|
||||
})
|
||||
|
||||
const timedEvents = computed(() => {
|
||||
return props.events.filter((e) => !e.isAllDay)
|
||||
})
|
||||
|
||||
/**
|
||||
* Lay out timed events per day, detecting overlaps.
|
||||
* Events in the same day that overlap in time are split into columns.
|
||||
*/
|
||||
const layoutEvents = computed((): LayoutEvent[] => {
|
||||
const result: LayoutEvent[] = []
|
||||
|
||||
for (let dayIndex = 0; dayIndex < 7; dayIndex++) {
|
||||
const dayDate = days.value[dayIndex].date
|
||||
|
||||
const dayEvs = timedEvents.value.filter((e) => {
|
||||
const eStart = new Date(e.start)
|
||||
const eEnd = new Date(e.end)
|
||||
return isSameDay(eStart, dayDate) ||
|
||||
(eStart < dayDate && eEnd > dayDate)
|
||||
})
|
||||
|
||||
// Simple overlap detection: group overlapping events
|
||||
const columns: CalendarEvent[][] = []
|
||||
for (const ev of dayEvs) {
|
||||
const eStart = new Date(ev.start).getTime()
|
||||
const eEnd = new Date(ev.end).getTime()
|
||||
|
||||
let placed = false
|
||||
for (const col of columns) {
|
||||
const lastInCol = col[col.length - 1]
|
||||
const lastEnd = new Date(lastInCol.end).getTime()
|
||||
if (eStart >= lastEnd) {
|
||||
col.push(ev)
|
||||
placed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!placed) columns.push([ev])
|
||||
}
|
||||
|
||||
// Build LayoutEvent for each event
|
||||
for (let colIdx = 0; colIdx < columns.length; colIdx++) {
|
||||
for (const ev of columns[colIdx]) {
|
||||
const eStart = new Date(ev.start)
|
||||
const eEnd = new Date(ev.end)
|
||||
|
||||
// Clamp to day boundaries
|
||||
const dayStart = new Date(dayDate)
|
||||
dayStart.setHours(0, 0, 0, 0)
|
||||
const dayEnd = new Date(dayDate)
|
||||
dayEnd.setHours(24, 0, 0, 0)
|
||||
|
||||
const clampedStart = eStart < dayStart ? dayStart : eStart
|
||||
const clampedEnd = eEnd > dayEnd ? dayEnd : eEnd
|
||||
|
||||
const startHours = clampedStart.getHours() + clampedStart.getMinutes() / 60
|
||||
const durationHours = (clampedEnd.getTime() - clampedStart.getTime()) / 3_600_000
|
||||
|
||||
// Find how many columns this event belongs to (for width calculation)
|
||||
const totalCols = columns.filter((col) => {
|
||||
const eS = new Date(ev.start).getTime()
|
||||
const eE = new Date(ev.end).getTime()
|
||||
return col.some((other) => {
|
||||
if (other === ev) return false
|
||||
const oS = new Date(other.start).getTime()
|
||||
const oE = new Date(other.end).getTime()
|
||||
return eS < oE && eE > oS
|
||||
})
|
||||
}).length + 1
|
||||
|
||||
result.push({
|
||||
event: ev,
|
||||
dayIndex,
|
||||
top: startHours * HOUR_HEIGHT,
|
||||
height: Math.max(durationHours * HOUR_HEIGHT, 18),
|
||||
column: colIdx,
|
||||
totalColumns: totalCols
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
/** Events per day index for rendering into the correct column. */
|
||||
function eventsForDay(dayIndex: number): LayoutEvent[] {
|
||||
return layoutEvents.value.filter((e) => e.dayIndex === dayIndex)
|
||||
}
|
||||
|
||||
function allDayEventsForDay(dayIndex: number): CalendarEvent[] {
|
||||
const d = days.value[dayIndex].date
|
||||
return allDayEvents.value.filter((e) => {
|
||||
const s = new Date(e.start)
|
||||
const end = new Date(e.end)
|
||||
return isSameDay(s, d) || (s < d && end > d)
|
||||
})
|
||||
}
|
||||
|
||||
function formatHour(h: number): string {
|
||||
return h === 0 ? '00:00' : `${String(h).padStart(2, '0')}:00`
|
||||
}
|
||||
|
||||
function eventStyle(layout: LayoutEvent): Record<string, string> {
|
||||
const colWidth = 100 / layout.totalColumns
|
||||
return {
|
||||
top: `${layout.top}px`,
|
||||
height: `${layout.height}px`,
|
||||
left: `${layout.column * colWidth + 0.5}%`,
|
||||
right: `${(layout.totalColumns - layout.column - 1) * colWidth + 0.5}%`,
|
||||
position: 'absolute'
|
||||
}
|
||||
}
|
||||
|
||||
// Accent color palette for calendars (cycle through)
|
||||
const CAL_COLORS = ['#a8e600', '#38bdf8', '#a78bfa', '#f472b6', '#fb923c', '#4ade80', '#f87171']
|
||||
function calendarColor(calendarId: string): string {
|
||||
let hash = 0
|
||||
for (let i = 0; i < calendarId.length; i++) hash = (hash * 31 + calendarId.charCodeAt(i)) & 0xffffff
|
||||
return CAL_COLORS[Math.abs(hash) % CAL_COLORS.length]
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="week-view">
|
||||
<!-- Day header row -->
|
||||
<div class="day-headers">
|
||||
<div class="time-gutter" />
|
||||
<div
|
||||
v-for="(day, i) in days"
|
||||
:key="i"
|
||||
class="day-header"
|
||||
:class="{ today: day.isToday }"
|
||||
>
|
||||
<span class="day-name">{{ day.dayName }}</span>
|
||||
<span class="day-num">{{ day.dayNum }}</span>
|
||||
<span class="month-label">{{ day.monthLabel }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- All-day event row (shown only when there are all-day events) -->
|
||||
<div
|
||||
v-if="events.some((e) => e.isAllDay)"
|
||||
class="allday-row"
|
||||
>
|
||||
<div class="time-gutter allday-gutter">
|
||||
<span class="allday-label">весь день</span>
|
||||
</div>
|
||||
<div v-for="(day, i) in days" :key="i" class="allday-col">
|
||||
<div
|
||||
v-for="ev in allDayEventsForDay(i)"
|
||||
:key="ev.id"
|
||||
class="allday-event"
|
||||
:style="{ '--event-color': calendarColor(ev.calendarId) }"
|
||||
@click="emit('eventClick', ev)"
|
||||
>
|
||||
{{ ev.title }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Scrollable time grid -->
|
||||
<div class="grid-scroll" ref="scrollEl">
|
||||
<div class="time-grid" :style="{ height: `${24 * HOUR_HEIGHT}px` }">
|
||||
<!-- Hour labels -->
|
||||
<div class="time-gutter-col">
|
||||
<div
|
||||
v-for="h in HOURS"
|
||||
:key="h"
|
||||
class="hour-label"
|
||||
:style="{ top: `${h * HOUR_HEIGHT}px` }"
|
||||
>
|
||||
{{ formatHour(h) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Day columns -->
|
||||
<div
|
||||
v-for="(day, i) in days"
|
||||
:key="i"
|
||||
class="day-col"
|
||||
:class="{ today: day.isToday }"
|
||||
>
|
||||
<!-- Hour grid lines -->
|
||||
<div
|
||||
v-for="h in HOURS"
|
||||
:key="h"
|
||||
class="hour-row"
|
||||
:style="{ top: `${h * HOUR_HEIGHT}px`, height: `${HOUR_HEIGHT}px` }"
|
||||
/>
|
||||
|
||||
<!-- Current time indicator -->
|
||||
<div
|
||||
v-if="day.isToday"
|
||||
class="now-line"
|
||||
:style="{ top: `${nowTop}px` }"
|
||||
>
|
||||
<div class="now-dot" />
|
||||
</div>
|
||||
|
||||
<!-- Timed events -->
|
||||
<EventBlock
|
||||
v-for="layout in eventsForDay(i)"
|
||||
:key="layout.event.id"
|
||||
:event="layout.event"
|
||||
:style="eventStyle(layout)"
|
||||
:color="calendarColor(layout.event.calendarId)"
|
||||
@click="emit('eventClick', layout.event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading overlay -->
|
||||
<div v-if="loading" class="loading-overlay">
|
||||
<span class="spinner" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.week-view {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Day headers ── */
|
||||
.day-headers {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
background: rgba(10, 10, 18, 0.5);
|
||||
}
|
||||
|
||||
.time-gutter {
|
||||
width: 52px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.day-header {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 8px 4px;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
border-left: 1px solid var(--glass-border);
|
||||
gap: 2px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.day-header.today .day-num {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
color: var(--accent-text);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.day-name {
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.day-num {
|
||||
font-size: 18px;
|
||||
font-weight: 300;
|
||||
color: var(--text-primary);
|
||||
line-height: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
.month-label {
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* ── All-day row ── */
|
||||
.allday-row {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.allday-gutter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.allday-label {
|
||||
font-size: 9px;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.4px;
|
||||
}
|
||||
|
||||
.allday-col {
|
||||
flex: 1;
|
||||
border-left: 1px solid var(--glass-border);
|
||||
padding: 2px 3px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.allday-event {
|
||||
font-size: 11px;
|
||||
padding: 1px 6px;
|
||||
border-radius: 4px;
|
||||
background: color-mix(in srgb, var(--event-color) 22%, transparent);
|
||||
border-left: 3px solid var(--event-color);
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.allday-event:hover {
|
||||
filter: brightness(1.15);
|
||||
}
|
||||
|
||||
/* ── Scrollable grid ── */
|
||||
.grid-scroll {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.time-grid {
|
||||
display: flex;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* ── Time gutter column ── */
|
||||
.time-gutter-col {
|
||||
width: 52px;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.hour-label {
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
font-size: 10px;
|
||||
color: var(--text-muted);
|
||||
transform: translateY(-50%);
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ── Day column ── */
|
||||
.day-col {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
border-left: 1px solid var(--glass-border);
|
||||
}
|
||||
|
||||
.day-col.today {
|
||||
background: rgba(168, 230, 0, 0.022);
|
||||
}
|
||||
|
||||
/* ── Hour rows (grid lines) ── */
|
||||
.hour-row {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.05);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.hour-row:nth-child(2n) {
|
||||
border-top-color: transparent;
|
||||
border-top: 1px dashed rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
|
||||
/* ── Current time line ── */
|
||||
.now-line {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
background: var(--accent);
|
||||
opacity: 0.75;
|
||||
pointer-events: none;
|
||||
z-index: 4;
|
||||
}
|
||||
|
||||
.now-dot {
|
||||
position: absolute;
|
||||
left: -4px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
box-shadow: 0 0 6px var(--accent);
|
||||
}
|
||||
|
||||
/* ── Loading overlay ── */
|
||||
.loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(9, 9, 14, 0.45);
|
||||
backdrop-filter: blur(4px);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 2px solid var(--glass-border);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { useAccountsStore } from '../../stores/accounts.store'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import AppIcon from '../AppIcon.vue'
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
|
@ -9,6 +9,7 @@ const emit = defineEmits<{
|
|||
|
||||
const accountsStore = useAccountsStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
function getInitial(email: string): string {
|
||||
return email.charAt(0).toUpperCase()
|
||||
|
|
@ -44,6 +45,24 @@ function getAccountColor(index: number): string {
|
|||
|
||||
<div class="spacer" />
|
||||
|
||||
<button
|
||||
class="account-btn nav-btn"
|
||||
:class="{ 'nav-active': route.path === '/' || route.path === '' }"
|
||||
v-tooltip="'Почта'"
|
||||
@click="router.push('/')"
|
||||
>
|
||||
<AppIcon name="envelope" :size="15" class="nav-icon" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="account-btn nav-btn"
|
||||
:class="{ 'nav-active': route.path === '/calendar' }"
|
||||
v-tooltip="'Календарь'"
|
||||
@click="router.push('/calendar')"
|
||||
>
|
||||
<AppIcon name="calendar" :size="15" class="nav-icon" />
|
||||
</button>
|
||||
|
||||
<button class="account-btn settings-btn" v-tooltip="'Настройки'" @click="router.push('/settings')">
|
||||
<AppIcon name="settings" :size="15" class="settings-icon" />
|
||||
</button>
|
||||
|
|
@ -138,13 +157,24 @@ function getAccountColor(index: number): string {
|
|||
}
|
||||
|
||||
.add-icon,
|
||||
.settings-icon {
|
||||
.settings-icon,
|
||||
.nav-icon {
|
||||
color: var(--text-muted);
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.add-btn:hover .add-icon,
|
||||
.settings-btn:hover .settings-icon {
|
||||
.settings-btn:hover .settings-icon,
|
||||
.nav-btn:hover .nav-icon {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.nav-btn.nav-active {
|
||||
background: var(--accent-muted);
|
||||
border-color: color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
}
|
||||
|
||||
.nav-btn.nav-active .nav-icon {
|
||||
color: var(--accent);
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ const router = createRouter({
|
|||
name: 'settings',
|
||||
component: () => import('./views/SettingsView.vue')
|
||||
},
|
||||
{
|
||||
path: '/calendar',
|
||||
name: 'calendar',
|
||||
component: () => import('./views/CalendarView.vue')
|
||||
},
|
||||
{
|
||||
path: '/compose',
|
||||
name: 'compose',
|
||||
|
|
|
|||
135
src/renderer/src/stores/calendar.store.ts
Normal file
135
src/renderer/src/stores/calendar.store.ts
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { startOfWeek, endOfWeek, addWeeks, subWeeks } from 'date-fns'
|
||||
import { useIpc } from '../composables/useIpc'
|
||||
import { useAccountsStore } from './accounts.store'
|
||||
import type { CalendarInfo, CalendarEvent } from '@shared/types/calendar'
|
||||
|
||||
export const useCalendarStore = defineStore('calendar', () => {
|
||||
const { invoke } = useIpc()
|
||||
const accountsStore = useAccountsStore()
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const calendars = ref<CalendarInfo[]>([])
|
||||
const events = ref<CalendarEvent[]>([])
|
||||
const selectedCalendarIds = ref<Set<string>>(new Set())
|
||||
const selectedEvent = ref<CalendarEvent | null>(null)
|
||||
const currentWeekStart = ref<Date>(startOfWeek(new Date(), { weekStartsOn: 1 }))
|
||||
const loading = ref(false)
|
||||
const loadingCalendars = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
// ── Computed ───────────────────────────────────────────────────────────────
|
||||
|
||||
const currentWeekEnd = computed(() => endOfWeek(currentWeekStart.value, { weekStartsOn: 1 }))
|
||||
|
||||
const visibleEvents = computed(() => {
|
||||
if (selectedCalendarIds.value.size === 0) return events.value
|
||||
return events.value.filter((e) => selectedCalendarIds.value.has(e.calendarId))
|
||||
})
|
||||
|
||||
// ── Calendars ──────────────────────────────────────────────────────────────
|
||||
|
||||
async function loadCalendars(): Promise<void> {
|
||||
const accountId = accountsStore.activeAccountId
|
||||
if (!accountId) return
|
||||
|
||||
loadingCalendars.value = true
|
||||
error.value = null
|
||||
try {
|
||||
calendars.value = await invoke('calendar:list', { accountId })
|
||||
// Select all calendars by default
|
||||
selectedCalendarIds.value = new Set(calendars.value.map((c) => c.id))
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message
|
||||
calendars.value = []
|
||||
} finally {
|
||||
loadingCalendars.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function toggleCalendar(calendarId: string): void {
|
||||
const s = new Set(selectedCalendarIds.value)
|
||||
if (s.has(calendarId)) s.delete(calendarId)
|
||||
else s.add(calendarId)
|
||||
selectedCalendarIds.value = s
|
||||
}
|
||||
|
||||
// ── Events ─────────────────────────────────────────────────────────────────
|
||||
|
||||
async function loadEvents(): Promise<void> {
|
||||
const accountId = accountsStore.activeAccountId
|
||||
if (!accountId || calendars.value.length === 0) return
|
||||
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
const start = currentWeekStart.value.toISOString()
|
||||
// Expand end by 1 day to include events that start on Sunday
|
||||
const end = new Date(currentWeekEnd.value.getTime() + 24 * 60 * 60 * 1000).toISOString()
|
||||
|
||||
const allEvents: CalendarEvent[] = []
|
||||
for (const cal of calendars.value) {
|
||||
try {
|
||||
const calEvents = await invoke('calendar:events', {
|
||||
accountId,
|
||||
calendarId: cal.id,
|
||||
start,
|
||||
end
|
||||
})
|
||||
allEvents.push(...calEvents)
|
||||
} catch {
|
||||
// Skip calendars that fail individually
|
||||
}
|
||||
}
|
||||
events.value = allEvents
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||
|
||||
async function goToToday(): Promise<void> {
|
||||
currentWeekStart.value = startOfWeek(new Date(), { weekStartsOn: 1 })
|
||||
await loadEvents()
|
||||
}
|
||||
|
||||
async function prevWeek(): Promise<void> {
|
||||
currentWeekStart.value = subWeeks(currentWeekStart.value, 1)
|
||||
await loadEvents()
|
||||
}
|
||||
|
||||
async function nextWeek(): Promise<void> {
|
||||
currentWeekStart.value = addWeeks(currentWeekStart.value, 1)
|
||||
await loadEvents()
|
||||
}
|
||||
|
||||
function selectEvent(event: CalendarEvent | null): void {
|
||||
selectedEvent.value = event
|
||||
}
|
||||
|
||||
return {
|
||||
calendars,
|
||||
events,
|
||||
selectedCalendarIds,
|
||||
selectedEvent,
|
||||
currentWeekStart,
|
||||
currentWeekEnd,
|
||||
loading,
|
||||
loadingCalendars,
|
||||
error,
|
||||
visibleEvents,
|
||||
loadCalendars,
|
||||
loadEvents,
|
||||
toggleCalendar,
|
||||
goToToday,
|
||||
prevWeek,
|
||||
nextWeek,
|
||||
selectEvent
|
||||
}
|
||||
})
|
||||
496
src/renderer/src/views/CalendarView.vue
Normal file
496
src/renderer/src/views/CalendarView.vue
Normal file
|
|
@ -0,0 +1,496 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted, watch } from 'vue'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import { useCalendarStore } from '../stores/calendar.store'
|
||||
import { useAccountsStore } from '../stores/accounts.store'
|
||||
import AccountSwitcher from '../components/sidebar/AccountSwitcher.vue'
|
||||
import WeekView from '../components/calendar/WeekView.vue'
|
||||
import EventDetailPopup from '../components/calendar/EventDetailPopup.vue'
|
||||
import AddAccountDialog from '../components/accounts/AddAccountDialog.vue'
|
||||
import NotificationContainer from '../components/notifications/NotificationContainer.vue'
|
||||
import AppIcon from '../components/AppIcon.vue'
|
||||
import type { CalendarEvent } from '@shared/types/calendar'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const calStore = useCalendarStore()
|
||||
const accountsStore = useAccountsStore()
|
||||
const showAddAccount = ref(false)
|
||||
|
||||
// Calendar color palette, same as WeekView
|
||||
const CAL_COLORS = ['#a8e600', '#38bdf8', '#a78bfa', '#f472b6', '#fb923c', '#4ade80', '#f87171']
|
||||
function calendarColor(calendarId: string): string {
|
||||
let hash = 0
|
||||
for (let i = 0; i < calendarId.length; i++) hash = (hash * 31 + calendarId.charCodeAt(i)) & 0xffffff
|
||||
return CAL_COLORS[Math.abs(hash) % CAL_COLORS.length]
|
||||
}
|
||||
|
||||
const weekLabel = () => {
|
||||
const s = calStore.currentWeekStart
|
||||
const e = calStore.currentWeekEnd
|
||||
const sStr = format(s, 'd MMM', { locale: ru })
|
||||
const eStr = format(e, 'd MMM yyyy', { locale: ru })
|
||||
return `${sStr} – ${eStr}`
|
||||
}
|
||||
|
||||
async function reload(): Promise<void> {
|
||||
await calStore.loadCalendars()
|
||||
await calStore.loadEvents()
|
||||
}
|
||||
|
||||
onMounted(reload)
|
||||
watch(() => accountsStore.activeAccountId, reload)
|
||||
|
||||
function handleEventClick(ev: CalendarEvent): void {
|
||||
calStore.selectEvent(ev)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="calendar-shell">
|
||||
<div class="content-area">
|
||||
<!-- Account switcher (same as mail view) -->
|
||||
<div class="account-bar">
|
||||
<AccountSwitcher @add-account="showAddAccount = true" />
|
||||
</div>
|
||||
|
||||
<!-- Calendar sidebar -->
|
||||
<div class="cal-sidebar">
|
||||
<div class="sidebar-header">
|
||||
<AppIcon name="calendar" :size="15" class="cal-icon" />
|
||||
<span>Календарь</span>
|
||||
</div>
|
||||
|
||||
<!-- Error state -->
|
||||
<div v-if="calStore.error" class="sidebar-error">
|
||||
<p class="error-title">CalDAV недоступен</p>
|
||||
<p class="error-detail">{{ calStore.error }}</p>
|
||||
<p class="error-hint">Убедитесь что Exchange 2013+ с поддержкой CalDAV доступен на том же хосте что и IMAP.</p>
|
||||
<button class="retry-btn" @click="reload">Повторить</button>
|
||||
</div>
|
||||
|
||||
<!-- Calendar list -->
|
||||
<div v-else-if="!calStore.loadingCalendars" class="calendar-list">
|
||||
<div
|
||||
v-for="cal in calStore.calendars"
|
||||
:key="cal.id"
|
||||
class="cal-item"
|
||||
:class="{ active: calStore.selectedCalendarIds.has(cal.id) }"
|
||||
@click="calStore.toggleCalendar(cal.id)"
|
||||
>
|
||||
<span
|
||||
class="cal-dot"
|
||||
:style="{ background: calendarColor(cal.id) }"
|
||||
/>
|
||||
<span class="cal-name" :title="cal.name">{{ cal.name }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="calStore.calendars.length === 0 && !calStore.loadingCalendars && !calStore.error" class="no-calendars">
|
||||
Нет доступных календарей
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="sidebar-loading">
|
||||
<span class="spinner" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main calendar area -->
|
||||
<div class="calendar-main">
|
||||
<!-- Toolbar -->
|
||||
<div class="toolbar">
|
||||
<button class="nav-btn" @click="calStore.prevWeek()">
|
||||
<AppIcon name="chevron-right" :size="14" style="transform: rotate(180deg)" />
|
||||
</button>
|
||||
<button class="nav-btn today-btn" @click="calStore.goToToday()">Сегодня</button>
|
||||
<button class="nav-btn" @click="calStore.nextWeek()">
|
||||
<AppIcon name="chevron-right" :size="14" />
|
||||
</button>
|
||||
|
||||
<span class="week-label">{{ weekLabel() }}</span>
|
||||
|
||||
<button class="nav-btn refresh-btn" :disabled="calStore.loading" @click="calStore.loadEvents()">
|
||||
<AppIcon name="refresh" :size="14" :class="{ spinning: calStore.loading }" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Week view -->
|
||||
<div class="week-wrap">
|
||||
<WeekView
|
||||
:week-start="calStore.currentWeekStart"
|
||||
:events="calStore.visibleEvents"
|
||||
:loading="calStore.loading"
|
||||
@event-click="handleEventClick"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Event detail popup -->
|
||||
<EventDetailPopup
|
||||
v-if="calStore.selectedEvent"
|
||||
:event="calStore.selectedEvent"
|
||||
@close="calStore.selectEvent(null)"
|
||||
/>
|
||||
|
||||
<AddAccountDialog
|
||||
v-if="showAddAccount"
|
||||
@close="showAddAccount = false"
|
||||
/>
|
||||
|
||||
<NotificationContainer />
|
||||
|
||||
<!-- Empty state: no accounts -->
|
||||
<div
|
||||
v-if="accountsStore.accounts.length === 0 && !accountsStore.loading && !showAddAccount"
|
||||
class="empty-state"
|
||||
>
|
||||
<div class="empty-content">
|
||||
<div class="empty-icon">
|
||||
<AppIcon name="calendar" :size="64" />
|
||||
</div>
|
||||
<h2>Добро пожаловать в Aero Mail</h2>
|
||||
<p>Добавьте почтовый аккаунт для просмотра календаря</p>
|
||||
<button class="add-btn" @click="showAddAccount = true">Добавить аккаунт</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.calendar-shell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background: #07070c;
|
||||
}
|
||||
|
||||
.content-area {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
padding: 8px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Account bar — same styling as in AppShell */
|
||||
.account-bar {
|
||||
width: var(--sidebar-width);
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
z-index: 4;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.09);
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%),
|
||||
rgba(8, 8, 13, 0.88);
|
||||
backdrop-filter: blur(40px) saturate(2.0);
|
||||
-webkit-backdrop-filter: blur(40px) saturate(2.0);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.12),
|
||||
0 8px 32px rgba(0, 0, 0, 0.50);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Calendar sidebar */
|
||||
.cal-sidebar {
|
||||
width: 200px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.015) 100%),
|
||||
rgba(9, 9, 15, 0.80);
|
||||
backdrop-filter: blur(28px) saturate(1.8);
|
||||
-webkit-backdrop-filter: blur(28px) saturate(1.8);
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.10),
|
||||
0 8px 28px rgba(0, 0, 0, 0.40);
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 14px 14px 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
letter-spacing: 0.3px;
|
||||
text-transform: uppercase;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
}
|
||||
|
||||
.cal-icon {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
/* Calendar list */
|
||||
.calendar-list {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.cal-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 8px;
|
||||
margin: 0 4px;
|
||||
transition: background var(--transition-fast);
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.cal-item.active {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cal-item:hover {
|
||||
background: var(--glass-bg-hover);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.cal-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 0 4px currentColor;
|
||||
}
|
||||
|
||||
.cal-name {
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.cal-item.active .cal-name {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.no-calendars {
|
||||
padding: 16px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Error state */
|
||||
.sidebar-error {
|
||||
padding: 12px 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.error-detail {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.error-hint {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.retry-btn {
|
||||
align-self: flex-start;
|
||||
font-size: 12px;
|
||||
padding: 4px 12px;
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--glass-bg-raised);
|
||||
border: 1px solid var(--glass-border);
|
||||
color: var(--text-secondary);
|
||||
transition: background var(--transition-fast);
|
||||
}
|
||||
.retry-btn:hover { background: var(--glass-bg-hover); }
|
||||
|
||||
.sidebar-loading {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
/* Main calendar */
|
||||
.calendar-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%),
|
||||
rgba(10, 10, 17, 0.55);
|
||||
backdrop-filter: blur(18px) saturate(1.3);
|
||||
-webkit-backdrop-filter: blur(18px) saturate(1.3);
|
||||
overflow: hidden;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.08),
|
||||
0 8px 28px rgba(0, 0, 0, 0.32);
|
||||
}
|
||||
|
||||
/* Toolbar */
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 10px 16px;
|
||||
border-bottom: 1px solid var(--glass-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
height: 28px;
|
||||
padding: 0 10px;
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--glass-bg);
|
||||
border: 1px solid var(--glass-border);
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
transition: background var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.nav-btn:hover:not(:disabled) {
|
||||
background: var(--glass-bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.today-btn {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.week-label {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
margin-left: 4px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
margin-left: auto;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.spinning {
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
/* Week wrap */
|
||||
.week-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Spinner */
|
||||
.spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--glass-border);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
/* Empty state (no accounts) */
|
||||
.empty-state {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: transparent;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.empty-content {
|
||||
text-align: center;
|
||||
padding: 64px 72px;
|
||||
width: 480px;
|
||||
background: rgba(255, 255, 255, 0.11);
|
||||
backdrop-filter: blur(72px) saturate(2.8);
|
||||
-webkit-backdrop-filter: blur(72px) saturate(2.8);
|
||||
border-radius: 20px;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.55),
|
||||
0 8px 32px rgba(0, 0, 0, 0.45),
|
||||
0 32px 80px rgba(0, 0, 0, 0.65);
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
margin-bottom: 24px;
|
||||
opacity: 0.28;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty-content h2 {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.empty-content p {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
padding: 10px 32px;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent) 88%, white 12%) 0%,
|
||||
var(--accent) 100%
|
||||
);
|
||||
color: var(--accent-text);
|
||||
border-radius: var(--radius-md);
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.40),
|
||||
0 2px 10px color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
}
|
||||
|
||||
.add-btn:hover {
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent-hover) 88%, white 12%) 0%,
|
||||
var(--accent-hover) 100%
|
||||
);
|
||||
}
|
||||
</style>
|
||||
22
src/shared/types/calendar.ts
Normal file
22
src/shared/types/calendar.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
export interface CalendarInfo {
|
||||
id: string
|
||||
name: string
|
||||
color?: string
|
||||
accountId: string
|
||||
}
|
||||
|
||||
export interface CalendarEvent {
|
||||
id: string
|
||||
uid: string
|
||||
calendarId: string
|
||||
accountId: string
|
||||
title: string
|
||||
start: string // ISO 8601
|
||||
end: string // ISO 8601
|
||||
isAllDay: boolean
|
||||
location?: string
|
||||
description?: string
|
||||
organizer?: string
|
||||
attendees: string[]
|
||||
status?: 'tentative' | 'confirmed' | 'cancelled'
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import type { AccountConfig } from './account'
|
||||
import type { FolderListResult, MessageListResult } from './provider'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, ComposeData, ComposeSession } from './message'
|
||||
import type { CalendarInfo, CalendarEvent } from './calendar'
|
||||
|
||||
export interface IpcChannelMap {
|
||||
'accounts:list': [void, AccountConfig[]]
|
||||
|
|
@ -47,6 +48,12 @@ export interface IpcChannelMap {
|
|||
|
||||
'app:setZoom': [{ factor: number }, void]
|
||||
'app:isEncryptionAvailable': [void, boolean]
|
||||
|
||||
'calendar:list': [{ accountId: string }, CalendarInfo[]]
|
||||
'calendar:events': [
|
||||
{ accountId: string; calendarId: string; start: string; end: string },
|
||||
CalendarEvent[]
|
||||
]
|
||||
}
|
||||
|
||||
export interface IpcEventMap {
|
||||
|
|
|
|||
Loading…
Reference in a new issue