wip
This commit is contained in:
parent
e2363f9f9f
commit
485071162c
|
@ -1,7 +1,23 @@
|
||||||
enum SharingAction: Codable {
|
import Foundation
|
||||||
|
|
||||||
|
enum SharingAction: Stateable {
|
||||||
case showSharing(Bool)
|
case showSharing(Bool)
|
||||||
|
|
||||||
|
case shareLocation(lat: Double, lon: Double)
|
||||||
|
|
||||||
|
case shareContact(jid: String)
|
||||||
|
|
||||||
|
case shareDocuments([Data])
|
||||||
|
|
||||||
// case sendAttachment([ShareItem])
|
// case sendAttachment([ShareItem])
|
||||||
// case sendAttachmentDone
|
// case sendAttachmentDone
|
||||||
// case sendAttachmentError(reason: String)
|
// case sendAttachmentError(reason: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct ShareItem: Stateable {
|
||||||
|
// let id: String
|
||||||
|
// let type: AttachmentType
|
||||||
|
// let data: Data
|
||||||
|
// let thumbnail: Data
|
||||||
|
// let string: String
|
||||||
|
// }
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -40,14 +40,7 @@ struct AttachmentContactsPickerView: View {
|
||||||
.clipped()
|
.clipped()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
if let selectedContact = selectedContact {
|
if let selectedContact = selectedContact {
|
||||||
// TODO: fix it
|
store.dispatch(.sharingAction(.shareContact(jid: selectedContact.contactBareJid)))
|
||||||
// store.dispatch(.conversationAction(.sendAttachment([.init(
|
|
||||||
// id: UUID().uuidString,
|
|
||||||
// type: .contact,
|
|
||||||
// data: Data(),
|
|
||||||
// thumbnail: Data(),
|
|
||||||
// string: selectedContact.contactBareJid
|
|
||||||
// )])))
|
|
||||||
store.dispatch(.sharingAction(.showSharing(false)))
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,9 @@ struct AttachmentFilesPickerView: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
DocumentPicker(
|
DocumentPicker(
|
||||||
completion: { arr in
|
completion: { dataArray in
|
||||||
let sharedFiles = arr.map {
|
|
||||||
ShareItem(
|
|
||||||
id: UUID().uuidString,
|
|
||||||
type: .file,
|
|
||||||
data: $0,
|
|
||||||
thumbnail: Data(),
|
|
||||||
string: ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// TODO: Send files
|
|
||||||
// store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
|
|
||||||
store.dispatch(.sharingAction(.showSharing(false)))
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
|
store.dispatch(.sharingAction(.shareDocuments(dataArray)))
|
||||||
},
|
},
|
||||||
cancel: {
|
cancel: {
|
||||||
store.dispatch(.sharingAction(.showSharing(false)))
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
|
@ -52,9 +42,17 @@ struct DocumentPicker: UIViewControllerRepresentable {
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
}
|
}
|
||||||
|
|
||||||
func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) {
|
func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt: [URL]) {
|
||||||
// TODO: Send documents
|
var dataArray = [Data]()
|
||||||
// Handle the selected files
|
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) {
|
func documentPickerWasCancelled(_: UIDocumentPickerViewController) {
|
||||||
|
|
|
@ -62,14 +62,7 @@ struct AttachmentLocationPickerView: View {
|
||||||
}
|
}
|
||||||
.clipped()
|
.clipped()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
// TODO: Send location
|
store.dispatch(.sharingAction(.shareLocation(lat: region.center.latitude, lon: region.center.longitude)))
|
||||||
// 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)))
|
store.dispatch(.sharingAction(.showSharing(false)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue