Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: organization error handling #21

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sources/Screens/Browser/BrowserList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct BrowserList: View, LoadStateProvider, ViewDataProvider, TimerLifecycle, T
@ObservedObject private var workspaceStore: WorkspaceStore
@StateObject private var browserStore = BrowserStore()
@State private var tappedItem: VOFile.Entity?
@State private var searchText = ""
private let folderID: String
private let confirmLabelText: String?
private let onCompletion: ((String) -> Void)?
Expand Down Expand Up @@ -67,8 +68,8 @@ struct BrowserList: View, LoadStateProvider, ViewDataProvider, TimerLifecycle, T
}
}
.listStyle(.inset)
.searchable(text: $browserStore.searchText)
.onChange(of: browserStore.searchText) {
.searchable(text: $searchText)
.onChange(of: searchText) {
browserStore.searchPublisher.send($1)
}
.navigationDestination(item: $tappedItem) {
Expand Down
1 change: 0 additions & 1 deletion Sources/Screens/Browser/BrowserStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class BrowserStore: ObservableObject {
@Published var folderIsLoading: Bool = false
@Published var folderError: String?
@Published var query: VOFile.Query?
@Published var searchText = ""
private var list: VOFile.List?
private var cancellables = Set<AnyCancellable>()
private var timer: Timer?
Expand Down
4 changes: 3 additions & 1 deletion Sources/Screens/File/FileOverview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ struct FileOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycle,
}
}
.searchable(text: $searchText)
.onChange(of: fileStore.searchText) { fileStore.searchPublisher.send($1) }
.onChange(of: searchText) {
fileStore.searchPublisher.send($1)
}
.refreshable { fileStore.fetchNextPage(replace: true) }
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/Screens/File/FileStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class FileStore: ObservableObject {
@Published var insightsIsPresented = false
@Published var infoIsPresented = false
@Published var viewMode: ViewMode = .grid
@Published var searchText = ""
private var list: VOFile.List?
private var cancellables = Set<AnyCancellable>()
private var timer: Timer?
Expand Down
4 changes: 2 additions & 2 deletions Sources/Screens/Group/GroupList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct GroupList: View, ViewDataProvider, LoadStateProvider, TimerLifecycle, Tok
}
}
}
.searchable(text: $groupStore.searchText)
.onChange(of: groupStore.searchText) {
.searchable(text: $searchText)
.onChange(of: searchText) {
groupStore.searchPublisher.send($1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Screens/Group/GroupMemberList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ struct GroupMemberList: View, ViewDataProvider, LoadStateProvider, TimerLifecycl
}
}
}
.searchable(text: $groupStore.searchText)
.onChange(of: userStore.searchText) {
.searchable(text: $searchText)
.onChange(of: searchText) {
userStore.searchPublisher.send($1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Screens/Group/GroupSelector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ struct GroupSelector: View, ViewDataProvider, LoadStateProvider, TimerLifecycle,
}
}
}
.searchable(text: $groupStore.searchText)
.onChange(of: groupStore.searchText) {
.searchable(text: $searchText)
.onChange(of: searchText) {
groupStore.searchPublisher.send($1)
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/Screens/Group/GroupStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class GroupStore: ObservableObject {
@Published var entitiesError: String?
@Published var current: VOGroup.Entity?
@Published var query: String?
@Published var searchText = ""
private var list: VOGroup.List?
private var cancellables = Set<AnyCancellable>()
private var timer: Timer?
Expand Down
3 changes: 1 addition & 2 deletions Sources/Screens/Insights/InsightsEntityList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct InsightsEntityList: View {
}
}
.searchable(text: $searchText)
.onChange(of: insightsStore.searchText) {
.onChange(of: searchText) {
insightsStore.searchPublisher.send($1)
}
}
Expand Down Expand Up @@ -86,7 +86,6 @@ struct InsightsEntityList: View {
insightsStore.clear()
insightsStore.fetchEntityNextPage()
}
.sync($insightsStore.searchText, with: $searchText)
.sync($insightsStore.showError, with: $showError)
}

Expand Down
1 change: 0 additions & 1 deletion Sources/Screens/Insights/InsightsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class InsightsStore: ObservableObject {
@Published var showError = false
@Published var errorTitle: String?
@Published var errorMessage: String?
@Published var searchText = ""
private var list: VOInsights.EntityList?
private var cancellables: Set<AnyCancellable> = []
private var timer: Timer?
Expand Down
19 changes: 11 additions & 8 deletions Sources/Screens/Organization/OrganizationCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
import SwiftUI
import VoltaserveCore

struct OrganizationCreate: View {
struct OrganizationCreate: View, FormValidatable, ErrorPresentable {
@ObservedObject private var organizationStore: OrganizationStore
@Environment(\.dismiss) private var dismiss
@State private var name = ""
@State private var isProcessing = false
@State private var showError = false
@State private var errorTitle: String?
@State private var errorMessage: String?
private let onCompletion: ((VOOrganization.Entity) -> Void)?

init(organizationStore: OrganizationStore, onCompletion: ((VOOrganization.Entity) -> Void)? = nil) {
Expand Down Expand Up @@ -51,7 +48,7 @@ struct OrganizationCreate: View {
}
}
}
.voErrorAlert(isPresented: $showError, title: errorTitle, message: errorMessage)
.voErrorSheet(isPresented: $errorIsPresented, message: errorMessage)
}
}

Expand All @@ -72,15 +69,21 @@ struct OrganizationCreate: View {
onCompletion(organization)
}
} failure: { message in
errorTitle = "Error: Creating Organization"
errorMessage = message
showError = true
errorIsPresented = true
} anyways: {
isProcessing = false
}
}

private func isValid() -> Bool {
// MARK: - ErrorPresentable

@State var errorIsPresented: Bool = false
@State var errorMessage: String?

// MARK: - FormValidatable

func isValid() -> Bool {
!normalizedName.isEmpty
}
}
21 changes: 11 additions & 10 deletions Sources/Screens/Organization/OrganizationEditName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
import SwiftUI
import VoltaserveCore

struct OrganizationEditName: View {
struct OrganizationEditName: View, FormValidatable, ErrorPresentable {
@ObservedObject private var organizationStore: OrganizationStore
@Environment(\.dismiss) private var dismiss
@State private var value = ""
@State private var isSaving = false
@State private var showError = false
@State private var errorTitle: String?
@State private var errorMessage: String?
private let onCompletion: ((VOOrganization.Entity) -> Void)?

init(organizationStore: OrganizationStore, onCompletion: ((VOOrganization.Entity) -> Void)? = nil) {
Expand Down Expand Up @@ -46,7 +43,7 @@ struct OrganizationEditName: View {
}
}
}
.voErrorAlert(isPresented: $showError, title: errorTitle, message: errorMessage)
.voErrorSheet(isPresented: $errorIsPresented, message: errorMessage)
.onAppear {
value = current.name
}
Expand All @@ -55,8 +52,6 @@ struct OrganizationEditName: View {
value = newCurrent.name
}
}
} else {
ProgressView()
}
}

Expand All @@ -78,15 +73,21 @@ struct OrganizationEditName: View {
onCompletion(updatedOrganization)
}
} failure: { message in
errorTitle = "Error: Saving Name"
errorMessage = message
showError = true
errorIsPresented = true
} anyways: {
isSaving = false
}
}

private func isValid() -> Bool {
// MARK: - ErrorPresentable

@State var errorIsPresented: Bool = false
@State var errorMessage: String?

// MARK: - FormValidatable

func isValid() -> Bool {
if let current = organizationStore.current {
return !nornalizedValue.isEmpty && nornalizedValue != current.name
}
Expand Down
Loading