From a9ebfb4f2dd30c280f9bfcb63d85abe90339ea24 Mon Sep 17 00:00:00 2001 From: ananyay <14322650+ananyeet@users.noreply.github.com> Date: Thu, 16 Jul 2020 21:59:30 -0500 Subject: [PATCH 01/25] momentjs install --- frontend/package-lock.json | 13 +++++++++++++ frontend/package.json | 1 + 2 files changed, 14 insertions(+) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 6943250b..dbcedaa7 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -8613,6 +8613,19 @@ "minimist": "^1.2.5" } }, + "moment": { + "version": "2.27.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.27.0.tgz", + "integrity": "sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ==" + }, + "moment-timezone": { + "version": "0.5.31", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.31.tgz", + "integrity": "sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==", + "requires": { + "moment": ">= 2.9.0" + } + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index d0074f35..4fe5bb54 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,6 +8,7 @@ "@testing-library/user-event": "^7.2.1", "bootstrap": "^4.5.0", "firebase": "^7.15.5", + "moment-timezone": "^0.5.31", "react": "^16.13.1", "react-bootstrap": "^1.0.1", "react-dom": "^16.13.1", From 6ee79edb3de3861f5461ffed7101d70f4745ecc1 Mon Sep 17 00:00:00 2001 From: ananyay <14322650+ananyeet@users.noreply.github.com> Date: Thu, 16 Jul 2020 21:59:45 -0500 Subject: [PATCH 02/25] 2-letter codes --- frontend/src/constants/countries.js | 251 ++++++++++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 frontend/src/constants/countries.js diff --git a/frontend/src/constants/countries.js b/frontend/src/constants/countries.js new file mode 100644 index 00000000..0f73357c --- /dev/null +++ b/frontend/src/constants/countries.js @@ -0,0 +1,251 @@ +// This file contains all the countries and their 2-letter country codes. +export const countryCodes = { +"United States Minor Outlying Islands" : "UM", +"United States of America" : "US", +"Denmark" : "DK", +"Spain" : "ES", +"France" : "FR", +"Greece" : "GR", +"Ireland" : "IE", +"India" : "IN", +"Italy" : "IT", +"Jamaica" : "JM", +"Sweden" : "SE", +"Andorra" : "AD", +"United Arab Emirates" : "AE", +"Afghanistan" : "AF", +"Antigua and Barbuda" : "AG", +"Anguilla" : "AI", +"Albania" : "AL", +"Armenia" : "AM", +"Angola" : "AO", +"Antarctica" : "AQ", +"Argentina" : "AR", +"American Samoa" : "AS", +"Austria" : "AT", +"Australia" : "AU", +"Aruba" : "AW", +"Åland Islands" : "AX", +"Azerbaijan" : "AZ", +"Bosnia and Herzegovina" : "BA", +"Barbados" : "BB", +"Bangladesh" : "BD", +"Belgium" : "BE", +"Burkina Faso" : "BF", +"Bulgaria" : "BG", +"Bahrain" : "BH", +"Burundi" : "BI", +"Benin" : "BJ", +"Saint Barthélemy" : "BL", +"Bermuda" : "BM", +"Brunei Darussalam" : "BN", +"Bolivia (Plurinational State of)" : "BO", +"Bonaire, Sint Eustatius and Saba" : "BQ", +"Brazil" : "BR", +"Bahamas" : "BS", +"Bhutan" : "BT", +"Bouvet Island" : "BV", +"Botswana" : "BW", +"Belarus" : "BY", +"Belize" : "BZ", +"Canada" : "CA", +"Cocos (Keeling) Islands" : "CC", +"Congo (the Democratic Republic of the)" : "CD", +"Central African Republic" : "CF", +"Congo" : "CG", +"Switzerland" : "CH", +"Côte d'Ivoire" : "CI", +"Cook Islands" : "CK", +"Chile" : "CL", +"Cameroon" : "CM", +"China" : "CN", +"Colombia" : "CO", +"Costa Rica" : "CR", +"Cuba" : "CU", +"Cabo Verde" : "CV", +"Curaçao" : "CW", +"Christmas Island" : "CX", +"Cyprus" : "CY", +"Czechia" : "CZ", +"Germany" : "DE", +"Djibouti" : "DJ", +"Dominica" : "DM", +"Dominican Republic" : "DO", +"Algeria" : "DZ", +"Ecuador" : "EC", +"Estonia" : "EE", +"Egypt" : "EG", +"Western Sahara" : "EH", +"Eritrea" : "ER", +"Ethiopia" : "ET", +"Finland" : "FI", +"Fiji" : "FJ", +"Falkland Islands [Malvinas]" : "FK", +"Micronesia (Federated States of)" : "FM", +"Faroe Islands" : "FO", +"Gabon" : "GA", +"United Kingdom of Great Britain and Northern Ireland" : "GB", +"Grenada" : "GD", +"Georgia" : "GE", +"French Guiana" : "GF", +"Guernsey" : "GG", +"Ghana" : "GH", +"Gibraltar" : "GI", +"Greenland" : "GL", +"Gambia" : "GM", +"Guinea" : "GN", +"Guadeloupe" : "GP", +"Equatorial Guinea" : "GQ", +"South Georgia and the South Sandwich Islands" : "GS", +"Guatemala" : "GT", +"Guam" : "GU", +"Guinea-Bissau" : "GW", +"Guyana" : "GY", +"Hong Kong" : "HK", +"Heard Island and McDonald Islands" : "HM", +"Honduras" : "HN", +"Croatia" : "HR", +"Haiti" : "HT", +"Hungary" : "HU", +"Indonesia" : "ID", +"Israel" : "IL", +"Isle of Man" : "IM", +"British Indian Ocean Territory" : "IO", +"Iraq" : "IQ", +"Iran (Islamic Republic of)" : "IR", +"Iceland" : "IS", +"Jersey" : "JE", +"Jordan" : "JO", +"Japan" : "JP", +"Kenya" : "KE", +"Kyrgyzstan" : "KG", +"Cambodia" : "KH", +"Kiribati" : "KI", +"Comoros" : "KM", +"Saint Kitts and Nevis" : "KN", +"Korea (the Democratic People's Republic of)" : "KP", +"Korea (the Republic of)" : "KR", +"Kuwait" : "KW", +"Cayman Islands" : "KY", +"Kazakhstan" : "KZ", +"Lao People's Democratic Republic" : "LA", +"Lebanon" : "LB", +"Saint Lucia" : "LC", +"Liechtenstein" : "LI", +"Sri Lanka" : "LK", +"Liberia" : "LR", +"Lesotho" : "LS", +"Lithuania" : "LT", +"Luxembourg" : "LU", +"Latvia" : "LV", +"Libya" : "LY", +"Morocco" : "MA", +"Monaco" : "MC", +"Moldova (the Republic of)" : "MD", +"Montenegro" : "ME", +"Saint Martin (French part)" : "MF", +"Madagascar" : "MG", +"Marshall Islands" : "MH", +"Republic of North Macedonia" : "MK", +"Mali" : "ML", +"Myanmar" : "MM", +"Mongolia" : "MN", +"Macao" : "MO", +"Northern Mariana Islands" : "MP", +"Martinique" : "MQ", +"Mauritania" : "MR", +"Montserrat" : "MS", +"Malta" : "MT", +"Mauritius" : "MU", +"Maldives" : "MV", +"Malawi" : "MW", +"Mexico" : "MX", +"Malaysia" : "MY", +"Mozambique" : "MZ", +"Namibia" : "NA", +"New Caledonia" : "NC", +"Niger" : "NE", +"Norfolk Island" : "NF", +"Nigeria" : "NG", +"Nicaragua" : "NI", +"Netherlands" : "NL", +"Norway" : "NO", +"Nepal" : "NP", +"Nauru" : "NR", +"Niue" : "NU", +"New Zealand" : "NZ", +"Oman" : "OM", +"Panama" : "PA", +"Peru" : "PE", +"French Polynesia" : "PF", +"Papua New Guinea" : "PG", +"Philippines" : "PH", +"Pakistan" : "PK", +"Poland" : "PL", +"Saint Pierre and Miquelon" : "PM", +"Pitcairn" : "PN", +"Puerto Rico" : "PR", +"Palestine, State of" : "PS", +"Portugal" : "PT", +"Palau" : "PW", +"Paraguay" : "PY", +"Qatar" : "QA", +"Réunion" : "RE", +"Romania" : "RO", +"Serbia" : "RS", +"Russian Federation" : "RU", +"Rwanda" : "RW", +"Saudi Arabia" : "SA", +"Solomon Islands" : "SB", +"Seychelles" : "SC", +"Sudan" : "SD", +"Singapore" : "SG", +"Saint Helena, Ascension and Tristan da Cunha" : "SH", +"Slovenia" : "SI", +"Svalbard and Jan Mayen" : "SJ", +"Slovakia" : "SK", +"Sierra Leone" : "SL", +"San Marino" : "SM", +"Senegal" : "SN", +"Somalia" : "SO", +"Suriname" : "SR", +"South Sudan" : "SS", +"Sao Tome and Principe" : "ST", +"El Salvador" : "SV", +"Sint Maarten (Dutch part)" : "SX", +"Syrian Arab Republic" : "SY", +"Eswatini" : "SZ", +"Turks and Caicos Islands" : "TC", +"Chad" : "TD", +"French Southern Territories" : "TF", +"Togo" : "TG", +"Thailand" : "TH", +"Tajikistan" : "TJ", +"Tokelau" : "TK", +"Timor-Leste" : "TL", +"Turkmenistan" : "TM", +"Tunisia" : "TN", +"Tonga" : "TO", +"Turkey" : "TR", +"Trinidad and Tobago" : "TT", +"Tuvalu" : "TV", +"Taiwan (Province of China)" : "TW", +"Tanzania, United Republic of" : "TZ", +"Ukraine" : "UA", +"Uganda" : "UG", +"Uruguay" : "UY", +"Uzbekistan" : "UZ", +"Holy See" : "VA", +"Saint Vincent and the Grenadines" : "VC", +"Venezuela (Bolivarian Republic of)" : "VE", +"Virgin Islands (British)" : "VG", +"Virgin Islands (U.S.)" : "VI", +"Viet Nam" : "VN", +"Vanuatu" : "VU", +"Wallis and Futuna" : "WF", +"Samoa" : "WS", +"Yemen" : "YE", +"Mayotte" : "YT", +"South Africa" : "ZA", +"Zambia" : "ZM", +"Zimbabwe" : "ZW"} \ No newline at end of file From 793510c19c71f6839efad24d5237d5db676850ec Mon Sep 17 00:00:00 2001 From: ananyay <14322650+ananyeet@users.noreply.github.com> Date: Thu, 16 Jul 2020 22:10:24 -0500 Subject: [PATCH 03/25] timezones for country --- frontend/src/components/Utils/time.js | 21 +++++++++++++++++++++ frontend/src/components/Utils/time.test.js | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/frontend/src/components/Utils/time.js b/frontend/src/components/Utils/time.js index 27eca202..45dd3d5b 100644 --- a/frontend/src/components/Utils/time.js +++ b/frontend/src/components/Utils/time.js @@ -1,3 +1,5 @@ +import * as moment from 'moment-timezone'; +import { countryCodes } from '../../constants/countries.js'; /** * Format a timestamp (in milliseconds) into a pretty string with just the time. * @@ -58,3 +60,22 @@ export function timestampToFormatted(msTimestamp, timezone = 'America/New_York') let formatted = date.toLocaleString('en-US', formatOptions); return formatted; } + +/** + * Returns all the time zones in a country (in pretty format). + * + * @param {string} countryName The name of the country for which to get the time zones. + * @returns The list of time zones in the provided country. + */ +export function timezonesForCountry(countryName) { + let zones; + try { + const countryCode = countryCodes[countryName]; + zones = moment.tz.zonesForCountry(countryCode); + } catch (e) { + zones = moment.tz.names(); + } + return zones.map(e => { + return e.replace(/[_]/g, " "); + }); +} \ No newline at end of file diff --git a/frontend/src/components/Utils/time.test.js b/frontend/src/components/Utils/time.test.js index d954ecb6..cf6cfec4 100644 --- a/frontend/src/components/Utils/time.test.js +++ b/frontend/src/components/Utils/time.test.js @@ -56,3 +56,25 @@ test('other full timestamp format', () => { expect(actualCentral).toEqual(expectedCentral); expect(actualSingapore).toEqual(expectedSingapore); }) + +describe('timezones for country', () => { + test('legit country no spaces', () => { + const actual = utils.timezonesForCountry("China"); + const expected = ["Asia/Shanghai", "Asia/Urumqi"]; + expect(actual.sort()).toBe(expected.sort()); + }) + + test('legit country, yes spaces', () => { + const actual = utils.timezonesForCountry("United States of America"); + expect(actual).toContain("America/Anchorage"); + expect(actual).toContain("America/New York"); + expect(actual).not.toContain("Africa/Accra"); + }) + + test('not legit country (spaces and non spaces)', () => { + const actual = utils.timezonesForCountry("MURICA"); + expect(actual).toContain("America/New York"); + expect(actual).toContain("Europe/Paris"); + expect(actual).toContain("Africa/Accra"); + }) +}) \ No newline at end of file From ab21cdd7540db8d94aaebe3c23d7a38eb2963476 Mon Sep 17 00:00:00 2001 From: ananyay <14322650+ananyeet@users.noreply.github.com> Date: Thu, 16 Jul 2020 23:41:22 -0500 Subject: [PATCH 04/25] time dropdown --- frontend/src/components/Utils/time.test.js | 2 +- .../src/components/ViewActivities/activity.js | 80 ++------- .../components/ViewActivities/activityfns.js | 5 +- .../ViewActivities/activityfns.test.js | 2 + .../components/ViewActivities/editActivity.js | 154 ++++++++++++++++++ frontend/src/constants/countries.js | 6 +- frontend/src/constants/database.js | 4 +- frontend/src/styles/activities.css | 4 +- 8 files changed, 179 insertions(+), 78 deletions(-) create mode 100644 frontend/src/components/ViewActivities/editActivity.js diff --git a/frontend/src/components/Utils/time.test.js b/frontend/src/components/Utils/time.test.js index cf6cfec4..935a1b15 100644 --- a/frontend/src/components/Utils/time.test.js +++ b/frontend/src/components/Utils/time.test.js @@ -61,7 +61,7 @@ describe('timezones for country', () => { test('legit country no spaces', () => { const actual = utils.timezonesForCountry("China"); const expected = ["Asia/Shanghai", "Asia/Urumqi"]; - expect(actual.sort()).toBe(expected.sort()); + expect(new Set(actual.sort())).toEqual(new Set(expected.sort())); }) test('legit country, yes spaces', () => { diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js index 05ac9e0e..8626f882 100644 --- a/frontend/src/components/ViewActivities/activity.js +++ b/frontend/src/components/ViewActivities/activity.js @@ -2,22 +2,15 @@ import React from 'react'; import * as time from '../Utils/time.js'; import * as DB from '../../constants/database.js' import '../../styles/activities.css'; -import { getField, writeActivity } from './activityfns.js'; -import { Accordion, Button, Card, Col, Form, Row } from 'react-bootstrap'; - -/** - * Returns a dropdown of all the timezones. - */ -function timezonePicker() { - // TODO: Make this dropdown. (#51) - return
-} +import EditActivity from './editActivity.js'; +import { Accordion, Card } from 'react-bootstrap'; +import * as utils from './activityfns.js'; /** * A single activity. * * @param {Object} props This component expects the following props: - * - `activity` {Object} The activity to display. + * - `activity` The activity to display. * (MUST contain 'id' field with database activity id and 'tripId' field.) */ class Activity extends React.Component { @@ -31,32 +24,6 @@ class Activity extends React.Component { this.setEditActivity = this.setEditActivity.bind(this); this.finishEditActivity = this.finishEditActivity.bind(this); this.displayCard = this.displayCard.bind(this); - this.editActivity = this.editActivity.bind(this); - - // References. - this.editTitleRef = React.createRef(); - this.editStartDateRef = React.createRef(); - this.editEndDateRef = React.createRef(); - this.editStartTimeRef = React.createRef(); - this.editEndTimeRef = React.createRef(); - this.editDescriptionRef = React.createRef(); - } - - /** - * Edit an activity in the database upon form submission. - * TODO: Update times as well! This only does the text field forms (#64). - */ - editActivity() { - let newVals = {}; - if (this.editTitleRef.current.value !== '') { - newVals[DB.ACTIVITIES_TITLE] = this.editTitleRef.current.value; - } - if (this.editDescriptionRef.current.value !== '') { - newVals[DB.ACTIVITIES_DESCRIPTION] = this.editDescriptionRef.current.value; - } - if (Object.keys(newVals).length !== 0) { - writeActivity(this.props.activity.tripId, this.props.activity.id, newVals); - } } /** @@ -69,8 +36,6 @@ class Activity extends React.Component { */ finishEditActivity(event) { this.setState({editing: false}); - event.preventDefault(); - this.editActivity(); }; /** @@ -81,40 +46,15 @@ class Activity extends React.Component { if (!this.state.editing) { // View mode. return ( -

Start time: {time.timestampToFormatted(activity[DB.ACTIVITIES_START_TIME])}

-

End time: {time.timestampToFormatted(activity[DB.ACTIVITIES_END_TIME])}

+

{utils.getField(activity, DB.ACTIVITIES_DESCRIPTION, "")}

+

Start time: {time.timestampToFormatted(activity[DB.ACTIVITIES_START_TIME])} + {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 ")}

); } else { // Edit mode. - return ( - // TODO: Save form. (#48) -
- - Title: - - - - From: - - - {timezonePicker()} - - - To: - - - {timezonePicker()} - - - Description: - - - - -
- ) + return ( ); } } diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js index 37c62926..c0123889 100644 --- a/frontend/src/components/ViewActivities/activityfns.js +++ b/frontend/src/components/ViewActivities/activityfns.js @@ -51,13 +51,14 @@ export function compareActivities(a, b) { * @param {Object} activity * @param {string} fieldName * @param defaultValue + * @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){ +export function getField(activity, fieldName, defaultValue, prefix=""){ if (activity[fieldName] === null || activity[fieldName] === undefined) { return defaultValue; } - return activity[fieldName]; + return prefix + activity[fieldName]; } /** diff --git a/frontend/src/components/ViewActivities/activityfns.test.js b/frontend/src/components/ViewActivities/activityfns.test.js index 99d82ade..1295b5d8 100644 --- a/frontend/src/components/ViewActivities/activityfns.test.js +++ b/frontend/src/components/ViewActivities/activityfns.test.js @@ -96,4 +96,6 @@ test('getField', () => { const activity = {field1: 'yes'}; expect(activityFns.getField(activity, 'field1', 'nooo')).toBe('yes'); expect(activityFns.getField(activity, 'field2', 4)).toBe(4); + expect(activityFns.getField(activity, 'field1', 'nooo', 'aww ')).toBe('aww yes'); + expect(activityFns.getField(activity, 'field2', 4, ' and')).toBe(4); }) \ No newline at end of file diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js new file mode 100644 index 00000000..5c081ac0 --- /dev/null +++ b/frontend/src/components/ViewActivities/editActivity.js @@ -0,0 +1,154 @@ +import React from 'react'; +import { Button, Col, Form, Row } from 'react-bootstrap'; +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'; + +/** + * 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. + * - `submitFunction` The function to run upon submission. + */ +class EditActivity extends React.Component { + /** @inheritdoc */ + constructor(props){ + super(props); + + this.state = {startTz: false, endTz: false}; + + // Bind state users/modifiers to `this`. + this.editActivity = this.editActivity.bind(this); + this.finishEditActivity = this.finishEditActivity.bind(this); + + // References. + this.editTitleRef = React.createRef(); + this.editStartDateRef = React.createRef(); + this.editEndDateRef = React.createRef(); + this.editStartTimeRef = React.createRef(); + this.editEndTimeRef = React.createRef(); + this.editDescriptionRef = React.createRef(); + this.editStartLocRef = React.createRef(); + this.editEndLocRef = React.createRef(); + this.startTz = React.createRef(); + this.endTz = React.createRef(); + } + + /** + * Edit an activity in the database upon form submission. + * TODO: Update times as well! This only does the text field forms (#64). + */ + editActivity() { + let newVals = {}; + if (this.editTitleRef.current.value !== '') { + newVals[DB.ACTIVITIES_TITLE] = this.editTitleRef.current.value; + } + if (this.editDescriptionRef.current.value !== '') { + newVals[DB.ACTIVITIES_DESCRIPTION] = this.editDescriptionRef.current.value; + } + if (this.editStartLocRef.current.value !== ''){ + newVals[DB.ACTIVITIES_START_COUNTRY] = this.editStartLocRef.current.value; + } + if (this.editEndLocRef.current.value !== ''){ + newVals[DB.ACTIVITIES_END_COUNTRY] = this.editEndLocRef.current.value; + } + if (Object.keys(newVals).length !== 0) { + writeActivity(this.props.activity.tripId, this.props.activity.id, newVals); + } + } + + /** Runs when the `submit` button is pressed. */ + finishEditActivity(event) { + event.preventDefault(); + this.editActivity(); + this.props.submitFunction(); + } + + startTimeTzUpdate = () => { this.setState({startTz : !this.state.startTz})}; + endTimeTzUpdate = () => { this.setState({endTz : !this.state.endTz})}; + + /** + * Returns a dropdown of all the timezones. + * + * @param st either "start" or "end" + */ + timezonePicker(st) { + console.log(this.state.startTz); + return ( +
+ + {time.timezonesForCountry(this.editStartLocRef).map((item, index) => { + return (); + })} + +
+ ) + } + /** + * 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 ( + + {countryList.map((item, index) => { + return ( + + ); + })} + + ); + } + + + render() { + const activity = this.props.activity; + const titleWidth = 3; + const countryWidth = 6; + return ( +
+ + Title: + + + + Start Location: + {this.countriesDropdown(this.editStartLocRef, this.startTimeTzUpdate)} + + + End Location: + {this.countriesDropdown(this.editEndLocRef, this.endTimeTzUpdate)} + + + From: + + + {this.timezonePicker("start")} + + + To: + + + {this.timezonePicker("end")} + + + Description: + + + + +
+ ); + } +} + +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 {

{utils.getField(activity, DB.ACTIVITIES_DESCRIPTION, "")}

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/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js index 5c081ac0..ac40ad65 100644 --- a/frontend/src/components/ViewActivities/editActivity.js +++ b/frontend/src/components/ViewActivities/editActivity.js @@ -48,10 +48,10 @@ class EditActivity extends React.Component { if (this.editDescriptionRef.current.value !== '') { newVals[DB.ACTIVITIES_DESCRIPTION] = this.editDescriptionRef.current.value; } - if (this.editStartLocRef.current.value !== ''){ + if (this.editStartLocRef.current.value !== 'No Change'){ newVals[DB.ACTIVITIES_START_COUNTRY] = this.editStartLocRef.current.value; } - if (this.editEndLocRef.current.value !== ''){ + if (this.editEndLocRef.current.value !== 'No Change'){ newVals[DB.ACTIVITIES_END_COUNTRY] = this.editEndLocRef.current.value; } if (Object.keys(newVals).length !== 0) { @@ -75,7 +75,6 @@ class EditActivity extends React.Component { * @param st either "start" or "end" */ timezonePicker(st) { - console.log(this.state.startTz); return (
+ {countryList.map((item, index) => { return ( - + ); })} From fc1e666fad0216e6a6e0bee6e35e42d979a1a397 Mon Sep 17 00:00:00 2001 From: ananyay <14322650+ananyeet@users.noreply.github.com> Date: Fri, 17 Jul 2020 00:07:03 -0500 Subject: [PATCH 08/25] Remove magic numbers from column widths. --- .../src/components/ViewActivities/editActivity.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js index 276d8fdf..9dfa5594 100644 --- a/frontend/src/components/ViewActivities/editActivity.js +++ b/frontend/src/components/ViewActivities/editActivity.js @@ -112,6 +112,9 @@ class EditActivity extends React.Component { const activity = this.props.activity; const titleWidth = 3; const countryWidth = 6; + const dateWidth = 4; + const timeWidth = 2; + const tzPickerWidth = 3; return (
@@ -128,15 +131,15 @@ class EditActivity extends React.Component { From: - - - {this.timezonePicker("start")} + + + {this.timezonePicker("start")} To: - - - {this.timezonePicker("end")} + + + {this.timezonePicker("end")} Description: From 866eed2f2029ec28137e11d317d2e3ef26a60c11 Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Fri, 17 Jul 2020 13:39:36 -0500 Subject: [PATCH 09/25] Update editActivity.js --- .../components/ViewActivities/editActivity.js | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js index 9dfa5594..6356b3e8 100644 --- a/frontend/src/components/ViewActivities/editActivity.js +++ b/frontend/src/components/ViewActivities/editActivity.js @@ -110,39 +110,39 @@ 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 TITLEWIDTH = 3; + const COUNTRYWIDTH = 6; + const DATEWIDTH = 4; + const TIMEWIDTH = 2; + const TZPICKERWIDTH = 3; return ( - Title: + Title: - Start Location: - {this.countriesDropdown(this.editStartLocRef, this.startTimeTzUpdate)} + Start Location: + {this.countriesDropdown(this.editStartLocRef, this.startTimeTzUpdate)} - End Location: - {this.countriesDropdown(this.editEndLocRef, this.endTimeTzUpdate)} + End Location: + {this.countriesDropdown(this.editEndLocRef, this.endTimeTzUpdate)} - From: - - - {this.timezonePicker("start")} + From: + + + {this.timezonePicker("start")} - To: - - - {this.timezonePicker("end")} + To: + + + {this.timezonePicker("end")} - Description: + Description: From 925f6c1279640c1639e48a8ee15a7df6c16f966a Mon Sep 17 00:00:00 2001 From: Ananya Yammanuru <14322650+ananyeet@users.noreply.github.com> Date: Mon, 20 Jul 2020 11:58:50 -0500 Subject: [PATCH 10/25] SINGLE QUOTES --- frontend/src/components/Utils/time.js | 2 +- frontend/src/components/Utils/time.test.js | 20 +++++++++---------- .../src/components/ViewActivities/activity.js | 6 +++--- .../components/ViewActivities/activityfns.js | 2 +- .../components/ViewActivities/editActivity.js | 16 +++++++-------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/Utils/time.js b/frontend/src/components/Utils/time.js index 45dd3d5b..7393e549 100644 --- a/frontend/src/components/Utils/time.js +++ b/frontend/src/components/Utils/time.js @@ -76,6 +76,6 @@ export function timezonesForCountry(countryName) { zones = moment.tz.names(); } return zones.map(e => { - return e.replace(/[_]/g, " "); + return e.replace(/[_]/g, ' '); }); } \ No newline at end of file diff --git a/frontend/src/components/Utils/time.test.js b/frontend/src/components/Utils/time.test.js index 935a1b15..dc9bc610 100644 --- a/frontend/src/components/Utils/time.test.js +++ b/frontend/src/components/Utils/time.test.js @@ -59,22 +59,22 @@ test('other full timestamp format', () => { describe('timezones for country', () => { test('legit country no spaces', () => { - const actual = utils.timezonesForCountry("China"); - const expected = ["Asia/Shanghai", "Asia/Urumqi"]; + const actual = utils.timezonesForCountry('China'); + const expected = ['Asia/Shanghai', 'Asia/Urumqi']; expect(new Set(actual.sort())).toEqual(new Set(expected.sort())); }) test('legit country, yes spaces', () => { - const actual = utils.timezonesForCountry("United States of America"); - expect(actual).toContain("America/Anchorage"); - expect(actual).toContain("America/New York"); - expect(actual).not.toContain("Africa/Accra"); + const actual = utils.timezonesForCountry('United States of America'); + expect(actual).toContain('America/Anchorage'); + expect(actual).toContain('America/New York'); + expect(actual).not.toContain('Africa/Accra'); }) test('not legit country (spaces and non spaces)', () => { - const actual = utils.timezonesForCountry("MURICA"); - expect(actual).toContain("America/New York"); - expect(actual).toContain("Europe/Paris"); - expect(actual).toContain("Africa/Accra"); + const actual = utils.timezonesForCountry('MURICA'); + expect(actual).toContain('America/New York'); + expect(actual).toContain('Europe/Paris'); + expect(actual).toContain('Africa/Accra'); }) }) \ No newline at end of file diff --git a/frontend/src/components/ViewActivities/activity.js b/frontend/src/components/ViewActivities/activity.js index 794f3a92..32e28cb4 100644 --- a/frontend/src/components/ViewActivities/activity.js +++ b/frontend/src/components/ViewActivities/activity.js @@ -46,11 +46,11 @@ class Activity extends React.Component { if (!this.state.editing) { // View mode. return ( -

{utils.getField(activity, DB.ACTIVITIES_DESCRIPTION, "")}

+

{utils.getField(activity, DB.ACTIVITIES_DESCRIPTION, '')}

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 (
- {time.timezonesForCountry(this.editStartLocRef).map((item, index) => { return (); @@ -96,8 +96,8 @@ class EditActivity extends React.Component { */ countriesDropdown(ref, tzref) { return ( - - + + {countryList.map((item, index) => { return ( @@ -133,13 +133,13 @@ class EditActivity extends React.Component { From: - {this.timezonePicker("start")} + {this.timezonePicker('start')} To: - {this.timezonePicker("end")} + {this.timezonePicker('end')} Description: From 17c44d37437e220b00baf1b742274306a713b952 Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Mon, 20 Jul 2020 12:26:59 -0500 Subject: [PATCH 11/25] Update dropdowns so they're reactive --- .../components/ViewActivities/editActivity.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js index 97f26ed0..81868dbf 100644 --- a/frontend/src/components/ViewActivities/editActivity.js +++ b/frontend/src/components/ViewActivities/editActivity.js @@ -22,6 +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); // References. this.editTitleRef = React.createRef(); @@ -75,15 +76,24 @@ class EditActivity extends React.Component { * @param st either 'start' or 'end' depending on whether the timezone is for the start or end timezone. */ timezonePicker(st) { + let ref = st === 'start' ? this.editStartLocRef : this.editEndLocRef; + let dbEntry = st === 'start' ? DB.ACTIVITIES_START_COUNTRY : DB.ACTIVITIES_END_COUNTRY; + let timezones; + if (ref.current == null) { + // If activity[key] DNE, then timezones will just return all tzs anyway + timezones = time.timezonesForCountry(this.props.activity[dbEntry]); + } else { + timezones = time.timezonesForCountry(ref.current.value); + } return (
- {time.timezonesForCountry(this.editStartLocRef).map((item, index) => { - return (); - })} + {timezones.map((item, index) => { + 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 ( - - Title: - - - - Start Location: - {this.countriesDropdown(this.editStartLocRef, this.startTimeTzUpdate)} - - - End Location: - {this.countriesDropdown(this.editEndLocRef, this.endTimeTzUpdate)} - - - From: - - - {this.timezoneDropdown('start')} - - - To: - - - {this.timezoneDropdown('end')} - - - Description: - - - + {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 ( + + {formLabel} + {dropdown} + + ); +} + +/** + * + * @param {*} controlId + * @param {*} formLabel + * @param {*} dateRef + * @param {*} dateDefault + * @param {*} timeRef + * @param {*} timeDefault + * @param {*} tzpicker + */ +export function dateTimeTzFormGroup(controlId, formLabel, dateRef, + dateDefault, timeRef, timeDefault, tzpicker) { + return ( + + {formLabel} + + + + + + + {tzpicker} + + ); +} \ No newline at end of file From 856d01241bfb7b0509d9a2d9a033f543930ae62a Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Mon, 20 Jul 2020 22:25:15 -0500 Subject: [PATCH 18/25] Remove unused variables. --- frontend/src/components/ViewActivities/editActivity.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js index 4f558a42..a6feb567 100644 --- a/frontend/src/components/ViewActivities/editActivity.js +++ b/frontend/src/components/ViewActivities/editActivity.js @@ -128,11 +128,6 @@ class EditActivity extends React.Component { } render() { - const TITLEWIDTH = 3; -const COUNTRYWIDTH = 6; -const DATEWIDTH = 4; -const TIMEWIDTH = 2; -const TZPICKERWIDTH = 3; const activity = this.props.activity; return (
From e9bc84de396feefa2ee67155ba866c7d77c1fb08 Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Mon, 20 Jul 2020 22:28:43 -0500 Subject: [PATCH 19/25] Function comments. --- .../ViewActivities/editActivityFormElements.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/ViewActivities/editActivityFormElements.js b/frontend/src/components/ViewActivities/editActivityFormElements.js index b864f2ba..c2899636 100644 --- a/frontend/src/components/ViewActivities/editActivityFormElements.js +++ b/frontend/src/components/ViewActivities/editActivityFormElements.js @@ -49,14 +49,17 @@ export function locationElementFormGroup(controlId, formLabel, dropdown) { } /** + * Create a Form Group for inserting date, time, and timezone for + * the editActivity form.. * - * @param {*} controlId - * @param {*} formLabel - * @param {*} dateRef - * @param {*} dateDefault - * @param {*} timeRef - * @param {*} timeDefault - * @param {*} tzpicker + * @param {string} controlId FormGroup's control ID. + * @param {string} formLabel Label of the field for this FormGroup. + * @param {ref} dateRef Date's reference. + * @param {string} dateDefault Default date. + * @param {ref} timeRef Time's reference. + * @param {ref} timeDefault Default time. + * @param {HTML} tzpicker Timezone picker dropdown. + * @returns A FormGroup for date, time, and timezone. */ export function dateTimeTzFormGroup(controlId, formLabel, dateRef, dateDefault, timeRef, timeDefault, tzpicker) { From 9adad7f54aa7091fcb4032e28c6e1cdb5f42c65c Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Tue, 21 Jul 2020 15:53:47 -0500 Subject: [PATCH 20/25] why didn't this show up in the diff?? --- .../ViewActivities/editActivityFormElements.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/ViewActivities/editActivityFormElements.js b/frontend/src/components/ViewActivities/editActivityFormElements.js index c2899636..5ab00d9b 100644 --- a/frontend/src/components/ViewActivities/editActivityFormElements.js +++ b/frontend/src/components/ViewActivities/editActivityFormElements.js @@ -52,14 +52,14 @@ export function locationElementFormGroup(controlId, formLabel, dropdown) { * Create a Form Group for inserting date, time, and timezone for * the editActivity form.. * - * @param {string} controlId FormGroup's control ID. - * @param {string} formLabel Label of the field for this FormGroup. - * @param {ref} dateRef Date's reference. - * @param {string} dateDefault Default date. - * @param {ref} timeRef Time's reference. - * @param {ref} timeDefault Default time. - * @param {HTML} tzpicker Timezone picker dropdown. - * @returns A FormGroup for date, time, and timezone. + * @param {string} controlId FormGroup's control ID. + * @param {string} formLabel Label of the field for this FormGroup. + * @param {ref} dateRef Date's reference. + * @param {string} dateDefault Default date. + * @param {ref} timeRef Time's reference. + * @param {ref} timeDefault Default time. + * @param {HTML} tzpicker Timezone picker dropdown. + * @returns A FormGroup for date, time, and timezone. */ export function dateTimeTzFormGroup(controlId, formLabel, dateRef, dateDefault, timeRef, timeDefault, tzpicker) { From 4ad9b6b871ad315df30163634fea0acbffffde6f Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Tue, 21 Jul 2020 16:01:32 -0500 Subject: [PATCH 21/25] Comments changes. --- frontend/src/components/Utils/time.js | 2 +- .../components/ViewActivities/activityfns.js | 13 ++--- .../components/ViewActivities/editActivity.js | 53 ++++++++++--------- .../editActivityFormElements.js | 6 +-- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/frontend/src/components/Utils/time.js b/frontend/src/components/Utils/time.js index 2615403c..40451be6 100644 --- a/frontend/src/components/Utils/time.js +++ b/frontend/src/components/Utils/time.js @@ -65,7 +65,7 @@ export function timestampToFormatted(msTimestamp, timezone = 'America/New_York') * Returns all the time zones in a country (in pretty format). * * @param {string} countryName The name of the country for which to get the time zones. - * @returns The list of time zones in the provided country. + * @returns {Array.} The list of time zones in the provided country. */ export function timezonesForCountry(countryName) { let zones; diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js index ecb08b91..c2c17a02 100644 --- a/frontend/src/components/ViewActivities/activityfns.js +++ b/frontend/src/components/ViewActivities/activityfns.js @@ -48,11 +48,12 @@ export function compareActivities(a, b) { /** * Get the field of field name `fieldName` from `activity or the default value. * - * @param {Object} activity - * @param {string} fieldName - * @param defaultValue - * @param prefix The prefix to put before a returned value if the field exists. - * @returns `activity[fieldName]` if possible, else `defaultValue`. + * @param {Object} activity Activity to get field from. + * @param {string} fieldName Name of the field in the activity to get. + * @param defaultValue Default value to return if activity[fieldName] can't be found. + * Can be any type. + * @param {string} prefix The prefix to put before a returned value if the field exists. + * @returns `activity[fieldName]` if possible, else `defaultValue`. Can be any type. */ export function getField(activity, fieldName, defaultValue, prefix=''){ if (activity[fieldName] === null || activity[fieldName] === undefined) { @@ -67,7 +68,7 @@ export function getField(activity, fieldName, defaultValue, prefix=''){ * @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) diff --git a/frontend/src/components/ViewActivities/editActivity.js b/frontend/src/components/ViewActivities/editActivity.js index a6feb567..a5096a10 100644 --- a/frontend/src/components/ViewActivities/editActivity.js +++ b/frontend/src/components/ViewActivities/editActivity.js @@ -80,16 +80,16 @@ class EditActivity extends React.Component { * * Tests done manually using UI. * - * @param st Either 'start' or 'end' depending on whether the + * @param {string} st Either 'start' or 'end' depending on whether the * timezone is for the start or end timezone. - * @returns HTML dropdown item. + * @returns {HTML} HTML dropdown item. */ timezoneDropdown(st) { - let ref = st === 'start' ? this.editStartLocRef : this.editEndLocRef; - let dbEntry = st === 'start' ? DB.ACTIVITIES_START_COUNTRY : DB.ACTIVITIES_END_COUNTRY; + const ref = st === 'start' ? this.editStartLocRef : this.editEndLocRef; + const dbEntry = st === 'start' ? DB.ACTIVITIES_START_COUNTRY : DB.ACTIVITIES_END_COUNTRY; let timezones; if (ref.current == null) { - // If activity[key] DNE, then timezones will just return all tzs anyway + // If activity[key] DNE, then timezones will just return all tzs anyway. timezones = time.timezonesForCountry(this.props.activity[dbEntry]); } else { timezones = time.timezonesForCountry(ref.current.value); @@ -111,8 +111,9 @@ class EditActivity extends React.Component { * 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. + * @param {ref} ref The reference to attach to the dropdown. + * @param {ref} tzref The corresponding time zone reference field. + * @returns {HTML} HTML dropdown of all the countries with timezones. */ countriesDropdown(ref, tzref) { return ( @@ -138,38 +139,38 @@ class EditActivity extends React.Component { this.editTitleRef // ref )} {formElements.locationElementFormGroup( - 'formActivityStartLocation', // controlId - 'Start Location:', // formLabel - this.countriesDropdown(this.editStartLocRef, this.startTimeTzUpdate) + 'formActivityStartLocation', // controlId + 'Start Location:', // formLabel + this.countriesDropdown(this.editStartLocRef, this.startTimeTzUpdate) // dropdown )} {formElements.locationElementFormGroup( 'formActivityEndLocation', // controlId - 'End Location:', // formLabel - this.countriesDropdown(this.editEndLocRef, this.endTimeTzUpdate) + 'End Location:', // formLabel + this.countriesDropdown(this.editEndLocRef, this.endTimeTzUpdate) // dropdown )} {formElements.dateTimeTzFormGroup( - 'formActivityStartTime', // controlId - 'From:', // formLabel - this.editStartDateRef, // dateRef - null, // dateDefault - this.editStartTimeRef, // timeRef, - null, //timeDefault, + '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, + 'formActivityEndTime', // controlId + 'To:', // formLabel + this.editEndDateRef, // dateRef + null, // dateDefault + this.editEndTimeRef, // timeRef, + null, //timeDefault, this.timezoneDropdown('end') // tzpicker )} {formElements.textElementFormGroup( 'formActivityDescription', // controlId - 'Description:', // formLabel + 'Description:', // formLabel getField(activity, DB.ACTIVITIES_DESCRIPTION, 'Add some details!'), // placeHolder - this.editDescriptionRef // ref + this.editDescriptionRef // ref )} diff --git a/frontend/src/components/ViewActivities/editActivityFormElements.js b/frontend/src/components/ViewActivities/editActivityFormElements.js index 5ab00d9b..f53ccaba 100644 --- a/frontend/src/components/ViewActivities/editActivityFormElements.js +++ b/frontend/src/components/ViewActivities/editActivityFormElements.js @@ -16,7 +16,7 @@ const TZPICKERWIDTH = 3; * @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. + * @returns {HTML} A text element form group. */ export function textElementFormGroup(controlId, formLabel, placeHolder, ref) { return ( @@ -37,7 +37,7 @@ export function textElementFormGroup(controlId, formLabel, placeHolder, ref) { * @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. + * @returns {HTML} a location dropdown form group. */ export function locationElementFormGroup(controlId, formLabel, dropdown) { return ( @@ -59,7 +59,7 @@ export function locationElementFormGroup(controlId, formLabel, dropdown) { * @param {ref} timeRef Time's reference. * @param {ref} timeDefault Default time. * @param {HTML} tzpicker Timezone picker dropdown. - * @returns A FormGroup for date, time, and timezone. + * @returns {HTML} A FormGroup for date, time, and timezone. */ export function dateTimeTzFormGroup(controlId, formLabel, dateRef, dateDefault, timeRef, timeDefault, tzpicker) { From 194b4bc4449c2375888954c19c56918320b56c00 Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Tue, 21 Jul 2020 16:17:44 -0500 Subject: [PATCH 22/25] comprehensive timezone testing --- frontend/src/components/Utils/time.test.js | 105 ++++++++++----------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/frontend/src/components/Utils/time.test.js b/frontend/src/components/Utils/time.test.js index dc9bc610..8971b718 100644 --- a/frontend/src/components/Utils/time.test.js +++ b/frontend/src/components/Utils/time.test.js @@ -3,78 +3,77 @@ import * as utils from './time'; const TZ_CHICAGO = 'America/Chicago'; const TZ_SINGAPORE = 'Asia/Singapore'; +const ALLTZS = ["Africa/Abidjan", "Africa/Accra", "Africa/Addis Ababa", "Africa/Algiers", "Africa/Asmara", "Africa/Asmera", "Africa/Bamako", "Africa/Bangui", "Africa/Banjul", "Africa/Bissau", "Africa/Blantyre", "Africa/Brazzaville", "Africa/Bujumbura", "Africa/Cairo", "Africa/Casablanca", "Africa/Ceuta", "Africa/Conakry", "Africa/Dakar", "Africa/Dar es Salaam", "Africa/Djibouti", "Africa/Douala", "Africa/El Aaiun", "Africa/Freetown", "Africa/Gaborone", "Africa/Harare", "Africa/Johannesburg", "Africa/Juba", "Africa/Kampala", "Africa/Khartoum", "Africa/Kigali", "Africa/Kinshasa", "Africa/Lagos", "Africa/Libreville", "Africa/Lome", "Africa/Luanda", "Africa/Lubumbashi", "Africa/Lusaka", "Africa/Malabo", "Africa/Maputo", "Africa/Maseru", "Africa/Mbabane", "Africa/Mogadishu", "Africa/Monrovia", "Africa/Nairobi", "Africa/Ndjamena", "Africa/Niamey", "Africa/Nouakchott", "Africa/Ouagadougou", "Africa/Porto-Novo", "Africa/Sao Tome", "Africa/Timbuktu", "Africa/Tripoli", "Africa/Tunis", "Africa/Windhoek", "America/Adak", "America/Anchorage", "America/Anguilla", "America/Antigua", "America/Araguaina", "America/Argentina/Buenos Aires", "America/Argentina/Catamarca", "America/Argentina/ComodRivadavia", "America/Argentina/Cordoba", "America/Argentina/Jujuy", "America/Argentina/La Rioja", "America/Argentina/Mendoza", "America/Argentina/Rio Gallegos", "America/Argentina/Salta", "America/Argentina/San Juan", "America/Argentina/San Luis", "America/Argentina/Tucuman", "America/Argentina/Ushuaia", "America/Aruba", "America/Asuncion", "America/Atikokan", "America/Atka", "America/Bahia", "America/Bahia Banderas", "America/Barbados", "America/Belem", "America/Belize", "America/Blanc-Sablon", "America/Boa Vista", "America/Bogota", "America/Boise", "America/Buenos Aires", "America/Cambridge Bay", "America/Campo Grande", "America/Cancun", "America/Caracas", "America/Catamarca", "America/Cayenne", "America/Cayman", "America/Chicago", "America/Chihuahua", "America/Coral Harbour", "America/Cordoba", "America/Costa Rica", "America/Creston", "America/Cuiaba", "America/Curacao", "America/Danmarkshavn", "America/Dawson", "America/Dawson Creek", "America/Denver", "America/Detroit", "America/Dominica", "America/Edmonton", "America/Eirunepe", "America/El Salvador", "America/Ensenada", "America/Fort Nelson", "America/Fort Wayne", "America/Fortaleza", "America/Glace Bay", "America/Godthab", "America/Goose Bay", "America/Grand Turk", "America/Grenada", "America/Guadeloupe", "America/Guatemala", "America/Guayaquil", "America/Guyana", "America/Halifax", "America/Havana", "America/Hermosillo", "America/Indiana/Indianapolis", "America/Indiana/Knox", "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Tell City", "America/Indiana/Vevay", "America/Indiana/Vincennes", "America/Indiana/Winamac", "America/Indianapolis", "America/Inuvik", "America/Iqaluit", "America/Jamaica", "America/Jujuy", "America/Juneau", "America/Kentucky/Louisville", "America/Kentucky/Monticello", "America/Knox IN", "America/Kralendijk", "America/La Paz", "America/Lima", "America/Los Angeles", "America/Louisville", "America/Lower Princes", "America/Maceio", "America/Managua", "America/Manaus", "America/Marigot", "America/Martinique", "America/Matamoros", "America/Mazatlan", "America/Mendoza", "America/Menominee", "America/Merida", "America/Metlakatla", "America/Mexico City", "America/Miquelon", "America/Moncton", "America/Monterrey", "America/Montevideo", "America/Montreal", "America/Montserrat", "America/Nassau", "America/New York", "America/Nipigon", "America/Nome", "America/Noronha", "America/North Dakota/Beulah", "America/North Dakota/Center", "America/North Dakota/New Salem", "America/Nuuk", "America/Ojinaga", "America/Panama", "America/Pangnirtung", "America/Paramaribo", "America/Phoenix", "America/Port-au-Prince", "America/Port of Spain", "America/Porto Acre", "America/Porto Velho", "America/Puerto Rico", "America/Punta Arenas", "America/Rainy River", "America/Rankin Inlet", "America/Recife", "America/Regina", "America/Resolute", "America/Rio Branco", "America/Rosario", "America/Santa Isabel", "America/Santarem", "America/Santiago", "America/Santo Domingo", "America/Sao Paulo", "America/Scoresbysund", "America/Shiprock", "America/Sitka", "America/St Barthelemy", "America/St Johns", "America/St Kitts", "America/St Lucia", "America/St Thomas", "America/St Vincent", "America/Swift Current", "America/Tegucigalpa", "America/Thule", "America/Thunder Bay", "America/Tijuana", "America/Toronto", "America/Tortola", "America/Vancouver", "America/Virgin", "America/Whitehorse", "America/Winnipeg", "America/Yakutat", "America/Yellowknife", "Antarctica/Casey", "Antarctica/Davis", "Antarctica/DumontDUrville", "Antarctica/Macquarie", "Antarctica/Mawson", "Antarctica/McMurdo", "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/South Pole", "Antarctica/Syowa", "Antarctica/Troll", "Antarctica/Vostok", "Arctic/Longyearbyen", "Asia/Aden", "Asia/Almaty", "Asia/Amman", "Asia/Anadyr", "Asia/Aqtau", "Asia/Aqtobe", "Asia/Ashgabat", "Asia/Ashkhabad", "Asia/Atyrau", "Asia/Baghdad", "Asia/Bahrain", "Asia/Baku", "Asia/Bangkok", "Asia/Barnaul", "Asia/Beirut", "Asia/Bishkek", "Asia/Brunei", "Asia/Calcutta", "Asia/Chita", "Asia/Choibalsan", "Asia/Chongqing", "Asia/Chungking", "Asia/Colombo", "Asia/Dacca", "Asia/Damascus", "Asia/Dhaka", "Asia/Dili", "Asia/Dubai", "Asia/Dushanbe", "Asia/Famagusta", "Asia/Gaza", "Asia/Harbin", "Asia/Hebron", "Asia/Ho Chi Minh", "Asia/Hong Kong", "Asia/Hovd", "Asia/Irkutsk", "Asia/Istanbul", "Asia/Jakarta", "Asia/Jayapura", "Asia/Jerusalem", "Asia/Kabul", "Asia/Kamchatka", "Asia/Karachi", "Asia/Kashgar", "Asia/Kathmandu", "Asia/Katmandu", "Asia/Khandyga", "Asia/Kolkata", "Asia/Krasnoyarsk", "Asia/Kuala Lumpur", "Asia/Kuching", "Asia/Kuwait", "Asia/Macao", "Asia/Macau", "Asia/Magadan", "Asia/Makassar", "Asia/Manila", "Asia/Muscat", "Asia/Nicosia", "Asia/Novokuznetsk", "Asia/Novosibirsk", "Asia/Omsk", "Asia/Oral", "Asia/Phnom Penh", "Asia/Pontianak", "Asia/Pyongyang", "Asia/Qatar", "Asia/Qostanay", "Asia/Qyzylorda", "Asia/Rangoon", "Asia/Riyadh", "Asia/Saigon", "Asia/Sakhalin", "Asia/Samarkand", "Asia/Seoul", "Asia/Shanghai", "Asia/Singapore", "Asia/Srednekolymsk", "Asia/Taipei", "Asia/Tashkent", "Asia/Tbilisi", "Asia/Tehran", "Asia/Tel Aviv", "Asia/Thimbu", "Asia/Thimphu", "Asia/Tokyo", "Asia/Tomsk", "Asia/Ujung Pandang", "Asia/Ulaanbaatar", "Asia/Ulan Bator", "Asia/Urumqi", "Asia/Ust-Nera", "Asia/Vientiane", "Asia/Vladivostok", "Asia/Yakutsk", "Asia/Yangon", "Asia/Yekaterinburg", "Asia/Yerevan", "Atlantic/Azores", "Atlantic/Bermuda", "Atlantic/Canary", "Atlantic/Cape Verde", "Atlantic/Faeroe", "Atlantic/Faroe", "Atlantic/Jan Mayen", "Atlantic/Madeira", "Atlantic/Reykjavik", "Atlantic/South Georgia", "Atlantic/St Helena", "Atlantic/Stanley", "Australia/ACT", "Australia/Adelaide", "Australia/Brisbane", "Australia/Broken Hill", "Australia/Canberra", "Australia/Currie", "Australia/Darwin", "Australia/Eucla", "Australia/Hobart", "Australia/LHI", "Australia/Lindeman", "Australia/Lord Howe", "Australia/Melbourne", "Australia/NSW", "Australia/North", "Australia/Perth", "Australia/Queensland", "Australia/South", "Australia/Sydney", "Australia/Tasmania", "Australia/Victoria", "Australia/West", "Australia/Yancowinna", "Brazil/Acre", "Brazil/DeNoronha", "Brazil/East", "Brazil/West", "CET", "CST6CDT", "Canada/Atlantic", "Canada/Central", "Canada/Eastern", "Canada/Mountain", "Canada/Newfoundland", "Canada/Pacific", "Canada/Saskatchewan", "Canada/Yukon", "Chile/Continental", "Chile/EasterIsland", "Cuba", "EET", "EST", "EST5EDT", "Egypt", "Eire", "Etc/GMT", "Etc/GMT+0", "Etc/GMT+1", "Etc/GMT+10", "Etc/GMT+11", "Etc/GMT+12", "Etc/GMT+2", "Etc/GMT+3", "Etc/GMT+4", "Etc/GMT+5", "Etc/GMT+6", "Etc/GMT+7", "Etc/GMT+8", "Etc/GMT+9", "Etc/GMT-0", "Etc/GMT-1", "Etc/GMT-10", "Etc/GMT-11", "Etc/GMT-12", "Etc/GMT-13", "Etc/GMT-14", "Etc/GMT-2", "Etc/GMT-3", "Etc/GMT-4", "Etc/GMT-5", "Etc/GMT-6", "Etc/GMT-7", "Etc/GMT-8", "Etc/GMT-9", "Etc/GMT0", "Etc/Greenwich", "Etc/UCT", "Etc/UTC", "Etc/Universal", "Etc/Zulu", "Europe/Amsterdam", "Europe/Andorra", "Europe/Astrakhan", "Europe/Athens", "Europe/Belfast", "Europe/Belgrade", "Europe/Berlin", "Europe/Bratislava", "Europe/Brussels", "Europe/Bucharest", "Europe/Budapest", "Europe/Busingen", "Europe/Chisinau", "Europe/Copenhagen", "Europe/Dublin", "Europe/Gibraltar", "Europe/Guernsey", "Europe/Helsinki", "Europe/Isle of Man", "Europe/Istanbul", "Europe/Jersey", "Europe/Kaliningrad", "Europe/Kiev", "Europe/Kirov", "Europe/Lisbon", "Europe/Ljubljana", "Europe/London", "Europe/Luxembourg", "Europe/Madrid", "Europe/Malta", "Europe/Mariehamn", "Europe/Minsk", "Europe/Monaco", "Europe/Moscow", "Europe/Nicosia", "Europe/Oslo", "Europe/Paris", "Europe/Podgorica", "Europe/Prague", "Europe/Riga", "Europe/Rome", "Europe/Samara", "Europe/San Marino", "Europe/Sarajevo", "Europe/Saratov", "Europe/Simferopol", "Europe/Skopje", "Europe/Sofia", "Europe/Stockholm", "Europe/Tallinn", "Europe/Tirane", "Europe/Tiraspol", "Europe/Ulyanovsk", "Europe/Uzhgorod", "Europe/Vaduz", "Europe/Vatican", "Europe/Vienna", "Europe/Vilnius", "Europe/Volgograd", "Europe/Warsaw", "Europe/Zagreb", "Europe/Zaporozhye", "Europe/Zurich", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0", "Greenwich", "HST", "Hongkong", "Iceland", "Indian/Antananarivo", "Indian/Chagos", "Indian/Christmas", "Indian/Cocos", "Indian/Comoro", "Indian/Kerguelen", "Indian/Mahe", "Indian/Maldives", "Indian/Mauritius", "Indian/Mayotte", "Indian/Reunion", "Iran", "Israel", "Jamaica", "Japan", "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Mexico/BajaNorte", "Mexico/BajaSur", "Mexico/General", "NZ", "NZ-CHAT", "Navajo", "PRC", "PST8PDT", "Pacific/Apia", "Pacific/Auckland", "Pacific/Bougainville", "Pacific/Chatham", "Pacific/Chuuk", "Pacific/Easter", "Pacific/Efate", "Pacific/Enderbury", "Pacific/Fakaofo", "Pacific/Fiji", "Pacific/Funafuti", "Pacific/Galapagos", "Pacific/Gambier", "Pacific/Guadalcanal", "Pacific/Guam", "Pacific/Honolulu", "Pacific/Johnston", "Pacific/Kiritimati", "Pacific/Kosrae", "Pacific/Kwajalein", "Pacific/Majuro", "Pacific/Marquesas", "Pacific/Midway", "Pacific/Nauru", "Pacific/Niue", "Pacific/Norfolk", "Pacific/Noumea", "Pacific/Pago Pago", "Pacific/Palau", "Pacific/Pitcairn", "Pacific/Pohnpei", "Pacific/Ponape", "Pacific/Port Moresby", "Pacific/Rarotonga", "Pacific/Saipan", "Pacific/Samoa", "Pacific/Tahiti", "Pacific/Tarawa", "Pacific/Tongatapu", "Pacific/Truk", "Pacific/Wake", "Pacific/Wallis", "Pacific/Yap", "Poland", "Portugal", "ROC", "ROK", "Singapore", "Turkey", "UCT", "US/Alaska", "US/Aleutian", "US/Arizona", "US/Central", "US/East-Indiana", "US/Eastern", "US/Hawaii", "US/Indiana-Starke", "US/Michigan", "US/Mountain", "US/Pacific", "US/Pacific-New", "US/Samoa", "UTC", "Universal", "W-SU", "WET", "Zulu"] +const USTZS = ["America/New York", "America/Detroit", "America/Kentucky/Louisville", "America/Kentucky/Monticello", "America/Indiana/Indianapolis", "America/Indiana/Vincennes", "America/Indiana/Winamac", "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Vevay", "America/Chicago", "America/Indiana/Tell City", "America/Indiana/Knox", "America/Menominee", "America/North Dakota/Center", "America/North Dakota/New Salem", "America/North Dakota/Beulah", "America/Denver", "America/Boise", "America/Phoenix", "America/Los Angeles", "America/Anchorage", "America/Juneau", "America/Sitka", "America/Metlakatla", "America/Yakutat", "America/Nome", "America/Adak", "Pacific/Honolulu"] + test('new york date 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'; - const actual = utils.timestampToDateFormatted(testDate); - expect(actual).toEqual(expected); + // 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'; + const actual = utils.timestampToDateFormatted(testDate); + expect(actual).toEqual(expected); }); test('other date timestamp format', () => { - const testDate = new Date(Date.UTC(2020, 7, 23, 2, 3, 2, 4)).getTime(); - const expectedCentral = 'Saturday, August 22, 2020'; - const expectedSingapore = 'Sunday, August 23, 2020'; - const actualCentral = utils.timestampToDateFormatted(testDate, TZ_CHICAGO); - const actualSingapore = utils.timestampToDateFormatted(testDate, TZ_SINGAPORE); - expect(actualCentral).toEqual(expectedCentral); - expect(actualSingapore).toEqual(expectedSingapore); + const testDate = new Date(Date.UTC(2020, 7, 23, 2, 3, 2, 4)).getTime(); + const expectedCentral = 'Saturday, August 22, 2020'; + const expectedSingapore = 'Sunday, August 23, 2020'; + const actualCentral = utils.timestampToDateFormatted(testDate, TZ_CHICAGO); + const actualSingapore = utils.timestampToDateFormatted(testDate, TZ_SINGAPORE); + expect(actualCentral).toEqual(expectedCentral); + expect(actualSingapore).toEqual(expectedSingapore); }) test('new york time 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 = '10:19 AM'; - const actual = utils.timestampToTimeFormatted(testDate); - expect(actual).toEqual(expected); + // 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 = '10:19 AM'; + const actual = utils.timestampToTimeFormatted(testDate); + expect(actual).toEqual(expected); }); test('other time timestamp format', () => { - const testDate = new Date(Date.UTC(2020, 7, 23, 2, 3, 2, 4)).getTime(); - const expectedCentral = '9:03 PM'; - const expectedSingapore = '10:03 AM'; - const actualCentral = utils.timestampToTimeFormatted(testDate, TZ_CHICAGO); - const actualSingapore = utils.timestampToTimeFormatted(testDate, TZ_SINGAPORE); - expect(actualCentral).toEqual(expectedCentral); - expect(actualSingapore).toEqual(expectedSingapore); + const testDate = new Date(Date.UTC(2020, 7, 23, 2, 3, 2, 4)).getTime(); + const expectedCentral = '9:03 PM'; + const expectedSingapore = '10:03 AM'; + const actualCentral = utils.timestampToTimeFormatted(testDate, TZ_CHICAGO); + const actualSingapore = utils.timestampToTimeFormatted(testDate, TZ_SINGAPORE); + expect(actualCentral).toEqual(expectedCentral); + expect(actualSingapore).toEqual(expectedSingapore); }) 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 actual = utils.timestampToFormatted(testDate); - expect(actual).toEqual(expected); + // 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 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'); - expect(actualCentral).toEqual(expectedCentral); - expect(actualSingapore).toEqual(expectedSingapore); + 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'); + expect(actualCentral).toEqual(expectedCentral); + expect(actualSingapore).toEqual(expectedSingapore); }) describe('timezones for country', () => { - test('legit country no spaces', () => { - const actual = utils.timezonesForCountry('China'); - const expected = ['Asia/Shanghai', 'Asia/Urumqi']; - expect(new Set(actual.sort())).toEqual(new Set(expected.sort())); - }) + test('legit country no spaces', () => { + const actual = utils.timezonesForCountry('China'); + const expected = ['Asia/Shanghai', 'Asia/Urumqi']; + expect(new Set(actual.sort())).toEqual(new Set(expected.sort())); + }) - test('legit country, yes spaces', () => { - const actual = utils.timezonesForCountry('United States of America'); - expect(actual).toContain('America/Anchorage'); - expect(actual).toContain('America/New York'); - expect(actual).not.toContain('Africa/Accra'); - }) + test('legit country, yes spaces', () => { + const actual = utils.timezonesForCountry('United States of America'); + expect(new Set(actual)).toEqual(new Set(USTZS)); + }) - test('not legit country (spaces and non spaces)', () => { - const actual = utils.timezonesForCountry('MURICA'); - expect(actual).toContain('America/New York'); - expect(actual).toContain('Europe/Paris'); - expect(actual).toContain('Africa/Accra'); - }) + test('not legit country (spaces and non spaces)', () => { + const actual = utils.timezonesForCountry('MURICA'); + expect(new Set(actual)).toEqual(new Set(ALLTZS)); + }) }) \ No newline at end of file From 3ab3c1a1e25174e7e55d74abd4ff2f4b79d6889d Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Tue, 21 Jul 2020 21:20:33 -0500 Subject: [PATCH 23/25] Remove .gitignore changes. --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index 25ec766e..5b3d5cef 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,3 @@ # Target folder is generated by maven when deploying the app so it # does not make sense to include in the repo. target/ - -# for jsdoc -frontend/out/* \ No newline at end of file From d09878b532592c7896a3d47a9be1a7e7cb418ace Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Wed, 22 Jul 2020 10:54:56 -0500 Subject: [PATCH 24/25] @returns to @return --- frontend/src/components/Utils/time.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/Utils/time.js b/frontend/src/components/Utils/time.js index 6ac58b92..aa59a542 100644 --- a/frontend/src/components/Utils/time.js +++ b/frontend/src/components/Utils/time.js @@ -6,7 +6,7 @@ import { countryCodes } from '../../constants/countries.js'; * * @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. + * @return {string} Time formatted into desired pretty string. */ export function timestampToTimeFormatted(msTimestamp, timezone = 'America/New_York') { const date = new Date(msTimestamp); @@ -25,7 +25,7 @@ export function timestampToTimeFormatted(msTimestamp, timezone = 'America/New_Yo * * @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. + * @return {string} Time formatted into desired pretty string. */ export function timestampToDateFormatted(msTimestamp, timezone='America/New_York') { const date = new Date(msTimestamp); @@ -46,7 +46,7 @@ export function timestampToDateFormatted(msTimestamp, timezone='America/New_York * * @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. + * @return {string} Time formatted into desired pretty string. */ export function timestampToFormatted(msTimestamp, timezone = 'America/New_York') { let date = new Date(msTimestamp); @@ -64,10 +64,10 @@ export function timestampToFormatted(msTimestamp, timezone = 'America/New_York') } /** - * Returns all the time zones in a country (in pretty format). + * Returns all the time zones in a country (in displayable format). * * @param {string} countryName The name of the country for which to get the time zones. - * @returns {Array.} The list of time zones in the provided country. + * @return {string[]} The list of time zones in the provided country. */ export function timezonesForCountry(countryName) { let zones; From 52aa476e449f8dddfa009b372843c3890000167d Mon Sep 17 00:00:00 2001 From: Ananya Y <14322650+ananyeet@users.noreply.github.com> Date: Fri, 24 Jul 2020 15:36:12 -0500 Subject: [PATCH 25/25] @return fixes --- frontend/src/components/ViewActivities/activityfns.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/ViewActivities/activityfns.js b/frontend/src/components/ViewActivities/activityfns.js index 0d87bdcc..0a58e0f8 100644 --- a/frontend/src/components/ViewActivities/activityfns.js +++ b/frontend/src/components/ViewActivities/activityfns.js @@ -73,7 +73,7 @@ export function compareActivities(a, b) { * @param {string} fieldName Name of field to get. * @param {*} defaultValue Value if field is not found/is null. * @param {string} prefix The prefix to put before a returned value if the field exists. - * @returns {*} activity[fieldName] if possible, else defaultValue. + * @return {*} activity[fieldName] if possible, else defaultValue. */ export function getField(activity, fieldName, defaultValue, prefix=''){ if (activity[fieldName] === null || activity[fieldName] === undefined) { @@ -88,7 +88,7 @@ export function getField(activity, fieldName, defaultValue, prefix=''){ * @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)