mirror of
https://github.com/NinjaCheetah/RIT-Dining.git
synced 2026-03-05 05:25:29 -05:00
Started work on refactors
- The favorites model now lives inside of the base dining model, since it was only ever used in places where the main dining model was also available and is only relevant when the dining model is available. - Removed unnecessary instances of models that were going unused. - Moved the favorite/map/menu buttons in the top right of the DetailView into the right side toolbar. - This frees up a good bit of space at the top of the DetailView and looks cleaner, especially with iOS 26's new toolbar style. - Actually added a copyright string to the about screen. More refactors, both internally and for the UI, will be coming soon.
This commit is contained in:
@@ -14,7 +14,8 @@ struct LocationList: View {
|
||||
@Binding var openLocationsFirst: Bool
|
||||
@Binding var openLocationsOnly: Bool
|
||||
@Binding var searchText: String
|
||||
@Environment(Favorites.self) var favorites
|
||||
|
||||
@Environment(DiningModel.self) var model
|
||||
|
||||
// The dining locations need to be sorted before being displayed. Favorites should always be shown first, followed by non-favorites.
|
||||
// Afterwards, filters the sorted list based on any current search text and the "open locations only" filtering option.
|
||||
@@ -29,8 +30,8 @@ struct LocationList: View {
|
||||
return name
|
||||
}
|
||||
newLocations.sort { firstLoc, secondLoc in
|
||||
let firstLocIsFavorite = favorites.contains(firstLoc)
|
||||
let secondLocIsFavorite = favorites.contains(secondLoc)
|
||||
let firstLocIsFavorite = model.favorites.contains(firstLoc)
|
||||
let secondLocIsFavorite = model.favorites.contains(secondLoc)
|
||||
// Favorites get priority!
|
||||
if firstLocIsFavorite != secondLocIsFavorite {
|
||||
return firstLocIsFavorite && !secondLocIsFavorite
|
||||
@@ -61,7 +62,7 @@ struct LocationList: View {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text(location.name)
|
||||
if favorites.contains(location) {
|
||||
if model.favorites.contains(location) {
|
||||
Image(systemName: "star.fill")
|
||||
.foregroundStyle(.yellow)
|
||||
}
|
||||
@@ -94,21 +95,21 @@ struct LocationList: View {
|
||||
.swipeActions {
|
||||
Button(action: {
|
||||
withAnimation {
|
||||
if favorites.contains(location) {
|
||||
favorites.remove(location)
|
||||
if model.favorites.contains(location) {
|
||||
model.favorites.remove(location)
|
||||
} else {
|
||||
favorites.add(location)
|
||||
model.favorites.add(location)
|
||||
}
|
||||
}
|
||||
|
||||
}) {
|
||||
if favorites.contains(location) {
|
||||
if model.favorites.contains(location) {
|
||||
Label("Unfavorite", systemImage: "star")
|
||||
} else {
|
||||
Label("Favorite", systemImage: "star")
|
||||
}
|
||||
}
|
||||
.tint(favorites.contains(location) ? .yellow : nil)
|
||||
.tint(model.favorites.contains(location) ? .yellow : nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user