);
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index c4352804..77d635d4 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -1,4 +1,7 @@
import * as DB from '../../constants/database.js';
+import app from '../Firebase';
+
+const db = app.firestore();
/**
* Sort a list of trip activities by date.
@@ -54,4 +57,29 @@ export function getField(activity, fieldName, defaultValue){
return defaultValue;
}
return activity[fieldName];
+}
+
+/**
+ *
+ * @param {*} tripId
+ * @param {*} activityId
+ * @param {*} fieldName
+ * @param {*} newValue
+ */
+export async function writeActivity(tripId, activityId, newValues) {
+ // todo: check if tripId or activityId is not valid.
+ if (newValues === null) {
+ return false;
+ }
+
+ const act = db.collection(DB.COLLECTION_TRIPS).doc(tripId)
+ .collection(DB.COLLECTION_ACTIVITIES).doc(activityId);
+
+ try {
+ const a = await act.update(newValues);
+ return true;
+ } catch (e) {
+ console.log(e);
+ return false;
+ }
}
\ No newline at end of file
diff --git a/frontend/src/components/ViewActivities/activitylist.js b/frontend/src/components/ViewActivities/activitylist.js
index 8427d711..98ae91b3 100644
--- a/frontend/src/components/ViewActivities/activitylist.js
+++ b/frontend/src/components/ViewActivities/activitylist.js
@@ -7,7 +7,6 @@ import app from '../Firebase';
const db = app.firestore();
-
/**
* Gets the list of activities from the server.
*
@@ -23,6 +22,7 @@ export async function getActivityList(tripId) {
querySnapshot.forEach(doc => {
let data = doc.data();
data['id'] = doc.id;
+ data['tripId'] = tripId;
// TODO: if start date != end date, split into 2 days. (#37)
From 416d1cee9d9db37bf4b91f1699f1d42c9cf820bb Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 14 Jul 2020 17:46:14 -0500
Subject: [PATCH 03/24] Update comments and stuff
---
frontend/src/components/ViewActivities/activity.js | 6 +++---
frontend/src/components/ViewActivities/activityfns.js | 11 ++++++-----
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index 7d316ceb..69b27458 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -25,7 +25,7 @@ class Activity extends React.Component {
constructor(props) {
super(props);
- this.state = { editing: false, title: "abcd" };
+ this.state = { editing: false };
// Bind state users/modifiers to `this`.
this.setEditActivity = this.setEditActivity.bind(this);
@@ -57,7 +57,7 @@ class Activity extends React.Component {
};
/**
- *
+ * TODO FUNCTION DEF HERE
*/
editActivity() {
let newVals = {};
@@ -120,7 +120,7 @@ class Activity extends React.Component {
return (
-
+
{activity[DB.ACTIVITIES_TITLE]}
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 77d635d4..85a7f7f5 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -60,11 +60,11 @@ export function getField(activity, fieldName, defaultValue){
}
/**
+ * Write contents into an activity in the database.
*
- * @param {*} tripId
- * @param {*} activityId
- * @param {*} fieldName
- * @param {*} newValue
+ * @param {string} tripId Database ID of the trip whose actiivty should be modified.
+ * @param {string} activityId Database ID of the activity to be modified.
+ * @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
*/
export async function writeActivity(tripId, activityId, newValues) {
// todo: check if tripId or activityId is not valid.
@@ -76,8 +76,9 @@ export async function writeActivity(tripId, activityId, newValues) {
.collection(DB.COLLECTION_ACTIVITIES).doc(activityId);
try {
+ // Note: newValues cannot contain lists. Check documentation for update().
const a = await act.update(newValues);
- return true;
+ return a ? true : false;
} catch (e) {
console.log(e);
return false;
From 7ae5fc36faf6fd4367ae4c5d532511dcaea93fdf Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 14 Jul 2020 18:06:02 -0500
Subject: [PATCH 04/24] Function definition and description field.
---
frontend/src/components/ViewActivities/activity.js | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index 69b27458..15e983d5 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -57,13 +57,17 @@ class Activity extends React.Component {
};
/**
- * TODO FUNCTION DEF HERE
+ * Edit an activity in the database upon form submission.
+ * TODO: Update times as well! This only does the text field forms.
*/
editActivity() {
let newVals = {};
if (this.editTitleRef.current !== null) {
newVals[DB.ACTIVITIES_TITLE] = this.editTitleRef.current.value;
}
+ if (this.editDescriptionRef.current !== null) {
+ newVals[DB.ACTIVITIES_DESCRIPTION] = this.editDescriptionRef.current.value;
+ }
if (Object.keys(newVals).length !== 0) {
writeActivity(this.props.activity.tripId, this.props.activity.id, newVals);
}
From 6fb45c9d56a1e523eb628ac3dda6824342c86266 Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Wed, 15 Jul 2020 14:31:02 -0500
Subject: [PATCH 05/24] fix tests so they don't fail
---
frontend/src/components/Utils/time.test.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/frontend/src/components/Utils/time.test.js b/frontend/src/components/Utils/time.test.js
index 729b519d..bd0c6c78 100644
--- a/frontend/src/components/Utils/time.test.js
+++ b/frontend/src/components/Utils/time.test.js
@@ -1,7 +1,7 @@
-import * as utils from './utils';
+import * as utils from './time';
const TZ_CHICAGO = 'America/Chicago';
-const TZ_SINGAPORE = ;
+const TZ_SINGAPORE = "Asia/Singapore";
test('new york date timestamp format', () => {
// Month parameter is zero indexed so it's actually the 10th month.
From 380055b576fd023fc19baae986bc41a4a06f934f Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Wed, 15 Jul 2020 14:36:50 -0500
Subject: [PATCH 06/24] update issue number
---
frontend/src/components/ViewActivities/activityfns.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 85a7f7f5..3fb8f8b0 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -67,7 +67,7 @@ export function getField(activity, fieldName, defaultValue){
* @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
*/
export async function writeActivity(tripId, activityId, newValues) {
- // todo: check if tripId or activityId is not valid.
+ // todo: check if tripId or activityId is not valid. (#58)
if (newValues === null) {
return false;
}
From d891f87236f2450b600e4c54da9411b364369b61 Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Thu, 16 Jul 2020 13:40:59 -0500
Subject: [PATCH 07/24] timestamp field.
---
.../src/components/ViewActivities/activity.js | 34 +++++++++----------
.../components/ViewActivities/activityfns.js | 12 +++++--
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index 15e983d5..fdef1b63 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -42,30 +42,16 @@ class Activity extends React.Component {
this.editDescriptionRef = React.createRef();
}
- /**
- * Set the activity into editing mode.
- */
- setEditActivity = () => ( this.setState({editing: true}) );
-
- /**
- * Set the activity into viewing mode.
- */
- finishEditActivity(event) {
- this.setState({editing: false});
- event.preventDefault();
- this.editActivity();
- };
-
/**
* Edit an activity in the database upon form submission.
- * TODO: Update times as well! This only does the text field forms.
+ * TODO: Update times as well! This only does the text field forms (#46).
*/
editActivity() {
let newVals = {};
- if (this.editTitleRef.current !== null) {
+ if (this.editTitleRef.current.value !== "") {
newVals[DB.ACTIVITIES_TITLE] = this.editTitleRef.current.value;
}
- if (this.editDescriptionRef.current !== null) {
+ if (this.editDescriptionRef.current.value !== "") {
newVals[DB.ACTIVITIES_DESCRIPTION] = this.editDescriptionRef.current.value;
}
if (Object.keys(newVals).length !== 0) {
@@ -73,6 +59,20 @@ class Activity extends React.Component {
}
}
+ /**
+ * Set the activity into editing mode.
+ */
+ setEditActivity = () => ( this.setState({editing: true}) );
+
+ /**
+ * Set the activity into viewing mode.
+ */
+ finishEditActivity(event) {
+ this.setState({editing: false});
+ event.preventDefault();
+ this.editActivity();
+ };
+
/**
* Display the current activity, either in view or display mode.
*/
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 3fb8f8b0..3fe50478 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -1,5 +1,6 @@
import * as DB from '../../constants/database.js';
import app from '../Firebase';
+import Firebase from 'firebase';
const db = app.firestore();
@@ -65,12 +66,17 @@ export function getField(activity, fieldName, defaultValue){
* @param {string} tripId Database ID of the trip whose actiivty should be modified.
* @param {string} activityId Database ID of the activity to be modified.
* @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
+ * @returns true if the write was successful, false otherwise.
*/
export async function writeActivity(tripId, activityId, newValues) {
// todo: check if tripId or activityId is not valid. (#58)
- if (newValues === null) {
- return false;
- }
+ newValues = {
+ ...newValues,
+ "fillerstamp": Firebase.database.ServerValue.TIMESTAMP
+ };
+
+ console.log(Firebase.database.ServerValue.TIMESTAMP);
+ console.log(newValues);
const act = db.collection(DB.COLLECTION_TRIPS).doc(tripId)
.collection(DB.COLLECTION_ACTIVITIES).doc(activityId);
From 6062e52448cfef175d02ef359bc29b690f65a37b Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Thu, 16 Jul 2020 13:41:49 -0500
Subject: [PATCH 08/24] update issue number so it's right.
---
frontend/src/components/ViewActivities/activity.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index fdef1b63..e01a716a 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -44,7 +44,7 @@ class Activity extends React.Component {
/**
* Edit an activity in the database upon form submission.
- * TODO: Update times as well! This only does the text field forms (#46).
+ * TODO: Update times as well! This only does the text field forms (#64).
*/
editActivity() {
let newVals = {};
From 326d680b844268c077832abfa40afcdc1621da7f Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Thu, 16 Jul 2020 13:43:52 -0500
Subject: [PATCH 09/24] remove console logs'
---
frontend/src/components/ViewActivities/activityfns.js | 3 ---
1 file changed, 3 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 3fe50478..63fcde82 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -75,9 +75,6 @@ export async function writeActivity(tripId, activityId, newValues) {
"fillerstamp": Firebase.database.ServerValue.TIMESTAMP
};
- console.log(Firebase.database.ServerValue.TIMESTAMP);
- console.log(newValues);
-
const act = db.collection(DB.COLLECTION_TRIPS).doc(tripId)
.collection(DB.COLLECTION_ACTIVITIES).doc(activityId);
From c066e5a439979a201c901672ed53b068d43bad17 Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Thu, 16 Jul 2020 14:29:35 -0500
Subject: [PATCH 10/24] SINGLE QUOTES
---
frontend/src/components/Utils/time.js | 4 +--
frontend/src/components/Utils/time.test.js | 12 ++++----
.../src/components/ViewActivities/activity.js | 30 +++++++++----------
.../components/ViewActivities/activityday.js | 6 ++--
.../components/ViewActivities/activityfns.js | 2 +-
.../ViewActivities/activityfns.test.js | 6 ++--
.../components/ViewActivities/activitylist.js | 2 +-
7 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/frontend/src/components/Utils/time.js b/frontend/src/components/Utils/time.js
index 14f378db..27eca202 100644
--- a/frontend/src/components/Utils/time.js
+++ b/frontend/src/components/Utils/time.js
@@ -42,9 +42,9 @@ export function timestampToDateFormatted(msTimestamp, timezone='America/New_York
* @param {int} msTimestamp
* @param {string} timezone
* @returns {string} Time formatted into a string like
- * "Monday, January 19, 1970, 02:48 AM"
+ * 'Monday, January 19, 1970, 02:48 AM'
*/
-export function timestampToFormatted(msTimestamp, timezone = "America/New_York") {
+export function timestampToFormatted(msTimestamp, timezone = 'America/New_York') {
let date = new Date(msTimestamp);
let formatOptions = {
weekday: 'long',
diff --git a/frontend/src/components/Utils/time.test.js b/frontend/src/components/Utils/time.test.js
index bd0c6c78..d954ecb6 100644
--- a/frontend/src/components/Utils/time.test.js
+++ b/frontend/src/components/Utils/time.test.js
@@ -1,7 +1,7 @@
import * as utils from './time';
const TZ_CHICAGO = 'America/Chicago';
-const TZ_SINGAPORE = "Asia/Singapore";
+const TZ_SINGAPORE = 'Asia/Singapore';
test('new york date timestamp format', () => {
// Month parameter is zero indexed so it's actually the 10th month.
@@ -42,17 +42,17 @@ test('other time timestamp format', () => {
test('new york full timestamp format', () => {
// Month parameter is zero indexed so it's actually the 10th month.
const testDate = new Date(Date.UTC(2020, 9, 3, 14, 19, 4, 23)).getTime();
- const expected = "Saturday, October 3, 2020, 10:19 AM";
+ const expected = 'Saturday, October 3, 2020, 10:19 AM';
const actual = utils.timestampToFormatted(testDate);
expect(actual).toEqual(expected);
});
test('other full timestamp format', () => {
const testDate = new Date(Date.UTC(2020, 7, 23, 2, 3, 2, 4)).getTime();
- const expectedCentral = "Saturday, August 22, 2020, 9:03 PM";
- const expectedSingapore = "Sunday, August 23, 2020, 10:03 AM";
- const actualCentral = utils.timestampToFormatted(testDate, "America/Chicago");
- const actualSingapore = utils.timestampToFormatted(testDate, "Asia/Singapore");
+ const expectedCentral = 'Saturday, August 22, 2020, 9:03 PM';
+ const expectedSingapore = 'Sunday, August 23, 2020, 10:03 AM';
+ const actualCentral = utils.timestampToFormatted(testDate, 'America/Chicago');
+ const actualSingapore = utils.timestampToFormatted(testDate, 'Asia/Singapore');
expect(actualCentral).toEqual(expectedCentral);
expect(actualSingapore).toEqual(expectedSingapore);
})
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index e01a716a..05ac9e0e 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -48,10 +48,10 @@ class Activity extends React.Component {
*/
editActivity() {
let newVals = {};
- if (this.editTitleRef.current.value !== "") {
+ if (this.editTitleRef.current.value !== '') {
newVals[DB.ACTIVITIES_TITLE] = this.editTitleRef.current.value;
}
- if (this.editDescriptionRef.current.value !== "") {
+ if (this.editDescriptionRef.current.value !== '') {
newVals[DB.ACTIVITIES_DESCRIPTION] = this.editDescriptionRef.current.value;
}
if (Object.keys(newVals).length !== 0) {
@@ -88,31 +88,31 @@ class Activity extends React.Component {
} else { // Edit mode.
return (
// TODO: Save form. (#48)
-
+
Title:
-
+
-
+
From:
-
-
+
+
{timezonePicker()}
-
+
To:
-
-
+
+
{timezonePicker()}
-
+
Description:
-
-
+
)
}
diff --git a/frontend/src/components/ViewActivities/activityday.js b/frontend/src/components/ViewActivities/activityday.js
index 00ca43ed..21b8a2a5 100644
--- a/frontend/src/components/ViewActivities/activityday.js
+++ b/frontend/src/components/ViewActivities/activityday.js
@@ -7,8 +7,8 @@ import * as time from '../Utils/time.js'
* One single day of activities.
*
* @param {Object} props This component expects the following props:
- * - `activities` The list of activities for "today".
- * - `date` The date, formatted as "MM/DD/YYYY".
+ * - `activities` The list of activities for 'today'.
+ * - `date` The date, formatted as 'MM/DD/YYYY'.
*/
class ActivityDay extends React.Component {
/** @inheritdoc */
@@ -20,7 +20,7 @@ class ActivityDay extends React.Component {
Date: Tue, 21 Jul 2020 15:47:03 -0500
Subject: [PATCH 15/24] Change timestamp import
---
frontend/src/components/ViewActivities/activityfns.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 8ee3070e..d236193b 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -1,6 +1,7 @@
import * as DB from '../../constants/database.js';
import app from '../Firebase';
-import Firebase from 'firebase';
+import { firestore } from 'firebase';
+
const db = app.firestore();
@@ -72,7 +73,7 @@ export async function writeActivity(tripId, activityId, newValues) {
// todo: check if tripId or activityId is not valid. (#58)
newValues = {
...newValues,
- 'fillerstamp': Firebase.firestore.Timestamp.now()
+ 'fillerstamp': firestore.Timestamp.now()
};
const activity = db.collection(DB.COLLECTION_TRIPS).doc(tripId)
From ff397c30abf453350f08f08da054f3da9183cfec Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 21 Jul 2020 15:47:22 -0500
Subject: [PATCH 16/24] wrong variable name
---
frontend/src/components/ViewActivities/activityfns.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index d236193b..d9b26400 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -76,7 +76,7 @@ export async function writeActivity(tripId, activityId, newValues) {
'fillerstamp': firestore.Timestamp.now()
};
- const activity = db.collection(DB.COLLECTION_TRIPS).doc(tripId)
+ const act = db.collection(DB.COLLECTION_TRIPS).doc(tripId)
.collection(DB.COLLECTION_ACTIVITIES).doc(activityId);
try {
From d67017d1a6f29259dfe02093177f1935862aac58 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 21 Jul 2020 17:51:23 -0500
Subject: [PATCH 17/24] Documentation activityfns.js
---
.../components/ViewActivities/activityfns.js | 46 +++++++++++++------
1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index d9b26400..d3f8cd70 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -2,14 +2,32 @@ import * as DB from '../../constants/database.js';
import app from '../Firebase';
import { firestore } from 'firebase';
-
const db = app.firestore();
+/**
+ * An activity object.
+ * @typedef {Object} Activity
+ * @property {string} id The activity's ID in the database.
+ * @property {string} tripId The activity's tripId in the database.
+ * @property {string} title The activity's title.
+ * @property {long} start_time Number of seconds since epoch of activity's start time.
+ * @property {long} end_time Number of seconds since epoch of activity's end time.
+ * @property {string} [description] The activity's description.
+ */
+
+/**
+ * A single activity day. A single instance looks like:
+ *
['MM/DD/YYYY', [activities on that day]]
+ * @typedef {Array.} DayOfActivities
+ *
+ */
+
/**
* Sort a list of trip activities by date.
- * @param {Array} tripActivities Array of activities.
- * @returns List of trip activities in the form
- * [ ['MM/DD/YYYY', [activities on that day]], ...] in chronological order by date.
+ * @param {Activity[]} tripActivities Array of activities.
+ * @return {DayOfActivities[]} List of trip activities in the form
+ *
[ , ...]
+ * in chronological order by date.
*/
export function sortByDate(tripActivities) {
let activities = new Map(); // { MM/DD/YYYY: [activities] }.
@@ -31,8 +49,10 @@ export function sortByDate(tripActivities) {
/**
* Put a and b in display order.
- * @param {dictionary} a Dictionary representing activity a and its fields.
- * @param {dictionary} b Dictionary representing activity b and its fields.
+ * This function is a comparator.
+ * @param {Activity} a Dictionary representing activity a and its fields.
+ * @param {Activity} b Dictionary representing activity b and its fields.
+ * @return {int} -1 if a comes before b, else 1.
*/
export function compareActivities(a, b) {
if (a[DB.ACTIVITIES_START_TIME] < b[DB.ACTIVITIES_START_TIME]) {
@@ -47,12 +67,12 @@ export function compareActivities(a, b) {
/**
- * Get the field of field name `fieldName` from `activity or the default value.
+ * Get the field of field name fieldName from activity or the default value.
*
- * @param {Object} activity
- * @param {string} fieldName
- * @param defaultValue
- * @returns `activity[fieldName]` if possible, else `defaultValue`.
+ * @param {Activity} activity The activity from which to get the field.
+ * @param {string} fieldName Name of field to get.
+ * @param {*} defaultValue Value if field is not found/is null.
+ * @returns {*} activity[fieldName] if possible, else defaultValue.
*/
export function getField(activity, fieldName, defaultValue){
if (activity[fieldName] === null || activity[fieldName] === undefined) {
@@ -67,7 +87,7 @@ export function getField(activity, fieldName, defaultValue){
* @param {string} tripId Database ID of the trip whose actiivty should be modified.
* @param {string} activityId Database ID of the activity to be modified.
* @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
- * @returns true if the write was successful, false otherwise.
+ * @returns {boolean} `true` if the write was successful, `false` otherwise.
*/
export async function writeActivity(tripId, activityId, newValues) {
// todo: check if tripId or activityId is not valid. (#58)
@@ -87,4 +107,4 @@ export async function writeActivity(tripId, activityId, newValues) {
console.log(e);
return false;
}
-}
+}
\ No newline at end of file
From 34607807938ada8ca41a4e78157af8918d841657 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 21 Jul 2020 20:09:37 -0500
Subject: [PATCH 18/24] activityfns documentation
---
.../src/components/ViewActivities/activityfns.js | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index d3f8cd70..75f570a9 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -17,7 +17,7 @@ const db = app.firestore();
/**
* A single activity day. A single instance looks like:
- *
['MM/DD/YYYY', [activities on that day]]
+ *
['MM/DD/YYYY', [activities on that day]]
* @typedef {Array.} DayOfActivities
*
*/
@@ -26,7 +26,7 @@ const db = app.firestore();
* Sort a list of trip activities by date.
* @param {Activity[]} tripActivities Array of activities.
* @return {DayOfActivities[]} List of trip activities in the form
- *
[ , ...]
+ *
[ , ...]
* in chronological order by date.
*/
export function sortByDate(tripActivities) {
@@ -48,11 +48,11 @@ export function sortByDate(tripActivities) {
}
/**
- * Put a and b in display order.
+ * Put a and b in display order.
* This function is a comparator.
* @param {Activity} a Dictionary representing activity a and its fields.
* @param {Activity} b Dictionary representing activity b and its fields.
- * @return {int} -1 if a comes before b, else 1.
+ * @return {int} -1 if a comes before b, else 1.
*/
export function compareActivities(a, b) {
if (a[DB.ACTIVITIES_START_TIME] < b[DB.ACTIVITIES_START_TIME]) {
@@ -72,7 +72,7 @@ export function compareActivities(a, b) {
* @param {Activity} activity The activity from which to get the field.
* @param {string} fieldName Name of field to get.
* @param {*} defaultValue Value if field is not found/is null.
- * @returns {*} activity[fieldName] if possible, else defaultValue.
+ * @returns {*} activity[fieldName] if possible, else defaultValue.
*/
export function getField(activity, fieldName, defaultValue){
if (activity[fieldName] === null || activity[fieldName] === undefined) {
@@ -82,12 +82,12 @@ export function getField(activity, fieldName, defaultValue){
}
/**
- * Write contents into an activity in the database.
+ * Write contents into an activity already existing in the database.
*
* @param {string} tripId Database ID of the trip whose actiivty should be modified.
* @param {string} activityId Database ID of the activity to be modified.
- * @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
- * @returns {boolean} `true` if the write was successful, `false` otherwise.
+ * @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
+ * @returns {boolean} true if the write was successful, false otherwise.
*/
export async function writeActivity(tripId, activityId, newValues) {
// todo: check if tripId or activityId is not valid. (#58)
From 2448d919f1dc23e8dbde3dc72c3e0a80797a8fb9 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 21 Jul 2020 20:12:23 -0500
Subject: [PATCH 19/24] time.js comments.
---
frontend/src/components/Utils/time.js | 28 ++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/frontend/src/components/Utils/time.js b/frontend/src/components/Utils/time.js
index 27eca202..a0e70d01 100644
--- a/frontend/src/components/Utils/time.js
+++ b/frontend/src/components/Utils/time.js
@@ -1,9 +1,10 @@
/**
- * Format a timestamp (in milliseconds) into a pretty string with just the time.
+ * Format a timestamp (in milliseconds) into a pretty string with just the time like
+ * '10.19 AM'.
*
- * @param {int} msTimestamp
- * @param {string} timezone
- * @returns {string} Time formatted into a string like '10:19 AM'.
+ * @param {int} msTimestamp Timestamp in milliseconds of desired date.
+ * @param {string} timezone Timezone in which to convert.
+ * @returns {string} Time formatted into desired pretty string.
*/
export function timestampToTimeFormatted(msTimestamp, timezone = 'America/New_York') {
const date = new Date(msTimestamp);
@@ -17,11 +18,12 @@ export function timestampToTimeFormatted(msTimestamp, timezone = 'America/New_Yo
}
/**
- * Format a timestamp (in milliseconds) into a pretty string with just the date.
+ * Format a timestamp (in milliseconds) into a pretty string with just the date, like
+ * 'Monday, January 19, 1970'.
*
- * @param {int} msTimestamp
- * @param {string} timezone
- * @returns {string} Time formatted into a string like 'Monday, January 19, 1970'.
+ * @param {int} msTimestamp Timestamp in milliseconds of desired date.
+ * @param {string} timezone Timezone in which to convert.
+ * @returns {string} Time formatted into desired pretty string.
*/
export function timestampToDateFormatted(msTimestamp, timezone='America/New_York') {
const date = new Date(msTimestamp);
@@ -37,12 +39,12 @@ export function timestampToDateFormatted(msTimestamp, timezone='America/New_York
}
/**
- * Format a timestamp (in milliseconds) into a pretty string.
+ * Format a timestamp (in milliseconds) into a pretty string like
+ * 'Monday, January 19, 1970, 02:48 AM'.
*
- * @param {int} msTimestamp
- * @param {string} timezone
- * @returns {string} Time formatted into a string like
- * 'Monday, January 19, 1970, 02:48 AM'
+ * @param {int} msTimestamp Timestamp in milliseconds of desired date.
+ * @param {string} timezone Timezone in which to convert.
+ * @returns {string} Time formatted into desired pretty string.
*/
export function timestampToFormatted(msTimestamp, timezone = 'America/New_York') {
let date = new Date(msTimestamp);
From 4c24e687403e06a73d6751b3ce316dda89bd4d79 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 21 Jul 2020 21:03:54 -0500
Subject: [PATCH 20/24] Exhaustive comments
---
.../src/components/ViewActivities/activity.js | 16 ++++++++++------
.../src/components/ViewActivities/activityday.js | 10 +++++-----
.../src/components/ViewActivities/activityfns.js | 12 ++++++------
.../components/ViewActivities/activitylist.js | 13 +++++++------
4 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index dc98f42b..9fa46cae 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -6,7 +6,9 @@ import { getField, writeActivity } from './activityfns.js';
import { Accordion, Button, Card, Col, Form, Row } from 'react-bootstrap';
/**
- * Returns a dropdown of all the timezones.
+ * Return a dropdown of all the timezones.
+ *
+ * @return {HTML} Dropdown of all the timezones.
*/
function timezonePicker() {
// TODO: Make this dropdown. (#51)
@@ -14,14 +16,14 @@ function timezonePicker() {
}
/**
- * A single activity.
+ * React component for a single activity.
*
- * @param {Object} props This component expects the following props:
- * - `activity` {Object} The activity to display.
+ * @property {Object} props ReactJS props.
+ * @property {ActivityInfo} props.activity The activity to display.
* (MUST contain 'id' field with database activity id and 'tripId' field.)
*/
class Activity extends React.Component {
- /** {@inheritdoc} */
+ /** @override */
constructor(props) {
super(props);
@@ -66,6 +68,8 @@ class Activity extends React.Component {
/**
* Set the activity into viewing mode.
+ *
+ * @param {event} event The form's event.
*/
finishEditActivity(event) {
this.setState({editing: false});
@@ -118,7 +122,7 @@ class Activity extends React.Component {
}
}
- /** @inheritdoc */
+ /** @override */
render() {
const activity = this.props.activity;
return (
diff --git a/frontend/src/components/ViewActivities/activityday.js b/frontend/src/components/ViewActivities/activityday.js
index 21b8a2a5..58b221ca 100644
--- a/frontend/src/components/ViewActivities/activityday.js
+++ b/frontend/src/components/ViewActivities/activityday.js
@@ -4,14 +4,14 @@ import * as activityFns from './activityfns.js';
import * as time from '../Utils/time.js'
/**
- * One single day of activities.
+ * React component for a single day of activities.
*
- * @param {Object} props This component expects the following props:
- * - `activities` The list of activities for 'today'.
- * - `date` The date, formatted as 'MM/DD/YYYY'.
+ * @property {Object} props ReactJS props.
+ * @property {ActivityInfo[]} props.activities The list of activities for 'today'.
+ * @property {string} props.date The date, formatted as 'MM/DD/YYYY'.
*/
class ActivityDay extends React.Component {
- /** @inheritdoc */
+ /** @override */
render() {
const sortedActivities = Array.from(this.props.activities)
.sort(activityFns.compareActivities);
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 75f570a9..465533f9 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -6,7 +6,7 @@ const db = app.firestore();
/**
* An activity object.
- * @typedef {Object} Activity
+ * @typedef {Object} ActivityInfo
* @property {string} id The activity's ID in the database.
* @property {string} tripId The activity's tripId in the database.
* @property {string} title The activity's title.
@@ -18,13 +18,13 @@ const db = app.firestore();
/**
* A single activity day. A single instance looks like:
*
['MM/DD/YYYY', [activities on that day]]
- * @typedef {Array.} DayOfActivities
+ * @typedef {Array.} DayOfActivities
*
*/
/**
* Sort a list of trip activities by date.
- * @param {Activity[]} tripActivities Array of activities.
+ * @param {ActivityInfo[]} tripActivities Array of activities.
* @return {DayOfActivities[]} List of trip activities in the form
*
[ , ...]
* in chronological order by date.
@@ -50,8 +50,8 @@ export function sortByDate(tripActivities) {
/**
* Put a and b in display order.
* This function is a comparator.
- * @param {Activity} a Dictionary representing activity a and its fields.
- * @param {Activity} b Dictionary representing activity b and its fields.
+ * @param {ActivityInfo} a Dictionary representing activity a and its fields.
+ * @param {ActivityInfo} b Dictionary representing activity b and its fields.
* @return {int} -1 if a comes before b, else 1.
*/
export function compareActivities(a, b) {
@@ -69,7 +69,7 @@ export function compareActivities(a, b) {
/**
* Get the field of field name fieldName from activity or the default value.
*
- * @param {Activity} activity The activity from which to get the field.
+ * @param {ActivityInfo} activity The activity from which to get the field.
* @param {string} fieldName Name of field to get.
* @param {*} defaultValue Value if field is not found/is null.
* @returns {*} activity[fieldName] if possible, else defaultValue.
diff --git a/frontend/src/components/ViewActivities/activitylist.js b/frontend/src/components/ViewActivities/activitylist.js
index 3adb9f30..9dad6f86 100644
--- a/frontend/src/components/ViewActivities/activitylist.js
+++ b/frontend/src/components/ViewActivities/activitylist.js
@@ -11,6 +11,7 @@ const db = app.firestore();
* Gets the list of activities from the server.
*
* @param {string} tripId The trip ID.
+ * @return {ActivityInfo[]} The list of trip activities.
*/
export async function getActivityList(tripId) {
return new Promise(function(resolve, reject) {
@@ -42,20 +43,20 @@ export async function getActivityList(tripId) {
}
/**
- * The list of activities.
+ * React component for the list of activities.
*
- * @param {Object} props This component expects the following props:
- * - `tripId` {string} The trip's ID.
+ * @param {Object} props ReactJS props.
+ * @param {string} props.tripId The trip's ID.
*/
class ActivityList extends React.Component {
- /** @inheritdoc */
+ /** @override */
constructor(props) {
super(props);
this.state = { days : [] };
}
/**
- * @inheritdoc
+ * @override
*
* Get sorted list of activities from the database.
*
@@ -75,7 +76,7 @@ class ActivityList extends React.Component {
this.setState({days: activityFns.sortByDate(tripActivities)});
}
- /** @inheritdoc */
+ /** @override */
render() {
if (this.state === null) { return (); }
if (this.state.days === null) {
From 26184ff617795fe713869cb7fdf1b363e3d8995a Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Tue, 21 Jul 2020 21:21:39 -0500
Subject: [PATCH 21/24] to
---
frontend/src/components/ViewActivities/activityfns.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 465533f9..327f7e1f 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -52,7 +52,7 @@ export function sortByDate(tripActivities) {
* This function is a comparator.
* @param {ActivityInfo} a Dictionary representing activity a and its fields.
* @param {ActivityInfo} b Dictionary representing activity b and its fields.
- * @return {int} -1 if a comes before b, else 1.
+ * @return {int} -1 if a comes before b, else 1.
*/
export function compareActivities(a, b) {
if (a[DB.ACTIVITIES_START_TIME] < b[DB.ACTIVITIES_START_TIME]) {
@@ -72,7 +72,7 @@ export function compareActivities(a, b) {
* @param {ActivityInfo} activity The activity from which to get the field.
* @param {string} fieldName Name of field to get.
* @param {*} defaultValue Value if field is not found/is null.
- * @returns {*} activity[fieldName] if possible, else defaultValue.
+ * @returns {*} activity[fieldName] if possible, else defaultValue.
*/
export function getField(activity, fieldName, defaultValue){
if (activity[fieldName] === null || activity[fieldName] === undefined) {
@@ -86,8 +86,8 @@ export function getField(activity, fieldName, defaultValue){
*
* @param {string} tripId Database ID of the trip whose actiivty should be modified.
* @param {string} activityId Database ID of the activity to be modified.
- * @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
- * @returns {boolean} true if the write was successful, false otherwise.
+ * @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
+ * @returns {boolean} true if the write was successful, false otherwise.
*/
export async function writeActivity(tripId, activityId, newValues) {
// todo: check if tripId or activityId is not valid. (#58)
From 2e3427d0268da0e708611a7e55e68f83004489f1 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Fri, 24 Jul 2020 17:37:23 -0500
Subject: [PATCH 22/24] address PR comments
---
frontend/src/components/ViewActivities/activity.js | 2 +-
frontend/src/components/ViewActivities/activityday.js | 2 +-
frontend/src/components/ViewActivities/activityfns.js | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index 51c290fe..862102ec 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -111,7 +111,7 @@ class Activity extends React.Component {
{timezonePicker()}
-
+
Description:
{time.timestampToDateFormatted(date.getTime())}
{sortedActivities.map((activity, index) => (
-
+
))}
);
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index c84a3d6e..05898dd6 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -72,7 +72,7 @@ export function compareActivities(a, b) {
* @param {ActivityInfo} activity The activity from which to get the field.
* @param {string} fieldName Name of field to get.
* @param {*} defaultValue Value if field is not found/is null.
- * @returns {*} activity[fieldName] if possible, else defaultValue.
+ * @return {*} activity[fieldName] if possible, else defaultValue.
*/
export function getField(activity, fieldName, defaultValue) {
if (activity[fieldName] === null || activity[fieldName] === undefined) {
@@ -87,7 +87,7 @@ export function getField(activity, fieldName, defaultValue) {
* @param {string} tripId Database ID of the trip whose actiivty should be modified.
* @param {string} activityId Database ID of the activity to be modified.
* @param {Object} newValues Dictionary of the new values in {fieldName: newValue} form
- * @returns {boolean} true if the write was successful, false otherwise.
+ * @return {boolean} true if the write was successful, false otherwise.
*/
export async function writeActivity(tripId, activityId, newValues) {
// todo: check if tripId or activityId is not valid. (#58)
From baf3e3f909432c25b9950d086624a8f68767c4ce Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 27 Jul 2020 17:57:46 -0500
Subject: [PATCH 23/24] remove empty activity problem
---
frontend/src/components/ViewActivities/activityfns.js | 3 +++
1 file changed, 3 insertions(+)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 05898dd6..51f6dda0 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -30,6 +30,9 @@ const db = app.firestore();
* in chronological order by date.
*/
export function sortByDate(tripActivities) {
+ if (tripActivities === undefined) {
+ return null;
+ }
let activities = new Map(); // { MM/DD/YYYY: [activities] }.
for (let activity of tripActivities) {
const activityDate = new Date(activity[DB.ACTIVITIES_START_TIME]);
From bcc3547cb7fe98f3a0711e3added79b4a1069636 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 27 Jul 2020 18:15:08 -0500
Subject: [PATCH 24/24] Proper return of tripActivities for display
---
.../src/components/ViewActivities/activityfns.js | 2 ++
.../src/components/ViewActivities/activitylist.js | 12 ++++++------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index 51f6dda0..c77c6282 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -33,6 +33,7 @@ export function sortByDate(tripActivities) {
if (tripActivities === undefined) {
return null;
}
+ console.log(tripActivities);
let activities = new Map(); // { MM/DD/YYYY: [activities] }.
for (let activity of tripActivities) {
const activityDate = new Date(activity[DB.ACTIVITIES_START_TIME]);
@@ -45,6 +46,7 @@ export function sortByDate(tripActivities) {
}
// Sort activities by date.
+ console.log(activities);
let activitiesSorted = Array.from(activities).sort(compareActivities);
return activitiesSorted;
diff --git a/frontend/src/components/ViewActivities/activitylist.js b/frontend/src/components/ViewActivities/activitylist.js
index 5e5ecd1a..068c0312 100644
--- a/frontend/src/components/ViewActivities/activitylist.js
+++ b/frontend/src/components/ViewActivities/activitylist.js
@@ -16,10 +16,11 @@ const db = app.firestore();
export async function getActivityList(tripId) {
let tripActivities = [];
- db.collection(DB.COLLECTION_TRIPS).doc(tripId)
+ return db.collection(DB.COLLECTION_TRIPS).doc(tripId)
.collection(DB.COLLECTION_ACTIVITIES).get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
+ console.log(doc.data());
let data = doc.data();
data['id'] = doc.id;
data['tripId'] = tripId;
@@ -33,11 +34,9 @@ export async function getActivityList(tripId) {
data[DB.ACTIVITIES_END_TIME]['seconds'] * 1000;
tripActivities.push(data);
- })
- }).catch(error => {
- console.log("It seems that an error has occured.");
- tripActivities = null;
- }).then( () => {return tripActivities} );
+ });
+ return tripActivities;
+ });
}
/**
@@ -72,6 +71,7 @@ class ActivityList extends React.Component {
return;
}
this.setState({days: activityFns.sortByDate(tripActivities)});
+ console.log(this.state.days);
}
/** @override */