From 8025510b3d11b5442bb2045b44442ad9e03f3225 Mon Sep 17 00:00:00 2001 From: zoha131 Date: Wed, 28 Oct 2020 16:03:31 +0600 Subject: [PATCH] remove default data from RelationView to fix #144 If the viewmodel is in Activity mode then only ActivityIndicator will be shown. If there is any relation then the Relation data would be shown. Otherwise, a default text will be shown to indicate an empty relation. --- .../LocalizableStringConstants.swift | 1 + mentorship ios/Views/Relation/Relation.swift | 87 ++++++++++--------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/mentorship ios/Constants/LocalizableStringConstants.swift b/mentorship ios/Constants/LocalizableStringConstants.swift index 4b0baea3..d6695bba 100644 --- a/mentorship ios/Constants/LocalizableStringConstants.swift +++ b/mentorship ios/Constants/LocalizableStringConstants.swift @@ -45,6 +45,7 @@ struct LocalizableStringConstants { static let profile = LocalizedStringKey("Profile") static let editProfile = LocalizedStringKey("Edit Profile") static let addTask = LocalizedStringKey("Add Task") + static let noRelationText = LocalizedStringKey("No active relation") static let markComplete = LocalizedStringKey("Mark as complete") static let relationRequest = LocalizedStringKey("Relation Request") static let notAvailable = LocalizedStringKey("Not available") diff --git a/mentorship ios/Views/Relation/Relation.swift b/mentorship ios/Views/Relation/Relation.swift index fd608ef1..79119a1c 100644 --- a/mentorship ios/Views/Relation/Relation.swift +++ b/mentorship ios/Views/Relation/Relation.swift @@ -15,6 +15,11 @@ struct Relation: View { var endDate: Date { return Date(timeIntervalSince1970: relationViewModel.currentRelation.endDate ?? 0) } + + var hasRelation: Bool { + return relationViewModel.currentRelation.id != nil && + relationViewModel.currentRelation.id != 0 + } // use service to fetch relation and tasks func fetchRelationAndTasks() { @@ -69,49 +74,51 @@ struct Relation: View { var body: some View { NavigationView { ZStack { - Form { - //Top detail view - VStack(alignment: .leading, spacing: DesignConstants.Form.Spacing.minimalSpacing) { - //mentor/mentee name and end date - HStack { - Text(relationViewModel.personName).font(.title).fontWeight(.heavy) - Spacer() - Text(relationViewModel.personType).font(.title) - } - .foregroundColor(DesignConstants.Colors.subtitleText) - - Text("Ends On: \(DesignConstants.DateFormat.mediumDate.string(from: endDate))") - .font(.callout) - - //divider, adds a line below name and date - Divider() - .background(DesignConstants.Colors.defaultIndigoColor) - } - .listRowBackground(DesignConstants.Colors.formBackgroundColor) - - //Tasks To Do List section - TasksSection(tasks: relationViewModel.toDoTasks, isToDoSection: true, navToTaskComments: true) { task in - //set tapped task - RelationViewModel.taskTapped = task - //show alert for marking as complete confirmation - self.showAlert.toggle() - } - .alert(isPresented: $showAlert) { - Alert( - title: Text(LocalizableStringConstants.markComplete), - primaryButton: .cancel(), - secondaryButton: .default(Text(LocalizableStringConstants.confirm)) { - self.markAsComplete() - }) - } - - //Tasks Done List section - TasksSection(tasks: relationViewModel.doneTasks, navToTaskComments: true) - } - //show activity spinner if in activity if relationViewModel.inActivity { ActivityIndicator(isAnimating: $relationViewModel.inActivity, style: .medium) + } else if hasRelation { + Form { + //Top detail view + VStack(alignment: .leading, spacing: DesignConstants.Form.Spacing.minimalSpacing) { + //mentor/mentee name and end date + HStack { + Text(relationViewModel.personName).font(.title).fontWeight(.heavy) + Spacer() + Text(relationViewModel.personType).font(.title) + } + .foregroundColor(DesignConstants.Colors.subtitleText) + + Text("Ends On: \(DesignConstants.DateFormat.mediumDate.string(from: endDate))") + .font(.callout) + + //divider, adds a line below name and date + Divider() + .background(DesignConstants.Colors.defaultIndigoColor) + } + .listRowBackground(DesignConstants.Colors.formBackgroundColor) + + //Tasks To Do List section + TasksSection(tasks: relationViewModel.toDoTasks, isToDoSection: true, navToTaskComments: true) { task in + //set tapped task + RelationViewModel.taskTapped = task + //show alert for marking as complete confirmation + self.showAlert.toggle() + } + .alert(isPresented: $showAlert) { + Alert( + title: Text(LocalizableStringConstants.markComplete), + primaryButton: .cancel(), + secondaryButton: .default(Text(LocalizableStringConstants.confirm)) { + self.markAsComplete() + }) + } + + //Tasks Done List section + TasksSection(tasks: relationViewModel.doneTasks, navToTaskComments: true) + } + } else { + Text(LocalizableStringConstants.noRelationText) } } .environment(\.horizontalSizeClass, .regular)