-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clean up
import
related views (#27)
* Cleanup import views * updated
- Loading branch information
1 parent
bf86938
commit 27cd82e
Showing
6 changed files
with
108 additions
and
103 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
73 changes: 73 additions & 0 deletions
73
Chronos/App/Tabs/Settings/Import/ImportSourceDetailView.swift
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,73 @@ | ||
import Factory | ||
import SwiftUI | ||
|
||
struct ImportSourceDetailView: View { | ||
@State var importSource: ImportSource | ||
|
||
@State private var showFileImporter = false | ||
@State private var showImportConfirmation = false | ||
@State private var tokens: [Token]? | ||
|
||
@EnvironmentObject private var importNav: ExportNavigation | ||
|
||
private let importService = Container.shared.importService() | ||
|
||
var body: some View { | ||
VStack { | ||
Image(systemName: "square.and.arrow.down") | ||
.font(.system(size: 44)) | ||
.padding(.bottom, 16) | ||
|
||
Text(importSource.desc) | ||
.multilineTextAlignment(.center) | ||
|
||
Spacer() | ||
|
||
Button(action: { showFileImporter = true }) { | ||
Text("Select file") | ||
.bold() | ||
.frame(maxWidth: .infinity) | ||
.frame(height: 32) | ||
} | ||
.buttonStyle(.bordered) | ||
.fileImporter( | ||
isPresented: $showFileImporter, | ||
allowedContentTypes: [.json], | ||
allowsMultipleSelection: false, | ||
onCompletion: handleFileImport | ||
) | ||
.sheet(isPresented: $showImportConfirmation) { | ||
NavigationStack { | ||
if let tokens = tokens { | ||
ImportConfirmationView(tokens: tokens) | ||
} else { | ||
ImportFailureView() | ||
} | ||
} | ||
} | ||
|
||
Button(action: { importNav.showSheet = false }) { | ||
Text("Cancel") | ||
.bold() | ||
.frame(maxWidth: .infinity) | ||
.frame(height: 32) | ||
} | ||
.buttonStyle(.borderless) | ||
} | ||
.padding(.horizontal, 24) | ||
.padding(.bottom, 32) | ||
.navigationTitle("Import from \(importSource.name)") | ||
} | ||
|
||
private func handleFileImport(result: Result<[URL], Error>) { | ||
switch result { | ||
case let .success(fileUrls): | ||
if let fileUrl = fileUrls.first { | ||
tokens = importService.importTokens(importSource: importSource, url: fileUrl) | ||
showImportConfirmation = true | ||
} | ||
case let .failure(error): | ||
print(error) | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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