From db62bd6be97aec208f6a630c76b9bf5985c28e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Mu=CC=88ller?= Date: Sun, 7 Feb 2021 16:10:51 +0100 Subject: [PATCH] :lipstick: extracting upcoming lectures and exams blocks to distinct view for better readability of the code --- DHBW-Service/Views/Tabs/HomeView.swift | 134 ++++++++++++------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/DHBW-Service/Views/Tabs/HomeView.swift b/DHBW-Service/Views/Tabs/HomeView.swift index 0aef2b0..68eb048 100644 --- a/DHBW-Service/Views/Tabs/HomeView.swift +++ b/DHBW-Service/Views/Tabs/HomeView.swift @@ -55,49 +55,11 @@ struct HomeView: View { HStack { Spacer() - VStack { - Text("today".localized(tableName: "HomeView")) - .font(.title) - .frame(maxWidth: .infinity, alignment: .leading) - VStack { - if(!todaysEvents.isEmpty){ - ForEach(todaysEvents, id: \.self) { exam in - Text(exam.value(forKey: "summary") as! String) - .frame(maxWidth: .infinity, alignment: .leading) - } - } else { - Text("noLectures".localized(tableName: "HomeView")) - .frame(maxWidth: .infinity, alignment: .leading) - } - } - } - .padding() - .background( - RoundedRectangle(cornerRadius: 10) - .fill(Color.gray) - ) + // Todays lectures block + UpcomingLecturesBlock(eventsList: todaysEvents, titleKey: "today") - VStack { - Text("tomorrow".localized(tableName: "HomeView")) - .font(.title) - .frame(maxWidth: .infinity, alignment: .leading) - VStack { - if(!tomorrowsEvents.isEmpty){ - ForEach(tomorrowsEvents, id: \.self) { exam in - Text(exam.value(forKey: "summary") as! String) - .frame(maxWidth: .infinity, alignment: .leading) - } - } else { - Text("noLectures".localized(tableName: "HomeView")) - .frame(maxWidth: .infinity, alignment: .leading) - } - } - } - .padding() - .background( - RoundedRectangle(cornerRadius: 10) - .fill(Color.gray) - ) + // Tomorrows lectures block + UpcomingLecturesBlock(eventsList: tomorrowsEvents, titleKey: "tomorrow") Spacer() } @@ -106,31 +68,7 @@ struct HomeView: View { HStack { Spacer() - VStack { - Text("upcomingExams".localized(tableName: "HomeView")) - .font(.title) - .frame(maxWidth: .infinity, alignment: .leading) - VStack { - if(!upcomingExams.isEmpty){ - ForEach(upcomingExams, id: \.self) { exam in - Text(exam.value(forKey: "summary") as! String) - .frame(maxWidth: .infinity, alignment: .leading) - } - } else { - Text("noExams".localized(tableName: "HomeView")) - .frame(maxWidth: .infinity, alignment: .leading) - } - } - } - .padding() - .background( - RoundedRectangle(cornerRadius: 10) - .fill(Color.gray) - ) - .overlay( - RoundedRectangle(cornerRadius: 10) - .stroke(Color.red, lineWidth: 4) - ) + UpcomingExamsBlock(examsList: upcomingExams, titleKey: "upcomingExams") Spacer() } @@ -257,6 +195,68 @@ extension HomeView{ } } +struct UpcomingLecturesBlock: View { + let eventsList: [NSManagedObject] + let titleKey: String + + var body: some View { + VStack { + Text(titleKey.localized(tableName: "HomeView")) + .font(.title) + .frame(maxWidth: .infinity, alignment: .leading) + VStack { + if(!eventsList.isEmpty){ + ForEach(eventsList, id: \.self) { exam in + Text(exam.value(forKey: "summary") as! String) + .frame(maxWidth: .infinity, alignment: .leading) + } + } else { + Text("noLectures".localized(tableName: "HomeView")) + .frame(maxWidth: .infinity, alignment: .leading) + } + } + } + .padding() + .background( + RoundedRectangle(cornerRadius: 10) + .fill(Color.gray) + ) + } +} + +struct UpcomingExamsBlock: View { + let examsList: [NSManagedObject] + let titleKey: String + + var body: some View { + VStack { + Text(titleKey.localized(tableName: "HomeView")) + .font(.title) + .frame(maxWidth: .infinity, alignment: .leading) + VStack { + if(!examsList.isEmpty){ + ForEach(examsList, id: \.self) { exam in + Text(exam.value(forKey: "summary") as! String) + .frame(maxWidth: .infinity, alignment: .leading) + } + } else { + Text("noExams".localized(tableName: "HomeView")) + .frame(maxWidth: .infinity, alignment: .leading) + } + } + } + .padding() + .background( + RoundedRectangle(cornerRadius: 10) + .fill(Color.gray) + ) + .overlay( + RoundedRectangle(cornerRadius: 10) + .stroke(Color.red, lineWidth: 4) + ) + } +} + struct HomeView_Previews: PreviewProvider { static var previews: some View { HomeView()