Skip to content

Commit

Permalink
Fix slow loading screens
Browse files Browse the repository at this point in the history
  • Loading branch information
alexphanna committed Oct 3, 2024
1 parent 6d9243c commit 351c323
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Binary file not shown.
3 changes: 0 additions & 3 deletions RU-Eating/Models/Place.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ class Place: Identifiable, Hashable {
let id = try! element.attr("for")
let isFavorite = settings.favoriteItemsIDs.contains(id)
let item = Item(name: name, id: id, servingsNumber: servingsNumber, servingsUnit: servingsUnit, carbonFootprint: carbonFootprint, isFavorite: isFavorite, settings: settings)
if fetchItems {
await item.fetchData(settings: settings)
}

lastCategory!.items.append(item)

Expand Down
7 changes: 7 additions & 0 deletions RU-Eating/ViewModels/MenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,18 @@ import Foundation
func updateMenu() async {
fetched = false
rawMenu = [Category]()
sortBy = "None"
filter = "All Items"
do {
rawMenu = try await place.fetchMenu(meal: meal == "Takeout" ? "Knight+Room" : meal, date: date, settings: settings)
if !items.items.isEmpty {
randomItem = items.items.randomElement()!
}
for category in rawMenu {
for item in category.items {
await item.fetchData(settings: settings)
}
}
} catch {
// do nothing
}
Expand Down
5 changes: 4 additions & 1 deletion RU-Eating/Views/ItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ struct ItemView: View {
if (settings.hideRestricted /*&& !viewModel.contains*/) || !settings.hideRestricted {
NavigationStack {
VStack {
if viewModel.item.ingredients.isEmpty {
if !viewModel.item.fetched {
ProgressView()
}
else if viewModel.item.ingredients.isEmpty {
Text("Nutritional information is not available for this item")
}
else {
Expand Down
12 changes: 7 additions & 5 deletions RU-Eating/Views/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ struct MenuView: View {
.pickerStyle(.menu)
Menu {
Section {
Picker("", selection: $viewModel.sortBy) {
ForEach(["None", "Name", "Nutrient", "Carbon Footprint", "Ingredients"], id: \.self) {
Text($0)
}
}
Button("None", action: { viewModel.sortBy = "None" })
Button("Name", action: { viewModel.sortBy = "Name" })
Button("Carbon Footprint", action: { viewModel.sortBy = "Carbon Footprint" })
Button("Nutrient", action: { viewModel.sortBy = "Nutrient" })
.disabled(!viewModel.fetched)
Button("Ingredients", action: { viewModel.sortBy = "Ingredients" })
.disabled(!viewModel.fetched)
}
Section {
Picker("", selection: $viewModel.sortOrder) {
Expand Down

0 comments on commit 351c323

Please sign in to comment.