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

Commit

Permalink
remove default data from RelationView to fix anitab-org#144
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Zoha131 committed Oct 28, 2020
1 parent d8c4b70 commit 8025510
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
1 change: 1 addition & 0 deletions mentorship ios/Constants/LocalizableStringConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
87 changes: 47 additions & 40 deletions mentorship ios/Views/Relation/Relation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8025510

Please sign in to comment.