Skip to content

Commit

Permalink
Minor updates to file Importer
Browse files Browse the repository at this point in the history
  • Loading branch information
afterxleep committed May 6, 2023
1 parent 0dd40be commit 884ab53
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Bouncer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@
buildSettings = {
CODE_SIGN_ENTITLEMENTS = SMSFilter/SMSFilter.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 721;
CURRENT_PROJECT_VERSION = 734;
DEVELOPMENT_TEAM = JM9222EF99;
INFOPLIST_FILE = SMSFilter/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -720,7 +720,7 @@
CODE_SIGN_ENTITLEMENTS = SMSFilter/SMSFilter.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 721;
CURRENT_PROJECT_VERSION = 734;
DEVELOPMENT_TEAM = JM9222EF99;
INFOPLIST_FILE = SMSFilter/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -866,7 +866,7 @@
CODE_SIGN_ENTITLEMENTS = Bouncer/Bouncer.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 721;
CURRENT_PROJECT_VERSION = 734;
DEVELOPMENT_ASSET_PATHS = "\"Bouncer/Preview Content\"";
DEVELOPMENT_TEAM = JM9222EF99;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -897,7 +897,7 @@
CODE_SIGN_ENTITLEMENTS = Bouncer/Bouncer.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 721;
CURRENT_PROJECT_VERSION = 734;
DEVELOPMENT_ASSET_PATHS = "\"Bouncer/Preview Content\"";
DEVELOPMENT_TEAM = JM9222EF99;
ENABLE_PREVIEWS = YES;
Expand Down
44 changes: 41 additions & 3 deletions Bouncer/Views/FilterList/FilterListContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,57 @@

import SwiftUI

enum FilterListError: Identifiable {
case emptyImportFileError
case decodingError(String)
case unknownError(String)

var id: String {
switch self {
case .emptyImportFileError: return "EMPTY_IMPORT_FILE"
case .decodingError(let str): return str
case .unknownError(let str): return str
}
}

var textView: Text {
switch self {
case .emptyImportFileError: return Text("EMPTY_IMPORT_FILE")
case .decodingError(let str): return Text("IMPORT_ERROR \(str)")
case .unknownError(let str): return Text("IMPORT_ERROR \(str)")
}
}
}

struct FilterListContainerView: View {
@EnvironmentObject var store: AppStore

@State var shouldShowImportList: Bool = false
@State var shouldDisplayErrorMessage: Bool = false
@State var errorAlert: FilterListError? = nil
var errorMessage: String = ""

var body: some View {
FilterListView(filters: store.state.filters.filters,
onDelete: deleteFilter,
onImport: importFilters,
importFiltersFromURL: importFiltersFromURL,
openSettings: {},
shouldShowImportList: $shouldShowImportList)

showError: showError(error:),
shouldShowImportList: $shouldShowImportList
)
// Display Filter import dialog when needed
.onChange(of: store.state.filters.filterImportInProgress, perform: { status in
shouldShowImportList = status
// Add a little delay to allow the File Selection view to dismiss
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
shouldShowImportList = status // Delay setting isPresented to false
}
})

// Import Error Display
.alert(item: $errorAlert) { error in
Alert(title: Text("ERROR"), message: error.textView)
}
}
}

Expand Down Expand Up @@ -49,4 +83,8 @@ extension FilterListContainerView {
store.dispatch(.filter(action: action))
}

func showError(error: FilterListError) {
errorAlert = error
}

}
35 changes: 4 additions & 31 deletions Bouncer/Views/FilterList/FilterListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,14 @@ struct FilterListView: View {
let onImport: ([Filter]) -> Void
let importFiltersFromURL: (URL) -> Void
let openSettings: () -> Void
let showError: (FilterListError) -> Void
@Binding var shouldShowImportList: Bool

@State var showingSettings = false
@State var showingFilterDetail = false
@State var showingInApp = false
@State var showingFileImporter = false
@State var importError: ImportError? = nil

enum ImportError: Identifiable {
case emptyImportFileError
case decodingError(String)
case unknownError(String)

var id: String {
switch self {
case .emptyImportFileError: return "EMPTY_IMPORT_FILE"
case .decodingError(let str): return str
case .unknownError(let str): return str
}
}

var textView: Text {
switch self {
case .emptyImportFileError: return Text("EMPTY_IMPORT_FILE")
case .decodingError(let str): return Text("IMPORT_ERROR \(str)")
case .unknownError(let str): return Text("IMPORT_ERROR \(str)")
}
}
}

var body: some View {
ZStack {
Expand All @@ -62,15 +41,14 @@ struct FilterListView: View {
}
}



struct FilterListView_Previews: PreviewProvider {
static var previews: some View {
FilterListView(filters: [],
onDelete: {_ in },
onImport: {_ in },
importFiltersFromURL: { _ in },
openSettings: {},
showError: { _ in },
shouldShowImportList: .constant(false)
)
}
Expand Down Expand Up @@ -117,20 +95,15 @@ extension FilterListView {
importFiltersFromURL(url)
}
case .failure(let error):
os_log(.error, log: .errorLog,
"Failed to load import file: %{public}@",
error.localizedDescription)
self.importError = .unknownError(error.localizedDescription)
showError(.unknownError(error.localizedDescription))
}
}
.sheet(isPresented: $shouldShowImportList) {
ImportFilterListContainerView()
}.sheet(isPresented: $showingSettings) {
TutorialContainerView()
}
.alert(item: $importError) { error in
Alert(title: Text("ERROR"), message: error.textView)
}


}

Expand Down

0 comments on commit 884ab53

Please sign in to comment.