Skip to content
This repository was archived by the owner on Nov 5, 2021. It is now read-only.

Commit 8025510

Browse files
committed
remove default data from RelationView to fix anitab-org#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.
1 parent d8c4b70 commit 8025510

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

mentorship ios/Constants/LocalizableStringConstants.swift

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct LocalizableStringConstants {
4545
static let profile = LocalizedStringKey("Profile")
4646
static let editProfile = LocalizedStringKey("Edit Profile")
4747
static let addTask = LocalizedStringKey("Add Task")
48+
static let noRelationText = LocalizedStringKey("No active relation")
4849
static let markComplete = LocalizedStringKey("Mark as complete")
4950
static let relationRequest = LocalizedStringKey("Relation Request")
5051
static let notAvailable = LocalizedStringKey("Not available")

mentorship ios/Views/Relation/Relation.swift

+47-40
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ struct Relation: View {
1515
var endDate: Date {
1616
return Date(timeIntervalSince1970: relationViewModel.currentRelation.endDate ?? 0)
1717
}
18+
19+
var hasRelation: Bool {
20+
return relationViewModel.currentRelation.id != nil &&
21+
relationViewModel.currentRelation.id != 0
22+
}
1823

1924
// use service to fetch relation and tasks
2025
func fetchRelationAndTasks() {
@@ -69,49 +74,51 @@ struct Relation: View {
6974
var body: some View {
7075
NavigationView {
7176
ZStack {
72-
Form {
73-
//Top detail view
74-
VStack(alignment: .leading, spacing: DesignConstants.Form.Spacing.minimalSpacing) {
75-
//mentor/mentee name and end date
76-
HStack {
77-
Text(relationViewModel.personName).font(.title).fontWeight(.heavy)
78-
Spacer()
79-
Text(relationViewModel.personType).font(.title)
80-
}
81-
.foregroundColor(DesignConstants.Colors.subtitleText)
82-
83-
Text("Ends On: \(DesignConstants.DateFormat.mediumDate.string(from: endDate))")
84-
.font(.callout)
85-
86-
//divider, adds a line below name and date
87-
Divider()
88-
.background(DesignConstants.Colors.defaultIndigoColor)
89-
}
90-
.listRowBackground(DesignConstants.Colors.formBackgroundColor)
91-
92-
//Tasks To Do List section
93-
TasksSection(tasks: relationViewModel.toDoTasks, isToDoSection: true, navToTaskComments: true) { task in
94-
//set tapped task
95-
RelationViewModel.taskTapped = task
96-
//show alert for marking as complete confirmation
97-
self.showAlert.toggle()
98-
}
99-
.alert(isPresented: $showAlert) {
100-
Alert(
101-
title: Text(LocalizableStringConstants.markComplete),
102-
primaryButton: .cancel(),
103-
secondaryButton: .default(Text(LocalizableStringConstants.confirm)) {
104-
self.markAsComplete()
105-
})
106-
}
107-
108-
//Tasks Done List section
109-
TasksSection(tasks: relationViewModel.doneTasks, navToTaskComments: true)
110-
}
111-
11277
//show activity spinner if in activity
11378
if relationViewModel.inActivity {
11479
ActivityIndicator(isAnimating: $relationViewModel.inActivity, style: .medium)
80+
} else if hasRelation {
81+
Form {
82+
//Top detail view
83+
VStack(alignment: .leading, spacing: DesignConstants.Form.Spacing.minimalSpacing) {
84+
//mentor/mentee name and end date
85+
HStack {
86+
Text(relationViewModel.personName).font(.title).fontWeight(.heavy)
87+
Spacer()
88+
Text(relationViewModel.personType).font(.title)
89+
}
90+
.foregroundColor(DesignConstants.Colors.subtitleText)
91+
92+
Text("Ends On: \(DesignConstants.DateFormat.mediumDate.string(from: endDate))")
93+
.font(.callout)
94+
95+
//divider, adds a line below name and date
96+
Divider()
97+
.background(DesignConstants.Colors.defaultIndigoColor)
98+
}
99+
.listRowBackground(DesignConstants.Colors.formBackgroundColor)
100+
101+
//Tasks To Do List section
102+
TasksSection(tasks: relationViewModel.toDoTasks, isToDoSection: true, navToTaskComments: true) { task in
103+
//set tapped task
104+
RelationViewModel.taskTapped = task
105+
//show alert for marking as complete confirmation
106+
self.showAlert.toggle()
107+
}
108+
.alert(isPresented: $showAlert) {
109+
Alert(
110+
title: Text(LocalizableStringConstants.markComplete),
111+
primaryButton: .cancel(),
112+
secondaryButton: .default(Text(LocalizableStringConstants.confirm)) {
113+
self.markAsComplete()
114+
})
115+
}
116+
117+
//Tasks Done List section
118+
TasksSection(tasks: relationViewModel.doneTasks, navToTaskComments: true)
119+
}
120+
} else {
121+
Text(LocalizableStringConstants.noRelationText)
115122
}
116123
}
117124
.environment(\.horizontalSizeClass, .regular)

0 commit comments

Comments
 (0)