This commit is contained in:
fmodf 2024-07-10 16:13:47 +02:00
parent eb06abaebf
commit e2363f9f9f
18 changed files with 81 additions and 31 deletions

View file

@ -11,4 +11,5 @@ enum AppAction: Codable {
case chatsAction(_ action: ChatsAction) case chatsAction(_ action: ChatsAction)
case conversationAction(_ action: ConversationAction) case conversationAction(_ action: ConversationAction)
case messagesAction(_ action: MessagesAction) case messagesAction(_ action: MessagesAction)
case sharingAction(_ action: SharingAction)
} }

View file

@ -5,9 +5,4 @@ enum ConversationAction: Codable {
case sendMessage(from: String, to: String, body: String) case sendMessage(from: String, to: String, body: String)
case setReplyText(String) case setReplyText(String)
case showAttachmentPicker(Bool)
case sendAttachment([ShareItem])
case sendAttachmentDone
case sendAttachmentError(reason: String)
} }

View file

@ -0,0 +1,7 @@
enum SharingAction: Codable {
case showSharing(Bool)
// case sendAttachment([ShareItem])
// case sendAttachmentDone
// case sendAttachmentError(reason: String)
}

View file

@ -0,0 +1,15 @@
import Combine
import Foundation
import Martin
final class SharingMiddleware {
static let shared = SharingMiddleware()
private let gallery = GalleryService()
func middleware(state _: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
switch action {
default:
return Empty().eraseToAnyPublisher()
}
}
}

View file

@ -30,6 +30,9 @@ extension AppState {
case .messagesAction: case .messagesAction:
break // messages actions are processed by MessagesMiddleware, and other components break // messages actions are processed by MessagesMiddleware, and other components
case .sharingAction(let action):
SharingState.reducer(state: &state.sharingState, action: action)
} }
} }
} }

View file

@ -17,9 +17,6 @@ extension ConversationState {
state.replyText = text.makeReply state.replyText = text.makeReply
} }
case .showAttachmentPicker(let flag):
state.attachmentPickerVisible = flag
default: default:
break break
} }

View file

@ -0,0 +1,11 @@
extension SharingState {
static func reducer(state: inout SharingState, action: SharingAction) {
switch action {
case .showSharing(let shown):
state.sharingShown = shown
default:
break
}
}
}

View file

@ -0,0 +1,5 @@
import Foundation
final class GalleryService {
var dumb = false
}

View file

@ -19,6 +19,7 @@ struct AppState: Stateable {
var rostersState: RostersState var rostersState: RostersState
var chatsState: ChatsState var chatsState: ChatsState
var conversationsState: ConversationState var conversationsState: ConversationState
var sharingState: SharingState
} }
// MARK: Init // MARK: Init
@ -33,5 +34,6 @@ extension AppState {
rostersState = RostersState() rostersState = RostersState()
chatsState = ChatsState() chatsState = ChatsState()
conversationsState = ConversationState() conversationsState = ConversationState()
sharingState = SharingState()
} }
} }

View file

@ -0,0 +1,10 @@
struct SharingState: Stateable {
var sharingShown: Bool
}
// MARK: Init
extension SharingState {
init() {
sharingShown = false
}
}

View file

@ -14,7 +14,8 @@ let store = AppStore(
RostersMiddleware.shared.middleware, RostersMiddleware.shared.middleware,
ChatsMiddleware.shared.middleware, ChatsMiddleware.shared.middleware,
ConversationMiddleware.shared.middleware, ConversationMiddleware.shared.middleware,
MessagesMiddleware.shared.middleware MessagesMiddleware.shared.middleware,
SharingMiddleware.shared.middleware
] ]
) )

View file

@ -40,14 +40,15 @@ struct AttachmentContactsPickerView: View {
.clipped() .clipped()
.onTapGesture { .onTapGesture {
if let selectedContact = selectedContact { if let selectedContact = selectedContact {
store.dispatch(.conversationAction(.sendAttachment([.init( // TODO: fix it
id: UUID().uuidString, // store.dispatch(.conversationAction(.sendAttachment([.init(
type: .contact, // id: UUID().uuidString,
data: Data(), // type: .contact,
thumbnail: Data(), // data: Data(),
string: selectedContact.contactBareJid // thumbnail: Data(),
)]))) // string: selectedContact.contactBareJid
store.dispatch(.conversationAction(.showAttachmentPicker(false))) // )])))
store.dispatch(.sharingAction(.showSharing(false)))
} }
} }
} }

View file

@ -16,11 +16,12 @@ struct AttachmentFilesPickerView: View {
string: "" string: ""
) )
} }
store.dispatch(.conversationAction(.sendAttachment(sharedFiles))) // TODO: Send files
store.dispatch(.conversationAction(.showAttachmentPicker(false))) // store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
store.dispatch(.sharingAction(.showSharing(false)))
}, },
cancel: { cancel: {
store.dispatch(.conversationAction(.showAttachmentPicker(false))) store.dispatch(.sharingAction(.showSharing(false)))
} }
) )
} }

View file

@ -19,7 +19,7 @@ struct AttachmentHeader: View {
Image(systemName: "xmark") Image(systemName: "xmark")
.foregroundColor(Color.Material.Elements.active) .foregroundColor(Color.Material.Elements.active)
.tappablePadding(.symmetric(12)) { .tappablePadding(.symmetric(12)) {
store.dispatch(.conversationAction(.showAttachmentPicker(false))) store.dispatch(.sharingAction(.showSharing(false)))
} }
} }
.padding(.horizontal, 16) .padding(.horizontal, 16)

View file

@ -62,14 +62,15 @@ struct AttachmentLocationPickerView: View {
} }
.clipped() .clipped()
.onTapGesture { .onTapGesture {
store.dispatch(.conversationAction(.sendAttachment([.init( // TODO: Send location
id: UUID().uuidString, // store.dispatch(.conversationAction(.sendAttachment([.init(
type: .location, // id: UUID().uuidString,
data: Data(), // type: .location,
thumbnail: Data(), // data: Data(),
string: "\(region.center.latitude),\(region.center.longitude)" // thumbnail: Data(),
)]))) // string: "\(region.center.latitude),\(region.center.longitude)"
store.dispatch(.conversationAction(.showAttachmentPicker(false))) // )])))
store.dispatch(.sharingAction(.showSharing(false)))
} }
} }
.onAppear { .onAppear {

View file

@ -131,7 +131,7 @@ struct AttachmentMediaPickerView: View {
.onTapGesture { .onTapGesture {
let ids = selectedMedia.map { $0.id } let ids = selectedMedia.map { $0.id }
sendGalleryMedia(ids: ids) sendGalleryMedia(ids: ids)
store.dispatch(.conversationAction(.showAttachmentPicker(false))) store.dispatch(.sharingAction(.showSharing(false)))
} }
} }
.onAppear { .onAppear {

View file

@ -49,7 +49,7 @@ struct ConversationTextInput: View {
.foregroundColor(.Material.Elements.active) .foregroundColor(.Material.Elements.active)
.padding(.leading, 8) .padding(.leading, 8)
.tappablePadding(.symmetric(8)) { .tappablePadding(.symmetric(8)) {
store.dispatch(.conversationAction(.showAttachmentPicker(true))) store.dispatch(.sharingAction(.showSharing(true)))
} }
TextField(L10n.Chat.textfieldPrompt, text: $messageStr) TextField(L10n.Chat.textfieldPrompt, text: $messageStr)
.font(.body1) .font(.body1)