Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
336 changes: 115 additions & 221 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions Example/Example/Models/Payload.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@

import SwiftUI
import SwiftData
import Mindbox

struct NotificationCenterView: View {

var viewModel: NotificationCenterViewModelProtocol

@State private var showAlert = false
@State private var alertTitle = String()
@State private var alertMessage = String()

@Environment(\.modelContext) private var modelContext
@Query private var items: [Item]

var body: some View {
NavigationStack {
List {
Expand All @@ -31,7 +32,7 @@ struct NotificationCenterView: View {
Spacer()
}
}

.contentShape(Rectangle())
.onTapGesture {
viewModel.sendOperationNCPushOpen(notification: item.mbPushNotification)
Expand Down Expand Up @@ -60,7 +61,7 @@ struct NotificationCenterView: View {
Button("OK", action: {})
}
}

private func deleteItems(offsets: IndexSet) {
withAnimation {
let originalOffsets = IndexSet(offsets.map { items.count - 1 - $0 })
Expand All @@ -70,14 +71,47 @@ struct NotificationCenterView: View {
return
} else {
modelContext.delete(items[index])

}
}
}
UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
}
}

// MARK: - NotificationCellView

private struct NotificationCellView: View {
var notification: PushNotification

var body: some View {
HStack(alignment: .center, content: {
if let imageUrl = notification.imageUrl, let url = URL(string: imageUrl) {
AsyncImage(url: url) { image in
image
.resizable()
.scaledToFill()
} placeholder: {
ProgressView()
}
.frame(maxWidth: 64, maxHeight: 64)
.clipShape(Circle())
}

VStack(alignment: .leading, content: {
Text(notification.title ?? "Empty")
.font(.headline)
Text(notification.body ?? "Empty")
.font(.subheadline)
.foregroundStyle(.gray)
Text(notification.clickUrl ?? "Empty")
.font(.footnote)
.foregroundStyle(.blue)
})
})
}
}

#Preview {
NotificationCenterView(viewModel: NotificationCenterViewModel())
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Item+SwiftData.swift
// NotificationModels.swift
// Example
//
// Created by Sergei Semko on 6/11/24.
Expand All @@ -13,7 +13,7 @@ import SwiftData
public final class Item {
public var timestamp: Date
public var mbPushNotification: PushNotification

public init(timestamp: Date, pushNotification: PushNotification) {
self.timestamp = timestamp
self.mbPushNotification = pushNotification
Expand All @@ -27,9 +27,14 @@ public struct PushNotification: Codable {
public let imageUrl: String?
public let payload: String?
public let uniqueKey: String?

var decodedPayload: Payload? {
guard let payloadData = payload?.data(using: .utf8) else { return nil }
return try? JSONDecoder().decode(Payload.self, from: payloadData)
}
}

public struct Payload: Codable {
var pushName: String
var pushDate: String
}

This file was deleted.