@@ -15,6 +15,11 @@ struct Relation: View {
15
15
var endDate : Date {
16
16
return Date ( timeIntervalSince1970: relationViewModel. currentRelation. endDate ?? 0 )
17
17
}
18
+
19
+ var hasRelation : Bool {
20
+ return relationViewModel. currentRelation. id != nil &&
21
+ relationViewModel. currentRelation. id != 0
22
+ }
18
23
19
24
// use service to fetch relation and tasks
20
25
func fetchRelationAndTasks( ) {
@@ -69,49 +74,51 @@ struct Relation: View {
69
74
var body : some View {
70
75
NavigationView {
71
76
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
-
112
77
//show activity spinner if in activity
113
78
if relationViewModel. inActivity {
114
79
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)
115
122
}
116
123
}
117
124
. environment ( \. horizontalSizeClass, . regular)
0 commit comments