Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Dec 17, 2023
1 parent 5d5451b commit 4e7fb31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 5 additions & 3 deletions DuckDuckGo/DataImport/Model/DataImportViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct DataImportViewModel {
@UserDefaultsWrapper(key: .homePageContinueSetUpImport, defaultValue: nil)
var successfulImportHappened: Bool?

let availableImportSources: [DataImport.Source]
/// Browser to import data from
let importSource: Source
/// BrowserProfileList loader (factory method) - used
Expand Down Expand Up @@ -128,7 +129,7 @@ struct DataImportViewModel {

init(importSource: Source? = nil,
screen: Screen? = nil,
availableImportSources: @autoclosure () -> Set<Source> = Set(ThirdPartyBrowser.installedBrowsers.map(\.importSource)),
availableImportSources: [DataImport.Source] = ThirdPartyBrowser.installedBrowsers.map(\.importSource),
preferredImportSources: [Source] = [.chrome, .firefox, .safari],
summary: [DataTypeImportResult] = [],
loadProfiles: @escaping (ThirdPartyBrowser) -> BrowserProfileList = { $0.browserProfiles() },
Expand All @@ -137,7 +138,7 @@ struct DataImportViewModel {
openPanelCallback: @escaping @MainActor (DataType) -> URL? = Self.openPanelCallback,
reportSenderFactory: @escaping ReportSenderFactory = { FeedbackSender().sendDataImportReport }) {

lazy var availableImportSources = availableImportSources()
self.availableImportSources = availableImportSources
let importSource = importSource ?? preferredImportSources.first(where: { availableImportSources.contains($0) }) ?? .csv

self.importSource = importSource
Expand Down Expand Up @@ -459,7 +460,7 @@ extension DataImportViewModel {
for dataType in (currentDataType.map { DataType.dataTypes(after: $0) } ?? DataType.allCases[0...]) where selectedDataTypes.contains(dataType) {
// if some of selected data types failed to import or not imported yet
switch summary.last(where: { $0.dataType == dataType })?.result {
case .success(let summary) where summary.successful == 0 && summary.duplicate == 0 && summary.failed == 0:
case .success(let summary) where summary.isEmpty:
return .fileImport(dataType: dataType)
case .failure(let error) where error.errorType == .noData:
return .fileImport(dataType: dataType)
Expand Down Expand Up @@ -680,6 +681,7 @@ extension DataImportViewModel {
}
}

log("dismiss")
dismiss()
if case .xcPreviews = NSApp.runType {
self.update(with: importSource) // reset
Expand Down
7 changes: 4 additions & 3 deletions DuckDuckGo/DataImport/View/DataImportSourcePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ struct DataImportSourcePicker: View {
viewModel.importSources
}

init(selectedSource: DataImport.Source,
init(importSources: [DataImport.Source],
selectedSource: DataImport.Source,
onSelectedSourceChanged: @escaping (DataImport.Source) -> Void) {
self.viewModel = DataImportSourceViewModel(selectedSource: selectedSource)
self.viewModel = DataImportSourceViewModel(importSources: importSources, selectedSource: selectedSource)
self.onSelectedSourceChanged = onSelectedSourceChanged
}

Expand Down Expand Up @@ -61,7 +62,7 @@ struct DataImportSourcePicker: View {
}

#Preview {
DataImportSourcePicker(selectedSource: .csv) {
DataImportSourcePicker(importSources: DataImport.Source.allCases, selectedSource: .csv) {
print("selection:", $0)
}
.padding()
Expand Down
13 changes: 7 additions & 6 deletions DuckDuckGo/DataImport/View/DataImportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,16 @@ struct DataImportView: View {
HStack(spacing: 8) {
Spacer()

ForEach(model.buttons, id: \.self) { button in
ForEach(model.buttons.indices, id: \.self) { idx in
Button {
model.performAction(for: button, dismiss: dismiss.callAsFunction)
model.performAction(for: model.buttons[idx],
dismiss: dismiss.callAsFunction)
} label: {
Text(button.title(dataType: model.screen.fileImportDataType))
Text(model.buttons[idx].title(dataType: model.screen.fileImportDataType))
.frame(minWidth: 80 - 16 - 1)
}
.keyboardShortcut(button.shortcut)
.disabled(button.isDisabled)
.keyboardShortcut(model.buttons[idx].shortcut)
.disabled(model.buttons[idx].isDisabled)
}
}
}
Expand Down Expand Up @@ -500,7 +501,7 @@ extension DataImportViewModel.ButtonType {
}
}

let viewModel = DataImportViewModel(importSource: .bookmarksHTML) { browser in
let viewModel = DataImportViewModel(importSource: .bookmarksHTML, availableImportSources: DataImport.Source.allCases) { browser in
guard case .chrome = browser else {
print("empty profiles")
return .init(browser: browser, profiles: [])
Expand Down

0 comments on commit 4e7fb31

Please sign in to comment.