-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements transfer file selector and closes #3
- Loading branch information
1 parent
80f2dc7
commit f664e31
Showing
5 changed files
with
175 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// FileSelectDialog.swift | ||
// Mission | ||
// | ||
// Created by Joe Diragi on 3/16/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct MultipleSelectionRow: View { | ||
var title: String | ||
@State var isSelected: Bool | ||
var action: () -> Void | ||
|
||
var body: some View { | ||
HStack { | ||
Toggle(self.title, isOn: self.$isSelected) | ||
.onChange(of: isSelected) { i in | ||
action() | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct FileSelectDialog: View { | ||
@ObservedObject var store: Store | ||
|
||
@State var files: [File] = [] | ||
@State var selections: [Int] = [] | ||
|
||
init(store: Store) { | ||
self.store = store | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
HStack { | ||
Text("Select Files") | ||
.font(.headline) | ||
.padding(.leading, 20) | ||
.padding(.bottom, 10) | ||
.padding(.top, 20) | ||
Button(action: { | ||
store.isShowingTransferFiles.toggle() | ||
}, label: { | ||
Image(systemName: "xmark.circle.fill") | ||
.padding(.top, 20) | ||
.padding(.bottom, 10) | ||
.padding(.leading, 20) | ||
.frame(alignment: .trailing) | ||
}).buttonStyle(BorderlessButtonStyle()) | ||
} | ||
List { | ||
ForEach(Array(store.addTransferFilesList.enumerated()), id: \.offset) { (i,f) in | ||
MultipleSelectionRow(title: f.name, isSelected: self.selections.contains(i)) { | ||
if self.selections.contains(i) { | ||
self.selections.removeAll(where: { $0 == i }) | ||
} else { | ||
self.selections.append(i) | ||
} | ||
} | ||
} | ||
} | ||
Button("Submit") { | ||
var dontDownload: [Int] = [] | ||
store.addTransferFilesList.enumerated().forEach { (i,f) in | ||
if (!self.selections.contains(i)) { | ||
dontDownload.append(i) | ||
} | ||
} | ||
print("Don't download: \(dontDownload)") | ||
setTransferFiles(transferId: store.transferToSetFiles, files: dontDownload, info: (config: store.server!.config, auth: store.server!.auth)) { i in | ||
store.isShowingTransferFiles.toggle() | ||
} | ||
}.padding() | ||
} | ||
} | ||
} |