-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOB-2153 - Purchase domains Search filters (#628)
* MOB-2152 - Implemented tracking of recent search history * Created filters view * Prepare to show filters view * Added filtre button. Fixed initial filters applied.
- Loading branch information
1 parent
b7022de
commit 1c3c2b1
Showing
9 changed files
with
279 additions
and
28 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
36 changes: 36 additions & 0 deletions
36
unstoppable-ios-app/domains-manager-ios/Entities/TLDCategory.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,36 @@ | ||
// | ||
// TLDCategory.swift | ||
// domains-manager-ios | ||
// | ||
// Created by Oleg Kuplin on 12.08.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum TLDCategory { | ||
case uns | ||
case ens | ||
case dns | ||
|
||
var icon: Image { | ||
switch self { | ||
case .uns: | ||
return .unsTLDLogo | ||
case .ens: | ||
return .ensTLDLogo | ||
case .dns: | ||
return .dnsTLDLogo | ||
} | ||
} | ||
|
||
static func categoryFor(tld: String) -> TLDCategory { | ||
switch tld { | ||
case Constants.ensDomainTLD: | ||
return .ens | ||
case _ where Constants.dnsDomainTLDs.contains(tld): | ||
return .dns | ||
default: | ||
return .uns | ||
} | ||
} | ||
} |
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
139 changes: 139 additions & 0 deletions
139
...domains-manager-ios/Modules/PurchaseDomains/Search/PurchaseDomainsSearchFiltersView.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,139 @@ | ||
// | ||
// PurchaseDomainsSearchFiltersView.swift | ||
// domains-manager-ios | ||
// | ||
// Created by Oleg Kuplin on 12.08.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PurchaseDomainsSearchFiltersView: View { | ||
|
||
@Environment(\.dismiss) var dismiss | ||
|
||
let appliedFilters: Set<String> | ||
let callback: (Set<String>)->() | ||
private let tlds: [String] | ||
@State private var currentFilters: Set<String> = [] | ||
|
||
var body: some View { | ||
NavigationStack { | ||
contentView() | ||
.navigationTitle(String.Constants.filter.localized()) | ||
.navigationBarTitleDisplayMode(.inline) | ||
.toolbar { | ||
ToolbarItem(placement: .topBarLeading) { | ||
CloseButtonView { | ||
dismiss() | ||
} | ||
} | ||
|
||
ToolbarItem(placement: .topBarTrailing) { | ||
resetButton() | ||
} | ||
} | ||
} | ||
} | ||
|
||
init(appliedFilters: Set<String>, | ||
callback: @escaping (Set<String>) -> Void) { | ||
self.appliedFilters = appliedFilters | ||
self.callback = callback | ||
self.tlds = User.instance.getAppVersionInfo().tlds | ||
self._currentFilters = State(wrappedValue: appliedFilters) | ||
} | ||
|
||
} | ||
|
||
// MARK: - Private methods | ||
private extension PurchaseDomainsSearchFiltersView { | ||
@ViewBuilder | ||
func contentView() -> some View { | ||
VStack { | ||
ScrollView { | ||
filtersSection() | ||
} | ||
doneButton() | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func filtersSection() -> some View { | ||
VStack(alignment: .leading, | ||
spacing: 16) { | ||
Text(String.Constants.endings.localized()) | ||
.textAttributes(color: .foregroundDefault, | ||
fontSize: 16, | ||
fontWeight: .medium) | ||
.frame(height: 24) | ||
filtersListView() | ||
} | ||
.padding() | ||
} | ||
|
||
@ViewBuilder | ||
func filtersListView() -> some View { | ||
UDCollectionSectionBackgroundView(withShadow: true) { | ||
LazyVStack(alignment: .leading, | ||
spacing: 24) { | ||
ForEach(tlds, id: \.self) { tld in | ||
tldRowView(tld) | ||
} | ||
} | ||
.padding(16) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func tldRowView(_ tld: String) -> some View { | ||
HStack(spacing: 16) { | ||
TLDCategory.categoryFor(tld: tld) | ||
.icon | ||
.resizable() | ||
.squareFrame(24) | ||
.foregroundStyle(Color.foregroundSecondary) | ||
Text(tld) | ||
.textAttributes(color: .foregroundDefault, | ||
fontSize: 16, | ||
fontWeight: .medium) | ||
Spacer() | ||
|
||
UDCheckBoxView(isOn: Binding( | ||
get: { | ||
currentFilters.contains(tld) | ||
}, set: { isOn in | ||
if isOn { | ||
currentFilters.insert(tld) | ||
} else { | ||
currentFilters.remove(tld) | ||
} | ||
}) | ||
) | ||
} | ||
.frame(height: 40) | ||
} | ||
|
||
@ViewBuilder | ||
func doneButton() -> some View { | ||
UDButtonView(text: String.Constants.doneButtonTitle.localized(), | ||
style: .large(.raisedPrimary)) { | ||
dismiss() | ||
callback(currentFilters) | ||
} | ||
.padding(.horizontal, 16) | ||
} | ||
|
||
@ViewBuilder | ||
func resetButton() -> some View { | ||
UDButtonView(text: String.Constants.reset.localized(), | ||
style: .medium(.ghostPrimary)) { | ||
currentFilters = [] | ||
} | ||
.disabled(currentFilters.isEmpty) | ||
} | ||
} | ||
|
||
#Preview { | ||
PurchaseDomainsSearchFiltersView(appliedFilters: ["x", "crypto"], | ||
callback: { _ in }) | ||
} |
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
Oops, something went wrong.