This commit is contained in:
fmodf 2024-07-10 16:48:18 +02:00
parent e2363f9f9f
commit 485071162c
6 changed files with 32 additions and 42 deletions

View file

@ -1,7 +1,23 @@
enum SharingAction: Codable {
import Foundation
enum SharingAction: Stateable {
case showSharing(Bool)
case shareLocation(lat: Double, lon: Double)
case shareContact(jid: String)
case shareDocuments([Data])
// case sendAttachment([ShareItem])
// case sendAttachmentDone
// case sendAttachmentError(reason: String)
}
// struct ShareItem: Stateable {
// let id: String
// let type: AttachmentType
// let data: Data
// let thumbnail: Data
// let string: String
// }

View file

@ -1,10 +0,0 @@
import Foundation
import SwiftUI
struct ShareItem: Stateable {
let id: String
let type: AttachmentType
let data: Data
let thumbnail: Data
let string: String
}

View file

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

View file

@ -6,19 +6,9 @@ struct AttachmentFilesPickerView: View {
var body: some View {
DocumentPicker(
completion: { arr in
let sharedFiles = arr.map {
ShareItem(
id: UUID().uuidString,
type: .file,
data: $0,
thumbnail: Data(),
string: ""
)
}
// TODO: Send files
// store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
completion: { dataArray in
store.dispatch(.sharingAction(.showSharing(false)))
store.dispatch(.sharingAction(.shareDocuments(dataArray)))
},
cancel: {
store.dispatch(.sharingAction(.showSharing(false)))
@ -52,9 +42,17 @@ struct DocumentPicker: UIViewControllerRepresentable {
self.parent = parent
}
func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) {
// TODO: Send documents
// Handle the selected files
func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt: [URL]) {
var dataArray = [Data]()
for url in didPickDocumentsAt {
do {
let data = try Data(contentsOf: url)
dataArray.append(data)
} catch {
print("Unable to load data from \(url): \(error)")
}
}
parent.completion(dataArray)
}
func documentPickerWasCancelled(_: UIDocumentPickerViewController) {

View file

@ -62,14 +62,7 @@ struct AttachmentLocationPickerView: View {
}
.clipped()
.onTapGesture {
// 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(.shareLocation(lat: region.center.latitude, lon: region.center.longitude)))
store.dispatch(.sharingAction(.showSharing(false)))
}
}