Skip to content

Create meal-order-menu-container component. - #53

Open
PaulAgeyev wants to merge 190 commits into
masterfrom
menu-order-component
Open

Create meal-order-menu-container component.#53
PaulAgeyev wants to merge 190 commits into
masterfrom
menu-order-component

Conversation

@PaulAgeyev

@PaulAgeyevPaulAgeyev commented Mar 29, 2018

Copy link
Copy Markdown
Contributor

In this PR:

  • Created the following routing:

/#/menu/2018-03-21
/#/history/2018-02-22

  • Created meal-order-menu-container component that contains paper-tabs component that contains days for ordering dishes.

  • Created meal-order-drawer in the meal-order-client-app component that contains
    app-datepicker.

View on desktop and on mobile device:
untitled4

ds

untitled

PaulAgeyevand others added 30 commits March 29, 2018 16:27

@dkalinindkalinin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@@ -19,9 +19,8 @@
-->
<link rel="import" href="shell/meal-order-app-namespace.html">

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

URLs should be relative. First is block with dependencies imports, then after empty line goes block with project imports.

@@ -19,9 +19,8 @@
-->
<link rel="import" href="shell/meal-order-app-namespace.html">
<script src="../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please remove

icon="icons:date-range"
drawer-toggle></iron-icon>
</div>
</iron-pages>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please extract the <...toolbar> component.

*
* @typedef {Object} Menu the menu for the current date
*
* @property {String} Vendor a vendor name

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should be vendor

];
}

_getClassForDrawer(page) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_getDrawerClass

route="{{route}}"
pattern="/:page/:date"
data="{{routeData}}">
</app-route>

@dkalinindkalininApr 26, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is done in <app> component.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Can you please describe in more detail?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Is it good practice to change routing by two way binding in this case?

_changeSelectedDay() {
const date = new Date(this.routeData.date);

let dayOfTheWeek = date.toLocaleDateString("ru-RU", {weekday: 'long'});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please use const and method chain.


const day = {
day: date.getDate(),
dayOfTheWeek: dayOfTheWeek,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not to create two properties?

*/
selectedDay: {
type: Object,
computed: '_changeSelectedDay(routeData.date)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_changeSelectedDay -> getSelectedDay

*/
inputDate: {
type: String,
computed: '_changeCalendarDate(routeData.date)',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_changeSelectedDay -> getSelectedDay

@dkalinindkalinin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

}
}

_drawerToggle() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_toggleDrawer

}
if (this.routeData.page.startsWith("history")) {
if (!this.routeData.date) {
let yesterday = new Date(this.serverTime);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is server time string or Object?

}
if (this.routeData.page.startsWith("history")) {
if (!this.routeData.date) {
let yesterday = new Date(this.serverTime);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

yesterday is not yesterday, it's a server date.

}
if (this.routeData.page.startsWith("history")) {
if (!this.routeData.date) {
let yesterday = new Date(this.serverTime);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not a const?

display: none;
};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please remove redundant empty line.

return menus.filter(menu => menu.date.getTime() === routeDate.getTime());
}

_getMenuDatesForWeek(menus) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_getDisplayedDays

return dayOfTheWeek;
}

_getMenuForDay(date) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

getDisplayedMenu


_getMenuDatesForWeek(menus) {
const weekDates = [];
let menuDates = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

const

for (let i = 0; i < DAYS_IN_PERIOD; i++) {
let tempDate = new Date();
tempDate.setDate(this.serverTime.getDate() + i);
tempDate.setMonth(this.serverTime.getMonth());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

const newDate = new Date(serverTime);
newDate.setDate(serverTime.getDate() + i);

const HOURS_PER_DAY = 86400000;
for (let i = 0; i < menuDates.length; i++) {
const diff = weekDates[i].getTime() - menuDates[i].getTime();
if (diff >= 0 && diff < HOURS_PER_DAY) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do we need this?

@PaulAgeyev

Copy link
Copy Markdown
ContributorAuthor

@dkalinin PTAL

@PaulAgeyev
PaulAgeyev requested review from alexanderkarpetc and removed request for alexanderkarpetcApril 30, 2018 13:41
…order-component
# Conflicts:
#	client/user/src/mealorder/meal-order-client-app.html
#	client/user/src/mealorder/menu/meal-order-drawer.html

@alexanderkarpetcalexanderkarpetc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See my comments

* @property {Number} month
* @property {Number} year
*
* @typedef {Array} Categories array contains the category name and dishes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You shouldn't duplicate word array

* @customElement
* @polymer
*/
class MealOrderToolbar extends (Polymer.Element) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Delete brackets

* @polymer
* @appliesMixin MealOrderApp.ReduxMixin
*/
class MealOrderMenuContainer extends (Polymer.Element) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Delete brackets


test('should instantiate the `meal-order-drawer` component', function (done) {
const elementShadowRoot = component.shadowRoot;
const drawer = elementShadowRoot.querySelector("meal-order-drawer");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Those tests look like you are testing polymer

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The component is checked for availability.

@dkalinindkalinin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if (!this.routeData.date) {
const newDate = new Date(this.serverTime);
newDate.setDate(newDate.getDate() - 1);
this.set('routeData.date', newDate.toISOString().slice(0, DATE_LENGTH));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.toISOString().slice(0, DATE_LENGTH) is repeated twice in a method.

*/
selectedDayOfTheWeek: {
type: Object,
computed: '_getSelectedDayOfTheWeek(routeData.date)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It should be a String. Also, we have two properties: selectedDay and selectedDayOfTheWeek. It's hard to find the difference by name or js doc. Let's rename selectedDayOfTheWeek to selectedDayName and extend the js doc.

<script>
{
/**
* menu-order is container for the vendors' menus and navigation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is a container. Also, please use `menu-order` when mention the tag name. Example: https://github.com/PolymerElements/paper-input/blob/master/paper-input.html

Also, check the js doc of other components.

* @polymer
* @appliesMixin MealOrderApp.ReduxMixin
*/
class MealOrderMenuContainer extends Polymer.Element {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It doesn't apply the mixin.

* Selected day.
*/
selectedDate: {
type: Object,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's a String, isn't it?

return date.toISOString().slice(0, DATE_LENGTH);
}

_getDayOfTheWeek(date) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's rename to _getWeekDayName.

* @typedef {Object} Date contains day, month, year
* @property {Number} day
* @property {Number} month
* @property {Number} year

@dkalinindkalininMay 10, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it property of type Object or Date?

}

_getDisplayedDays(menus) {
const weekDates = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

displayedDates


<paper-tabs id="paper-tabs" selected="[[selectedDate]]"
attr-for-selected='data-key'>
<template is="dom-repeat" items="{{displayedDays}}" as="calendar">

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's better to have the day alias instead of calendar.

if (weekDates[i].getTime() === uniqueDates[i].getTime()) {
weekDates[i].hasMenu = true;
}
}

@dkalinindkalininMay 10, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Too much logic to do simple things. All we need is:

  1. A simple array of 8 dates. It is used in top bar to render days.
  2. A Map which is computed from menus array. The key of map is a date, the value is an array of vendor menus by a key date. It's better to use menus.reduce(...) to compute the Map. In order to compute disabled state of day just call map.has(date).

@PaulAgeyev

Copy link
Copy Markdown
ContributorAuthor

@dkalinin PTAL

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@PaulAgeyev@dkalinin@alexanderkarpetc