wip
This commit is contained in:
parent
eb06abaebf
commit
e2363f9f9f
|
@ -11,4 +11,5 @@ enum AppAction: Codable {
|
|||
case chatsAction(_ action: ChatsAction)
|
||||
case conversationAction(_ action: ConversationAction)
|
||||
case messagesAction(_ action: MessagesAction)
|
||||
case sharingAction(_ action: SharingAction)
|
||||
}
|
||||
|
|
|
@ -5,9 +5,4 @@ enum ConversationAction: Codable {
|
|||
|
||||
case sendMessage(from: String, to: String, body: String)
|
||||
case setReplyText(String)
|
||||
|
||||
case showAttachmentPicker(Bool)
|
||||
case sendAttachment([ShareItem])
|
||||
case sendAttachmentDone
|
||||
case sendAttachmentError(reason: String)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
enum SharingAction: Codable {
|
||||
case showSharing(Bool)
|
||||
|
||||
// case sendAttachment([ShareItem])
|
||||
// case sendAttachmentDone
|
||||
// case sendAttachmentError(reason: String)
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,9 @@ extension AppState {
|
|||
|
||||
case .messagesAction:
|
||||
break // messages actions are processed by MessagesMiddleware, and other components
|
||||
|
||||
case .sharingAction(let action):
|
||||
SharingState.reducer(state: &state.sharingState, action: action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,6 @@ extension ConversationState {
|
|||
state.replyText = text.makeReply
|
||||
}
|
||||
|
||||
case .showAttachmentPicker(let flag):
|
||||
state.attachmentPickerVisible = flag
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
11
ConversationsClassic/AppCore/Reducers/SharingReducer.swift
Normal file
11
ConversationsClassic/AppCore/Reducers/SharingReducer.swift
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import Foundation
|
||||
|
||||
final class GalleryService {
|
||||
var dumb = false
|
||||
}
|
|
@ -19,6 +19,7 @@ struct AppState: Stateable {
|
|||
var rostersState: RostersState
|
||||
var chatsState: ChatsState
|
||||
var conversationsState: ConversationState
|
||||
var sharingState: SharingState
|
||||
}
|
||||
|
||||
// MARK: Init
|
||||
|
@ -33,5 +34,6 @@ extension AppState {
|
|||
rostersState = RostersState()
|
||||
chatsState = ChatsState()
|
||||
conversationsState = ConversationState()
|
||||
sharingState = SharingState()
|
||||
}
|
||||
}
|
||||
|
|
10
ConversationsClassic/AppCore/State/SharingState.swift
Normal file
10
ConversationsClassic/AppCore/State/SharingState.swift
Normal file
|
@ -0,0 +1,10 @@
|
|||
struct SharingState: Stateable {
|
||||
var sharingShown: Bool
|
||||
}
|
||||
|
||||
// MARK: Init
|
||||
extension SharingState {
|
||||
init() {
|
||||
sharingShown = false
|
||||
}
|
||||
}
|
|
@ -14,7 +14,8 @@ let store = AppStore(
|
|||
RostersMiddleware.shared.middleware,
|
||||
ChatsMiddleware.shared.middleware,
|
||||
ConversationMiddleware.shared.middleware,
|
||||
MessagesMiddleware.shared.middleware
|
||||
MessagesMiddleware.shared.middleware,
|
||||
SharingMiddleware.shared.middleware
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -40,14 +40,15 @@ struct AttachmentContactsPickerView: View {
|
|||
.clipped()
|
||||
.onTapGesture {
|
||||
if let selectedContact = selectedContact {
|
||||
store.dispatch(.conversationAction(.sendAttachment([.init(
|
||||
id: UUID().uuidString,
|
||||
type: .contact,
|
||||
data: Data(),
|
||||
thumbnail: Data(),
|
||||
string: selectedContact.contactBareJid
|
||||
)])))
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
// TODO: fix it
|
||||
// store.dispatch(.conversationAction(.sendAttachment([.init(
|
||||
// id: UUID().uuidString,
|
||||
// type: .contact,
|
||||
// data: Data(),
|
||||
// thumbnail: Data(),
|
||||
// string: selectedContact.contactBareJid
|
||||
// )])))
|
||||
store.dispatch(.sharingAction(.showSharing(false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,12 @@ struct AttachmentFilesPickerView: View {
|
|||
string: ""
|
||||
)
|
||||
}
|
||||
store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
// TODO: Send files
|
||||
// store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
|
||||
store.dispatch(.sharingAction(.showSharing(false)))
|
||||
},
|
||||
cancel: {
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
store.dispatch(.sharingAction(.showSharing(false)))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ struct AttachmentHeader: View {
|
|||
Image(systemName: "xmark")
|
||||
.foregroundColor(Color.Material.Elements.active)
|
||||
.tappablePadding(.symmetric(12)) {
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
store.dispatch(.sharingAction(.showSharing(false)))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
|
|
|
@ -62,14 +62,15 @@ struct AttachmentLocationPickerView: View {
|
|||
}
|
||||
.clipped()
|
||||
.onTapGesture {
|
||||
store.dispatch(.conversationAction(.sendAttachment([.init(
|
||||
id: UUID().uuidString,
|
||||
type: .location,
|
||||
data: Data(),
|
||||
thumbnail: Data(),
|
||||
string: "\(region.center.latitude),\(region.center.longitude)"
|
||||
)])))
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
// TODO: Send location
|
||||
// store.dispatch(.conversationAction(.sendAttachment([.init(
|
||||
// id: UUID().uuidString,
|
||||
// type: .location,
|
||||
// data: Data(),
|
||||
// thumbnail: Data(),
|
||||
// string: "\(region.center.latitude),\(region.center.longitude)"
|
||||
// )])))
|
||||
store.dispatch(.sharingAction(.showSharing(false)))
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
|
|
|
@ -131,7 +131,7 @@ struct AttachmentMediaPickerView: View {
|
|||
.onTapGesture {
|
||||
let ids = selectedMedia.map { $0.id }
|
||||
sendGalleryMedia(ids: ids)
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
store.dispatch(.sharingAction(.showSharing(false)))
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
|
|
|
@ -49,7 +49,7 @@ struct ConversationTextInput: View {
|
|||
.foregroundColor(.Material.Elements.active)
|
||||
.padding(.leading, 8)
|
||||
.tappablePadding(.symmetric(8)) {
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(true)))
|
||||
store.dispatch(.sharingAction(.showSharing(true)))
|
||||
}
|
||||
TextField(L10n.Chat.textfieldPrompt, text: $messageStr)
|
||||
.font(.body1)
|
||||
|
|
Loading…
Reference in a new issue