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

remove default data from RelationView #154

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions mentorship ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
839761C1249F821A0020535C /* ProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839761C0249F821A0020535C /* ProfileViewModel.swift */; };
839761C3249F83860020535C /* MembersViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839761C2249F83860020535C /* MembersViewModel.swift */; };
83AA531D249F860F001D6B0B /* UIHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83AA531C249F860F001D6B0B /* UIHelper.swift */; };
892B1E1925BF938C001A4B74 /* EmptyIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892B1E1825BF938C001A4B74 /* EmptyIndicator.swift */; };
AA29979BC7A25F0F15EF1EAB /* Pods_mentorship_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B7C6AD7AFF5534C376F1BAF /* Pods_mentorship_ios.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -243,6 +244,7 @@
839761C0249F821A0020535C /* ProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewModel.swift; sourceTree = "<group>"; };
839761C2249F83860020535C /* MembersViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MembersViewModel.swift; sourceTree = "<group>"; };
83AA531C249F860F001D6B0B /* UIHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIHelper.swift; sourceTree = "<group>"; };
892B1E1825BF938C001A4B74 /* EmptyIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyIndicator.swift; sourceTree = "<group>"; };
A54B8453C53ABE688B6FEF0C /* Pods-mentorship ios-mentorship iosUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-mentorship ios-mentorship iosUITests.debug.xcconfig"; path = "Target Support Files/Pods-mentorship ios-mentorship iosUITests/Pods-mentorship ios-mentorship iosUITests.debug.xcconfig"; sourceTree = "<group>"; };
A786C8A19E95295DBDC3690A /* Pods-mentorship iosTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-mentorship iosTests.debug.xcconfig"; path = "Target Support Files/Pods-mentorship iosTests/Pods-mentorship iosTests.debug.xcconfig"; sourceTree = "<group>"; };
B8251B7BB63EBD5A6466B87F /* Pods-mentorship ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-mentorship ios.debug.xcconfig"; path = "Target Support Files/Pods-mentorship ios/Pods-mentorship ios.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -368,7 +370,6 @@
53D4545324CD50F500083215 /* HomeTests.swift */,
53A6DDEF24BE52A100D5DFCE /* ProfileTests.swift */,
53A6DC8324CDAC7C00E4FE14 /* RelationTests.swift */,
53AC6DE624D2BF8700F7FDE3 /* TaskCommentsTests.swift */,
53A6DC8524CDC4EF00E4FE14 /* MembersTests.swift */,
53A6DC8724CDCBCA00E4FE14 /* SettingsTests.swift */,
534B69D924CB6DAE007646E6 /* MockURLProtocol.swift */,
Expand Down Expand Up @@ -528,6 +529,7 @@
53C0206E249B8D270000BEB5 /* CommonProfileSection.swift */,
53FEC16E24D8842200073535 /* SearchNavigation.swift */,
53C59E8D24E6B04900EA0DB4 /* SocialSignInButtons.swift */,
892B1E1825BF938C001A4B74 /* EmptyIndicator.swift */,
);
path = UtilityViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -994,6 +996,7 @@
538CD07224ABE9B800F6A665 /* AddTask.swift in Sources */,
53C59E8E24E6B04900EA0DB4 /* SocialSignInButtons.swift in Sources */,
53F205DD249ADF9200DDE52E /* ProfileEditor.swift in Sources */,
892B1E1925BF938C001A4B74 /* EmptyIndicator.swift in Sources */,
534AC02D2486D5CB00A34A46 /* BigBoldButtonStyle.swift in Sources */,
53D127B1249C956A003B4756 /* ActivityWithText.swift in Sources */,
530F44162482752500B1FD0B /* SceneDelegate.swift in Sources */,
Expand Down Expand Up @@ -1210,9 +1213,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "mentorship ios/mentorship ios.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"mentorship ios/Preview Content\"";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 4UDSZ3HFA2;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "mentorship ios/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -1221,6 +1225,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.anitab.mentorship;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -1232,9 +1237,10 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "mentorship ios/mentorship ios.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"mentorship ios/Preview Content\"";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 4UDSZ3HFA2;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "mentorship ios/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -1243,6 +1249,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.anitab.mentorship;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
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 noActiveRelation = 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
92 changes: 51 additions & 41 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
Comment on lines +20 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why are you checking for both nil and 0?
Wouldn't nil signify that the backend response was not found in which case showing the user the "No active relation" state is wrong and we should show an error state instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentRelation inside RelationModel has default id which is 0. And if there is no relation then the response I get is nil. This is why I am checking both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright..thanks for clarifying!

}

// use service to fetch relation and tasks
func fetchRelationAndTasks() {
Expand Down Expand Up @@ -67,7 +72,7 @@ struct Relation: View {
}

@ViewBuilder func trailingNavigationBarItem() -> some View {
if let id = relationViewModel.currentRelation.id, id != 0 {
if hasRelation {
Button(LocalizableStringConstants.addTask) {
self.relationViewModel.addTask.toggle()
}
Expand All @@ -77,49 +82,54 @@ 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)
}

//Screen background color
DesignConstants.Colors.formBackgroundColor.edgesIgnoringSafeArea(.all)

//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 {
EmptyIndicator(title: LocalizableStringConstants.noActiveRelation)
}
}
.environment(\.horizontalSizeClass, .regular)
Expand Down
15 changes: 15 additions & 0 deletions mentorship ios/Views/UtilityViews/EmptyIndicator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// EmptyIndicator.swift
// Created on 1/26/21
// Created for AnitaB.org Mentorship-iOS
//

import SwiftUI

struct EmptyIndicator: View {
var title: LocalizedStringKey

var body: some View {
Text(title)
}
}