+
+
+
+
+ );
+ }
+}
+
+export default EditActivity;
\ No newline at end of file
diff --git a/frontend/src/constants/countries.js b/frontend/src/constants/countries.js
index 0f73357c..0ba54d49 100644
--- a/frontend/src/constants/countries.js
+++ b/frontend/src/constants/countries.js
@@ -1,4 +1,5 @@
// This file contains all the countries and their 2-letter country codes.
+export const topNCountries = 10; // Number of "popular countries" to display first
export const countryCodes = {
"United States Minor Outlying Islands" : "UM",
"United States of America" : "US",
@@ -10,7 +11,6 @@ export const countryCodes = {
"India" : "IN",
"Italy" : "IT",
"Jamaica" : "JM",
-"Sweden" : "SE",
"Andorra" : "AD",
"United Arab Emirates" : "AE",
"Afghanistan" : "AF",
@@ -210,6 +210,7 @@ export const countryCodes = {
"Somalia" : "SO",
"Suriname" : "SR",
"South Sudan" : "SS",
+"Sweden" : "SE",
"Sao Tome and Principe" : "ST",
"El Salvador" : "SV",
"Sint Maarten (Dutch part)" : "SX",
@@ -248,4 +249,5 @@ export const countryCodes = {
"Mayotte" : "YT",
"South Africa" : "ZA",
"Zambia" : "ZM",
-"Zimbabwe" : "ZW"}
\ No newline at end of file
+"Zimbabwe" : "ZW"}
+export const countryList = Object.keys(countryCodes);
\ No newline at end of file
diff --git a/frontend/src/constants/database.js b/frontend/src/constants/database.js
index 77064536..52796c84 100644
--- a/frontend/src/constants/database.js
+++ b/frontend/src/constants/database.js
@@ -4,4 +4,6 @@ export const COLLECTION_ACTIVITIES = 'activities';
export const ACTIVITIES_START_TIME = 'start_time';
export const ACTIVITIES_END_TIME = 'end_time';
export const ACTIVITIES_TITLE = 'title';
-export const ACTIVITIES_DESCRIPTION = 'description';
\ No newline at end of file
+export const ACTIVITIES_DESCRIPTION = 'description';
+export const ACTIVITIES_START_COUNTRY = 'start_country';
+export const ACTIVITIES_END_COUNTRY = 'end_country';
\ No newline at end of file
diff --git a/frontend/src/styles/activities.css b/frontend/src/styles/activities.css
index 67d4ed4d..016d7ea1 100644
--- a/frontend/src/styles/activities.css
+++ b/frontend/src/styles/activities.css
@@ -22,11 +22,11 @@
/* TODO: auto height, transition. (#49)*/
.view-activity.edit {
- height: 20em;
+ height: 35em;
}
.view-activity {
overflow: scroll;
- height: 7.5em;
+ height: 10em;
transition: height 0.25s linear;
}
From 1a2c8244c0b6805075cd810030cd0f73de96c14f Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Thu, 16 Jul 2020 23:51:54 -0500
Subject: [PATCH 05/25] Update comments for countries.js.
---
frontend/src/constants/countries.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/frontend/src/constants/countries.js b/frontend/src/constants/countries.js
index 0ba54d49..15c37e96 100644
--- a/frontend/src/constants/countries.js
+++ b/frontend/src/constants/countries.js
@@ -1,4 +1,6 @@
-// This file contains all the countries and their 2-letter country codes.
+// This file contains all the countries and their 2-letter country codes.
+// It also contains a list of all the countries for which there are accompanying country codes-
+// called countryList. It's at the bottom of this (very long) file.
export const topNCountries = 10; // Number of "popular countries" to display first
export const countryCodes = {
"United States Minor Outlying Islands" : "UM",
@@ -250,4 +252,4 @@ export const countryCodes = {
"South Africa" : "ZA",
"Zambia" : "ZM",
"Zimbabwe" : "ZW"}
-export const countryList = Object.keys(countryCodes);
\ No newline at end of file
+export const countryList = Object.keys(countryCodes);
From a757ccde24c96dd1f0f9ac85d55c4db828b199b2 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Thu, 16 Jul 2020 23:54:00 -0500
Subject: [PATCH 06/25] Update editActivity.js's comments.
---
frontend/src/components/ViewActivities/editActivity.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js
index 5c081ac0..193f0b5f 100644
--- a/frontend/src/components/ViewActivities/editActivity.js
+++ b/frontend/src/components/ViewActivities/editActivity.js
@@ -10,7 +10,7 @@ import * as time from '../Utils/time.js';
*
* @param {Object} props This component expects the following props:
* - `activity` The activity to display.
- * - `submitFunction` The function to run upon submission.
+ * - `submitFunction` The function to run upon submission to trigger card flip.
*/
class EditActivity extends React.Component {
/** @inheritdoc */
@@ -59,7 +59,7 @@ class EditActivity extends React.Component {
}
}
- /** Runs when the `submit` button is pressed. */
+ /** Runs when the `submit` button on the form is pressed. */
finishEditActivity(event) {
event.preventDefault();
this.editActivity();
@@ -72,7 +72,7 @@ class EditActivity extends React.Component {
/**
* Returns a dropdown of all the timezones.
*
- * @param st either "start" or "end"
+ * @param st either "start" or "end" depending on whether the timezone is for the start or end timezone.
*/
timezonePicker(st) {
console.log(this.state.startTz);
@@ -90,7 +90,7 @@ class EditActivity extends React.Component {
)
}
/**
- * Create a dropdown of all the countries
+ * Create a dropdown of all the countries.
*
* @param ref The reference to attach to the dropdown.
* @param tzchange The function to run to update the time zone picker.
@@ -151,4 +151,4 @@ class EditActivity extends React.Component {
}
}
-export default EditActivity;
\ No newline at end of file
+export default EditActivity;
From a8d3af6135542c431849b2d8afd5b8c5ca43a86b Mon Sep 17 00:00:00 2001
From: ananyay <14322650+ananyeet@users.noreply.github.com>
Date: Fri, 17 Jul 2020 00:02:52 -0500
Subject: [PATCH 07/25] Update new location in server, display properly.
---
frontend/src/components/ViewActivities/activity.js | 4 ++--
frontend/src/components/ViewActivities/editActivity.js | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js
index 8626f882..794f3a92 100644
--- a/frontend/src/components/ViewActivities/activity.js
+++ b/frontend/src/components/ViewActivities/activity.js
@@ -48,9 +48,9 @@ class Activity extends React.Component {
Start time: {time.timestampToFormatted(activity[DB.ACTIVITIES_START_TIME])}
- {utils.getField(activity, DB.ACTIVITIES_START_COUNTRY, "", " at ")}
+ {utils.getField(activity, DB.ACTIVITIES_START_COUNTRY, '', ' at ')}
End time: {time.timestampToFormatted(activity[DB.ACTIVITIES_END_TIME])}
- {utils.getField(activity, DB.ACTIVITIES_END_COUNTRY, "", " at ")}
+ {utils.getField(activity, DB.ACTIVITIES_END_COUNTRY, '', ' at ')}
);
} else { // Edit mode.
diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js
index c0123889..ecb08b91 100644
--- a/frontend/src/components/ViewActivities/activityfns.js
+++ b/frontend/src/components/ViewActivities/activityfns.js
@@ -54,7 +54,7 @@ export function compareActivities(a, b) {
* @param prefix The prefix to put before a returned value if the field exists.
* @returns `activity[fieldName]` if possible, else `defaultValue`.
*/
-export function getField(activity, fieldName, defaultValue, prefix=""){
+export function getField(activity, fieldName, defaultValue, prefix=''){
if (activity[fieldName] === null || activity[fieldName] === undefined) {
return defaultValue;
}
diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js
index 6356b3e8..97f26ed0 100644
--- a/frontend/src/components/ViewActivities/editActivity.js
+++ b/frontend/src/components/ViewActivities/editActivity.js
@@ -72,14 +72,14 @@ class EditActivity extends React.Component {
/**
* Returns a dropdown of all the timezones.
*
- * @param st either "start" or "end" depending on whether the timezone is for the start or end timezone.
+ * @param st either 'start' or 'end' depending on whether the timezone is for the start or end timezone.
*/
timezonePicker(st) {
return (
)
@@ -92,7 +102,6 @@ class EditActivity extends React.Component {
* Create a dropdown of all the countries.
*
* @param ref The reference to attach to the dropdown.
- * @param tzchange The function to run to update the time zone picker.
*/
countriesDropdown(ref, tzref) {
return (
From ef67a440a93938cc4124003bab599ada3b44e8b4 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 20 Jul 2020 12:29:03 -0500
Subject: [PATCH 12/25] Update comments.
---
frontend/src/components/ViewActivities/editActivity.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js
index 81868dbf..d6b87dc4 100644
--- a/frontend/src/components/ViewActivities/editActivity.js
+++ b/frontend/src/components/ViewActivities/editActivity.js
@@ -73,7 +73,10 @@ class EditActivity extends React.Component {
/**
* Returns a dropdown of all the timezones.
*
- * @param st either 'start' or 'end' depending on whether the timezone is for the start or end timezone.
+ * @param st either 'start' or 'end' depending on whether the
+ * timezone is for the start or end timezone.
+ *
+ * Tests done manually via UI.
*/
timezonePicker(st) {
let ref = st === 'start' ? this.editStartLocRef : this.editEndLocRef;
From 1b937238d20be7351ea4ee42780f6f436bb98f4b Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 20 Jul 2020 19:41:14 -0500
Subject: [PATCH 13/25] Address comment about tz.names()
---
frontend/src/components/Utils/time.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/components/Utils/time.js b/frontend/src/components/Utils/time.js
index 7393e549..2615403c 100644
--- a/frontend/src/components/Utils/time.js
+++ b/frontend/src/components/Utils/time.js
@@ -73,7 +73,7 @@ export function timezonesForCountry(countryName) {
const countryCode = countryCodes[countryName];
zones = moment.tz.zonesForCountry(countryCode);
} catch (e) {
- zones = moment.tz.names();
+ zones = moment.tz.names(); // List of all timezones.
}
return zones.map(e => {
return e.replace(/[_]/g, ' ');
From fefb216c2298f2402e78420da75efc8703f0b1dd Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 20 Jul 2020 19:41:23 -0500
Subject: [PATCH 14/25] remove space
---
frontend/src/components/ViewActivities/editActivity.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js
index d6b87dc4..bc965b09 100644
--- a/frontend/src/components/ViewActivities/editActivity.js
+++ b/frontend/src/components/ViewActivities/editActivity.js
@@ -119,7 +119,6 @@ class EditActivity extends React.Component {
);
}
-
render() {
const activity = this.props.activity;
const TITLEWIDTH = 3;
From cef101d68093a3309fac97fd92772a1d0ca345a8 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 20 Jul 2020 19:48:41 -0500
Subject: [PATCH 15/25] Update comments to reflect content.
---
.../components/ViewActivities/editActivity.js | 24 ++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js
index bc965b09..8f58c204 100644
--- a/frontend/src/components/ViewActivities/editActivity.js
+++ b/frontend/src/components/ViewActivities/editActivity.js
@@ -6,7 +6,7 @@ import { countryList } from '../../constants/countries.js';
import * as time from '../Utils/time.js';
/**
- * The form that's used when the user is editing an activity
+ * The form that's used when the user is editing an activity.
*
* @param {Object} props This component expects the following props:
* - `activity` The activity to display.
@@ -22,7 +22,7 @@ class EditActivity extends React.Component {
// Bind state users/modifiers to `this`.
this.editActivity = this.editActivity.bind(this);
this.finishEditActivity = this.finishEditActivity.bind(this);
- this.timezonePicker = this.timezonePicker.bind(this);
+ this.timezoneDropdown = this.timezoneDropdown.bind(this);
// References.
this.editTitleRef = React.createRef();
@@ -67,18 +67,22 @@ class EditActivity extends React.Component {
this.props.submitFunction();
}
+ // "Flip switch" on timezone dropdown so the dropdown's contents update to the
+ // selected country's timezones.
startTimeTzUpdate = () => { this.setState({startTz : !this.state.startTz})};
endTimeTzUpdate = () => { this.setState({endTz : !this.state.endTz})};
/**
* Returns a dropdown of all the timezones.
+ * The dropdown's values change based on the corrresponding country dropdown to
+ * reduce scrolling and ensure that the location corresponds to the time zone.
*
- * @param st either 'start' or 'end' depending on whether the
+ * @param st Either 'start' or 'end' depending on whether the
* timezone is for the start or end timezone.
*
- * Tests done manually via UI.
+ * Tests done manually using UI.
*/
- timezonePicker(st) {
+ timezoneDropdown(st) {
let ref = st === 'start' ? this.editStartLocRef : this.editEndLocRef;
let dbEntry = st === 'start' ? DB.ACTIVITIES_START_COUNTRY : DB.ACTIVITIES_END_COUNTRY;
let timezones;
@@ -102,9 +106,13 @@ class EditActivity extends React.Component {
)
}
/**
- * Create a dropdown of all the countries.
+ * Create a dropdown of all the countries.
+ * This dropdown is linked to the corresponding timezone dropdown,
+ * so when the country changes here, the values in the timezone dropdown
+ * change as well.
*
* @param ref The reference to attach to the dropdown.
+ * @param tzref The corresponding time zone reference field.
*/
countriesDropdown(ref, tzref) {
return (
@@ -144,13 +152,13 @@ class EditActivity extends React.Component {
From:
-
{this.timezonePicker('start')}
+
{this.timezoneDropdown('start')}
To:
-
{this.timezonePicker('end')}
+
{this.timezoneDropdown('end')}
Description:
From 3fa333c1d18a33abf1e6bd955b42d826738d2ec0 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 20 Jul 2020 19:49:43 -0500
Subject: [PATCH 16/25] Update comments.
---
frontend/src/components/ViewActivities/editActivity.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js
index 8f58c204..3b1f39b6 100644
--- a/frontend/src/components/ViewActivities/editActivity.js
+++ b/frontend/src/components/ViewActivities/editActivity.js
@@ -77,10 +77,11 @@ class EditActivity extends React.Component {
* The dropdown's values change based on the corrresponding country dropdown to
* reduce scrolling and ensure that the location corresponds to the time zone.
*
+ * Tests done manually using UI.
+ *
* @param st Either 'start' or 'end' depending on whether the
* timezone is for the start or end timezone.
- *
- * Tests done manually using UI.
+ * @returns HTML dropdown item.
*/
timezoneDropdown(st) {
let ref = st === 'start' ? this.editStartLocRef : this.editEndLocRef;
@@ -93,7 +94,6 @@ class EditActivity extends React.Component {
timezones = time.timezonesForCountry(ref.current.value);
}
return (
-
{item});
})}
-
)
}
/**
From 4ba6c7edc80e6724a987f157392165fe916c7717 Mon Sep 17 00:00:00 2001
From: Ananya Y <14322650+ananyeet@users.noreply.github.com>
Date: Mon, 20 Jul 2020 22:24:18 -0500
Subject: [PATCH 17/25] Modularize form elements.
---
.../components/ViewActivities/editActivity.js | 82 +++++++++++--------
.../editActivityFormElements.js | 76 +++++++++++++++++
2 files changed, 122 insertions(+), 36 deletions(-)
create mode 100644 frontend/src/components/ViewActivities/editActivityFormElements.js
diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js
index 3b1f39b6..4f558a42 100644
--- a/frontend/src/components/ViewActivities/editActivity.js
+++ b/frontend/src/components/ViewActivities/editActivity.js
@@ -4,6 +4,7 @@ import { getField, writeActivity } from './activityfns.js';
import * as DB from '../../constants/database.js'
import { countryList } from '../../constants/countries.js';
import * as time from '../Utils/time.js';
+import * as formElements from './editActivityFormElements.js';
/**
* The form that's used when the user is editing an activity.
@@ -127,45 +128,54 @@ class EditActivity extends React.Component {
}
render() {
- const activity = this.props.activity;
const TITLEWIDTH = 3;
- const COUNTRYWIDTH = 6;
- const DATEWIDTH = 4;
- const TIMEWIDTH = 2;
- const TZPICKERWIDTH = 3;
+const COUNTRYWIDTH = 6;
+const DATEWIDTH = 4;
+const TIMEWIDTH = 2;
+const TZPICKERWIDTH = 3;
+ const activity = this.props.activity;
return (
-
-
-
+ {formElements.textElementFormGroup(
+ 'formActivityTitle', // controlId
+ 'Title:', // formLabel
+ activity[DB.ACTIVITIES_TITLE],// placeHolder
+ this.editTitleRef // ref
+ )}
+ {formElements.locationElementFormGroup(
+ 'formActivityStartLocation', // controlId
+ 'Start Location:', // formLabel
+ this.countriesDropdown(this.editStartLocRef, this.startTimeTzUpdate)
+ )}
+ {formElements.locationElementFormGroup(
+ 'formActivityEndLocation', // controlId
+ 'End Location:', // formLabel
+ this.countriesDropdown(this.editEndLocRef, this.endTimeTzUpdate)
+ )}
+ {formElements.dateTimeTzFormGroup(
+ 'formActivityStartTime', // controlId
+ 'From:', // formLabel
+ this.editStartDateRef, // dateRef
+ null, // dateDefault
+ this.editStartTimeRef, // timeRef,
+ null, //timeDefault,
+ this.timezoneDropdown('start') // tzpicker
+ )}
+ {formElements.dateTimeTzFormGroup(
+ 'formActivityEndTime', // controlId
+ 'To:', // formLabel
+ this.editEndDateRef, // dateRef
+ null, // dateDefault
+ this.editEndTimeRef, // timeRef,
+ null, //timeDefault,
+ this.timezoneDropdown('end') // tzpicker
+ )}
+ {formElements.textElementFormGroup(
+ 'formActivityDescription', // controlId
+ 'Description:', // formLabel
+ getField(activity, DB.ACTIVITIES_DESCRIPTION, 'Add some details!'), // placeHolder
+ this.editDescriptionRef // ref
+ )}
);
diff --git a/frontend/src/components/ViewActivities/editActivityFormElements.js b/frontend/src/components/ViewActivities/editActivityFormElements.js
new file mode 100644
index 00000000..b864f2ba
--- /dev/null
+++ b/frontend/src/components/ViewActivities/editActivityFormElements.js
@@ -0,0 +1,76 @@
+import React from 'react';
+import { Button, Col, Form, Row } from 'react-bootstrap';
+
+// This file waas written after #87 was created.
+// As a result, some fields and functions may not be used yet.
+const TITLEWIDTH = 3;
+const COUNTRYWIDTH = 6;
+const DATEWIDTH = 4;
+const TIMEWIDTH = 2;
+const TZPICKERWIDTH = 3;
+
+/**
+ * Create a Text element Form Group for the editActivity form.
+ *
+ * @param {string} controlId FormGroup's control ID.
+ * @param {string} formLabel The label of the field for this FormGroup.
+ * @param {string} placeHolder The input's placeholder.
+ * @param {ref} ref The input's reference.
+ * @returns A text element form group.
+ */
+export function textElementFormGroup(controlId, formLabel, placeHolder, ref) {
+ return (
+
+
{formLabel}
+
+
+
+
+ );
+}
+
+/**
+ * Create a Location Dropdown element Form Group for the editActivity form.
+ *
+ * @param {string} controlId FormGroup's control ID.
+ * @param {string} formLabel The label of the field for this FormGroup.
+ * @param {string} dropdown The dropdown.
+ * @returns a location dropdown form group.
+ */
+export function locationElementFormGroup(controlId, formLabel, dropdown) {
+ return (
+
+