-
-
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.
- Loading branch information
Showing
2 changed files
with
103 additions
and
7 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
85 changes: 85 additions & 0 deletions
85
apps/mobile/metro-now/metro-now/pages/search/search-page.view.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,85 @@ | ||
// metro-now | ||
// https://github.com/krystxf/metro-now | ||
|
||
import SwiftUI | ||
|
||
private enum Sorting: String, CaseIterable, Identifiable { | ||
case alphabetical, distance | ||
var id: Self { self } | ||
} | ||
|
||
private enum Filter: String, CaseIterable, Identifiable { | ||
case all, metro | ||
var id: Self { self } | ||
} | ||
|
||
struct SearchPageView: View { | ||
@State private var searchText = "" | ||
@StateObject private var viewModel = ClosestStopPageViewModel() | ||
|
||
@Environment(\.dismiss) private var dismiss | ||
@State private var sorting: Sorting = .distance | ||
@State private var filter: Filter = .metro | ||
|
||
var body: some View { | ||
NavigationStack { | ||
List { | ||
if filter == .metro { | ||
if let stops = viewModel.metroStops { | ||
ForEach(stops, id: \.id) { stop in | ||
Text(stop.name) | ||
} | ||
} | ||
} else { | ||
if let stops = viewModel.allStops { | ||
ForEach(stops, id: \.id) { stop in | ||
Text(stop.name) | ||
} | ||
} | ||
} | ||
} | ||
.searchable( | ||
text: $searchText, | ||
placement: .navigationBarDrawer(displayMode: .always) | ||
) | ||
.navigationTitle("Search") | ||
.toolbar { | ||
ToolbarItem(placement: .topBarLeading) { | ||
Menu { | ||
Button("Distance", action: {}) | ||
Button("A-Z", action: {}) | ||
} label: { | ||
Label("Sorting", systemImage: "arrow.up.arrow.down") | ||
} | ||
} | ||
ToolbarItem(placement: .principal) { | ||
Picker("Filter", selection: $filter) { | ||
Text("Metro").tag(Filter.metro) | ||
Text("All").tag(Filter.all) | ||
} | ||
.pickerStyle(.inline) | ||
.frame(maxWidth: 200) | ||
} | ||
ToolbarItem(placement: .topBarTrailing) { | ||
Button( | ||
action: { | ||
dismiss() | ||
} | ||
) { | ||
Label("Close", systemImage: "xmark") | ||
} | ||
// Picker("Flavor", selection: $selectedFlavor) { | ||
// Text("Distance").tag(Sorting.distance) | ||
// Label("A-Z", systemImage: "textformat.characters").tag(Sorting.alphabetical) | ||
// } | ||
// | ||
// .pickerStyle(.menu) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
SearchPageView() | ||
} |