Skip to content

Commit 43bb66d

Browse files
feat: Replace element save buttons with SaveButton and enforce permissions (#470)
1 parent 685e65c commit 43bb66d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

swift-paperless/Views/DocumentTypeEditView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct DocumentTypeEditView<Element>: View where Element: DocumentTypeProtocol {
4242
}
4343
.toolbar {
4444
ToolbarItem(placement: .navigationBarTrailing) {
45-
Button(saveLabel) {
45+
SaveButton(saveLabel) {
4646
do {
4747
try onSave?(element)
4848
} catch {

swift-paperless/Views/Settings/ManageView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct ManageView<Manager>: View where Manager: ManagerProtocol {
9393

9494
var body: some View {
9595
Manager.EditView(element: element, onSave: onSaveInternal)
96+
.disabled(!model.permissions.test(.change))
9697
}
9798
}
9899

@@ -194,6 +195,9 @@ struct ManageView<Manager>: View where Manager: ManagerProtocol {
194195
NavigationLink {
195196
Edit(model: model, element: element) { element in
196197
guard model.permissions.test(.change) else {
198+
Logger.shared.info(
199+
"Silently not saving from edit view: this likely indicates a button is active that shouldn't be"
200+
)
197201
return
198202
}
199203

swift-paperless/Views/StoragePathEditView.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct StoragePathEditView<Element>: View where Element: StoragePathProtocol {
5050

5151
.toolbar {
5252
ToolbarItem(placement: .navigationBarTrailing) {
53-
Button(saveLabel) {
53+
54+
SaveButton(saveLabel) {
5455
do {
5556
try onSave?(storagePath)
5657
} catch {
@@ -71,15 +72,10 @@ extension StoragePathEditView where Element == ProtoStoragePath {
7172
}
7273
}
7374

74-
struct EditStoragePath_Previews: PreviewProvider {
75-
struct Container: View {
76-
@State var path = ProtoStoragePath()
77-
var body: some View {
78-
StoragePathEditView(element: path, onSave: { _ in })
79-
}
80-
}
81-
82-
static var previews: some View {
83-
Container()
75+
#Preview {
76+
NavigationStack {
77+
StoragePathEditView<ProtoStoragePath>(onSave: { _ in })
78+
.navigationBarTitleDisplayMode(.inline)
79+
.navigationTitle(Text(.localizable(.storagePathCreateTitle)))
8480
}
8581
}

0 commit comments

Comments
 (0)