C1 — Localization: route the remaining hardcoded German strings through L10n (LoginView, ServerSetupView, SettingsView email, EventDetailSheet) so "System Default" + English device language shows fully English text. C2 — Per-calendar reminders: parse the new reminders_enabled flag on every calendar type; CalendarStore persists a reminderDisabledKeys set and passes it to NotificationScheduler, which skips events of muted calendars (default and per-event reminders). Filter sheet gains a per-calendar reminder toggle (leading swipe + bell.slash indicator), reconciled from the server and synced back via PUT. C3 — Widgets: - Shared WidgetTime.range helper; Today / Today & Tomorrow / Three Days / Up Next now show start–end instead of only the start time. - This Week: show up to 6 events per day (was 3) to use the height. - Two Weeks: mini event-title pills instead of bare dots. - Two Months: weeks expand to fill the column (no more empty lower third). - Day & Events: smaller header/strip/rows so content stops clipping. - Next 5 days → Next 7 days (range + labels), higher row cap. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
137 lines
5.8 KiB
Swift
137 lines
5.8 KiB
Swift
import SwiftUI
|
|
|
|
struct LoginView: View {
|
|
@Environment(AppState.self) var appState
|
|
@AppStorage("appLanguage") private var appLang = "system"
|
|
@State private var username = ""
|
|
@State private var password = ""
|
|
@State private var totpCode = ""
|
|
@State private var rememberMe = true
|
|
@State private var needsTOTP = false
|
|
@State private var error = ""
|
|
@State private var isLoading = false
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
ScrollView {
|
|
VStack(spacing: 0) {
|
|
Spacer().frame(height: 60)
|
|
|
|
VStack(spacing: 8) {
|
|
Image(systemName: "calendar")
|
|
.font(.system(size: 48, weight: .light))
|
|
.foregroundStyle(Color.accentColor)
|
|
Text("Calendarr")
|
|
.font(.largeTitle.bold())
|
|
Text(appState.serverURL
|
|
.replacingOccurrences(of: "https://", with: "")
|
|
.replacingOccurrences(of: "http://", with: ""))
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.padding(.bottom, 40)
|
|
|
|
VStack(spacing: 16) {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
Text(L10n.t("login.username", appLang))
|
|
.font(.footnote.weight(.medium))
|
|
.foregroundStyle(.secondary)
|
|
TextField(L10n.t("login.username", appLang), text: $username)
|
|
.textInputAutocapitalization(.never)
|
|
.autocorrectionDisabled()
|
|
.padding(12)
|
|
.background(.quaternary)
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
}
|
|
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
Text(L10n.t("login.password", appLang))
|
|
.font(.footnote.weight(.medium))
|
|
.foregroundStyle(.secondary)
|
|
SecureField(L10n.t("login.password", appLang), text: $password)
|
|
.padding(12)
|
|
.background(.quaternary)
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
}
|
|
|
|
if needsTOTP {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
Text(L10n.t("login.totp", appLang))
|
|
.font(.footnote.weight(.medium))
|
|
.foregroundStyle(.secondary)
|
|
TextField(L10n.t("login.totp_placeholder", appLang), text: $totpCode)
|
|
.keyboardType(.numberPad)
|
|
.padding(12)
|
|
.background(.quaternary)
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
}
|
|
.transition(.move(edge: .top).combined(with: .opacity))
|
|
}
|
|
|
|
Toggle(L10n.t("login.remember", appLang), isOn: $rememberMe)
|
|
.tint(Color.accentColor)
|
|
|
|
if !error.isEmpty {
|
|
Text(error)
|
|
.font(.caption)
|
|
.foregroundStyle(.red)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
|
|
Button {
|
|
Task { await login() }
|
|
} label: {
|
|
HStack {
|
|
if isLoading {
|
|
ProgressView().tint(.white)
|
|
} else {
|
|
Text(L10n.t("login.signin", appLang)).fontWeight(.semibold)
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.padding(14)
|
|
.background(Color.accentColor)
|
|
.foregroundStyle(.white)
|
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
|
}
|
|
.disabled(username.isEmpty || password.isEmpty || isLoading)
|
|
}
|
|
.padding(.horizontal, 32)
|
|
.animation(.easeInOut, value: needsTOTP)
|
|
|
|
Spacer().frame(height: 40)
|
|
|
|
Button(L10n.t("login.choose_server", appLang)) {
|
|
appState.resetServer()
|
|
}
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.navigationBarHidden(true)
|
|
}
|
|
}
|
|
|
|
private func login() async {
|
|
isLoading = true
|
|
error = ""
|
|
defer { isLoading = false }
|
|
|
|
do {
|
|
let code = needsTOTP ? (totpCode.isEmpty ? nil : totpCode) : nil
|
|
let result = try await CalendarrAPI.login(
|
|
baseURL: appState.serverURL,
|
|
username: username,
|
|
password: password,
|
|
totpCode: code,
|
|
rememberMe: rememberMe
|
|
)
|
|
appState.saveLogin(token: result.token, user: result.username, admin: result.isAdmin)
|
|
} catch APIError.twoFactorRequired {
|
|
withAnimation { needsTOTP = true }
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
}
|
|
}
|
|
}
|