feat: add complete Mayday iOS Xcode project
- Swift 6, SwiftUI, MVVM + async/await architecture - iOS 17.0 minimum deployment target - Two targets: Mayday app + MaydayLiveActivity widget extension - Models: UserResponse, TokenPair, AppNotification, SessionResponse, AlertAttributes - Services: HTTPClient (actor), AuthService, KeychainService, NotificationsAPIService, PushNotificationService - ViewModels: AuthViewModel, NotificationsViewModel, SettingsViewModel - Views: Login/Register/VerifyEmail, NotificationsList/Detail, Settings/ChangePassword/Sessions - APNs push notifications with UIApplicationDelegate - ActivityKit Live Activities for Dynamic Island + Lock Screen - Keychain (Security framework) token storage - 30-second polling with pagination for notifications - Xcode project file (project.pbxproj) with correct build phases for both targets Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import SwiftUI
|
||||
|
||||
struct NotificationDetailView: View {
|
||||
let notification: AppNotification
|
||||
let viewModel: NotificationsViewModel
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 20) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(notification.topic)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
Text(notification.subject)
|
||||
.font(.title2.bold())
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Подробности:")
|
||||
.font(.headline)
|
||||
Text(notification.body)
|
||||
.font(.body)
|
||||
}
|
||||
|
||||
if let metadata = notification.metadata, !metadata.isEmpty {
|
||||
Divider()
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Метаданные:")
|
||||
.font(.headline)
|
||||
ForEach(metadata.sorted(by: { $0.key < $1.key }), id: \.key) { key, value in
|
||||
HStack {
|
||||
Text(key).foregroundStyle(.secondary)
|
||||
Spacer()
|
||||
Text(value)
|
||||
}
|
||||
.font(.footnote)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
LabeledContent("Получено") {
|
||||
Text(notification.createdAt.formatted(date: .abbreviated, time: .shortened))
|
||||
}
|
||||
LabeledContent("Статус") {
|
||||
Text(notification.status.rawValue)
|
||||
}
|
||||
LabeledContent("Канал") {
|
||||
Text(notification.channel.rawValue)
|
||||
}
|
||||
}
|
||||
.font(.footnote)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.navigationTitle("Уведомление")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.task {
|
||||
await viewModel.markAsRead(notification)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import SwiftUI
|
||||
|
||||
struct NotificationsView: View {
|
||||
@EnvironmentObject var authViewModel: AuthViewModel
|
||||
@StateObject private var viewModel = NotificationsViewModel()
|
||||
@State private var showSettings = false
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Group {
|
||||
if viewModel.isLoading && viewModel.notifications.isEmpty {
|
||||
ProgressView()
|
||||
} else if let error = viewModel.error, viewModel.notifications.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"Ошибка загрузки",
|
||||
systemImage: "exclamationmark.triangle",
|
||||
description: Text(error)
|
||||
)
|
||||
} else if viewModel.notifications.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"Нет уведомлений",
|
||||
systemImage: "bell.slash",
|
||||
description: Text("Новые уведомления появятся здесь")
|
||||
)
|
||||
} else {
|
||||
notificationsList
|
||||
}
|
||||
}
|
||||
.navigationTitle("Уведомления")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button {
|
||||
showSettings = true
|
||||
} label: {
|
||||
Image(systemName: "gear")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showSettings) {
|
||||
SettingsView()
|
||||
.environmentObject(authViewModel)
|
||||
}
|
||||
.task {
|
||||
await viewModel.load()
|
||||
viewModel.startPolling()
|
||||
}
|
||||
.onDisappear {
|
||||
viewModel.stopPolling()
|
||||
}
|
||||
.refreshable {
|
||||
await viewModel.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var notificationsList: some View {
|
||||
List {
|
||||
ForEach(viewModel.notifications) { notification in
|
||||
NavigationLink(destination: NotificationDetailView(notification: notification, viewModel: viewModel)) {
|
||||
NotificationRowView(notification: notification)
|
||||
}
|
||||
.swipeActions(edge: .leading) {
|
||||
if !notification.isRead {
|
||||
Button {
|
||||
Task { await viewModel.markAsRead(notification) }
|
||||
} label: {
|
||||
Label("Прочитано", systemImage: "checkmark")
|
||||
}
|
||||
.tint(.blue)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if notification.id == viewModel.notifications.last?.id {
|
||||
Task { await viewModel.loadMore() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.isLoadingMore {
|
||||
HStack {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
||||
struct NotificationRowView: View {
|
||||
let notification: AppNotification
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
Circle()
|
||||
.fill(notification.isRead ? Color.clear : Color.blue)
|
||||
.frame(width: 8, height: 8)
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(notification.topic)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
Text(notification.subject)
|
||||
.font(.body)
|
||||
.fontWeight(notification.isRead ? .regular : .semibold)
|
||||
Text(notification.createdAt.relativeFormatted)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
}
|
||||
|
||||
extension Date {
|
||||
var relativeFormatted: String {
|
||||
let formatter = RelativeDateTimeFormatter()
|
||||
formatter.locale = Locale(identifier: "ru_RU")
|
||||
return formatter.localizedString(for: self, relativeTo: Date())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user