Skip to content

Commit

Permalink
Fix Navigation & Course Reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulon12 committed Jan 19, 2025
1 parent fe06e2c commit 2a1c592
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ struct AllAnnouncementsView: View {
var body: some View {
List(selection: $selectedAnnouncement) {
ForEach(announcementsManager.announcements) { announcement in
NavigationLink(value: announcement) {
NavigationLink {
CourseAnnouncementDetailView(announcement: announcement)
} label: {
AnnouncementRow(
course: announcement.course,
announcement: announcement,
Expand All @@ -27,10 +29,6 @@ struct AllAnnouncementsView: View {
}
}
.navigationTitle("All Announcements")
.navigationDestination(
item: $selectedAnnouncement,
destination: CourseAnnouncementDetailView.init
)
.statusToolbarItem("Announcements", isVisible: isLoadingAnnouncements)
.task {
isLoadingAnnouncements = true
Expand Down
19 changes: 19 additions & 0 deletions CanvasPlusPlayground/Features/Navigation/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct HomeView: View {
@EnvironmentObject private var llmEvaluator: LLMEvaluator

@State private var columnVisibility = NavigationSplitViewVisibility.all
@State private var isLoadingCourses = false

@SceneStorage("CourseListView.selectedNavigationPage")
private var selectedNavigationPage: NavigationPage?
Expand All @@ -39,6 +40,10 @@ struct HomeView: View {

NavigationSplitView(columnVisibility: $columnVisibility) {
Sidebar()
.statusToolbarItem("Courses", isVisible: isLoadingCourses)
.refreshable {
await loadCourses()
}
} content: {
contentView
} detail: {
Expand All @@ -53,6 +58,13 @@ struct HomeView: View {
navigationModel.selectedNavigationPage = selectedNavigationPage
navigationModel.selectedCoursePage = selectedCoursePage
}
.task {
if StorageKeys.needsAuthorization {
navigationModel.showAuthorizationSheet = true
} else {
await loadCourses()
}
}
.onChange(of: navigationModel.selectedNavigationPage) { _, new in
selectedNavigationPage = new
}
Expand Down Expand Up @@ -88,6 +100,13 @@ struct HomeView: View {
ContentUnavailableView("Select a course", systemImage: "folder")
}
}

private func loadCourses() async {
isLoadingCourses = true
await courseManager.getCourses()
await profileManager.getCurrentUserAndProfile()
isLoadingCourses = false
}
}

#Preview {
Expand Down
20 changes: 0 additions & 20 deletions CanvasPlusPlayground/Features/Navigation/Sidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ struct Sidebar: View {
@Environment(CourseManager.self) private var courseManager
@Environment(ProfileManager.self) private var profileManager

@State private var isLoadingCourses = false

var body: some View {
@Bindable var navigationModel = navigationModel

Expand Down Expand Up @@ -49,7 +47,6 @@ struct Sidebar: View {
.navigationSplitViewColumnWidth(min: 275, ideal: 275)
#endif
.listStyle(.sidebar)
.statusToolbarItem("Courses", isVisible: isLoadingCourses)
#if os(iOS)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Expand All @@ -59,23 +56,6 @@ struct Sidebar: View {
}
}
#endif
.task {
if StorageKeys.needsAuthorization {
navigationModel.showAuthorizationSheet = true
} else {
await loadCourses()
}
}
.refreshable {
await loadCourses()
}
}

private func loadCourses() async {
isLoadingCourses = true
await courseManager.getCourses()
await profileManager.getCurrentUserAndProfile()
isLoadingCourses = false
}
}

Expand Down

0 comments on commit 2a1c592

Please sign in to comment.