Skip to content

Commit

Permalink
naming fix
Browse files Browse the repository at this point in the history
  • Loading branch information
InsomniaRolodex committed Jul 1, 2024
1 parent 2413feb commit 6db002c
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 36 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
webpack.config.js
src/mock/*
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"eslint": "8.38.0",
"eslint-config-htmlacademy": "9.0.0",
"html-webpack-plugin": "5.5.1",
"lodash": "4.17.21",
"webpack": "5.92.0",
"webpack-cli": "5.1.4",
"webpack-dev-server": "4.13.3"
Expand Down
4 changes: 3 additions & 1 deletion src/mock/points.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { toCamelCase } from '../util.js'

export const points = [
{
id: 'f4b62099-293f-4c3d-a702-94eec4a2808c',
Expand Down Expand Up @@ -47,4 +49,4 @@ export const defaultPoint = [
offers: [],
type: 'flight'
}
];
]
8 changes: 4 additions & 4 deletions src/presenter/header-presenter.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { render, RenderPosition } from '../render.js';
import Filters from '../view/filters-view.js';
import TripInfo from '../view/trip-info-view.js';
import FiltersView from '../view/filters-view.js';
import TripInfoView from '../view/trip-info-view.js';

export default class HeaderPresenter {
constructor ({ container }) {
this.container = container;
}

initInfo () {
render (new TripInfo, this.container, RenderPosition.AFTERBEGIN);
render (new TripInfoView, this.container, RenderPosition.AFTERBEGIN);
}

initFilters () {
render(new Filters, this.container);
render(new FiltersView, this.container);
}
}
20 changes: 10 additions & 10 deletions src/presenter/trip-presenter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { render } from '../render.js';
import CreateForm from '../view/create-form-view.js';
import EditForm from '../view/edit-form-view.js';
import Sorting from '../view/sorting-view.js';
import TripList from '../view/trip-list-view.js';
import TripPoint from '../view/trip-point-view.js';
import CreateFormView from '../view/create-form-view.js';
import EditFormView from '../view/edit-form-view.js';
import SortingView from '../view/sorting-view.js';
import TripListView from '../view/trip-list-view.js';
import TripPointView from '../view/trip-point-view.js';
import PointModel from '../model/point-model.js';

export default class TripPresenter {
tripList = new TripList();
tripList = new TripListView();

constructor ({ container, pointModel = new PointModel }) {
this.container = container;
Expand All @@ -21,13 +21,13 @@ export default class TripPresenter {
const offers = this.pointModel.getOffers();
const defaultPoint = this.pointModel.getDefaultPoint();

render(new Sorting, this.container);
render(new SortingView, this.container);
render(this.tripList, this.container);
render(new EditForm(points[0], destinations, offers), this.tripList.getElement());
render(new CreateForm(defaultPoint[0], destinations, offers), this.tripList.getElement());
render(new EditFormView(points[0], destinations, offers), this.tripList.getElement());
render(new CreateFormView(defaultPoint[0], destinations, offers), this.tripList.getElement());

points.forEach((point) => {
render(new TripPoint(point, destinations, offers), this.tripList.getElement());
render(new TripPointView(point, destinations, offers), this.tripList.getElement());
});
}
}
11 changes: 7 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import dayjs from 'dayjs';
import lodash from 'lodash';

const humanizeDueDate = (dueDate, dateFormat) => dueDate ? dayjs(dueDate).format(dateFormat) : '';

const capitalize = (str) => str[0].toUpperCase() + str.slice(1);

const findDuration = (date1, date2) => {
let minutesDuration = dayjs(date1).diff(dayjs(date2), 'm');
const minutes = minutesDuration % 60;
const minutesAfterHours = minutesDuration % 60;

if (minutesDuration >= 60 && minutes !== 0) {
if (minutesDuration >= 60 && minutesAfterHours !== 0) {
minutesDuration /= 60;

return `${Math.floor(minutesDuration)}H ${minutes}M`;
return `${Math.floor(minutesDuration)}H ${minutesAfterHours}M`;
}

if (minutesDuration >= 60) {
Expand All @@ -21,5 +22,7 @@ const findDuration = (date1, date2) => {
return `${Math.floor(minutesDuration)}H`;
};

const toCamelCase = (str) => lodash.camelCase(str);

export { humanizeDueDate, capitalize, findDuration };

export { humanizeDueDate, capitalize, findDuration, toCamelCase };
8 changes: 4 additions & 4 deletions src/view/create-form-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createElement } from '../render.js';
import { capitalize, humanizeDueDate } from '../util.js';

const dateFormat = {
fullDate: 'DD/MM/YY H:mm'
FULL_DATE: 'DD/MM/YY H:mm'
};

const createFormTemplate = (point, destinations, offers) => {
Expand Down Expand Up @@ -84,10 +84,10 @@ const createFormTemplate = (point, destinations, offers) => {
<div class="event__field-group event__field-group--time">
<label class="visually-hidden" for="event-start-time-1">From</label>
<input class="event__input event__input--time" id="event-start-time-1" type="text" name="${humanizeDueDate(dateFrom, dateFormat.fullDate)}" value="19/03/19 00:00">
<input class="event__input event__input--time" id="event-start-time-1" type="text" name="${humanizeDueDate(dateFrom, dateFormat.FULL_DATE)}" value="19/03/19 00:00">
&mdash;
<label class="visually-hidden" for="event-end-time-1">To</label>
<input class="event__input event__input--time" id="event-end-time-1" type="text" name="event-end-time" value="${humanizeDueDate(dateTo, dateFormat.fullDate)}">
<input class="event__input event__input--time" id="event-end-time-1" type="text" name="event-end-time" value="${humanizeDueDate(dateTo, dateFormat.FULL_DATE)}">
</div>
<div class="event__field-group event__field-group--price">
Expand Down Expand Up @@ -137,7 +137,7 @@ const createFormTemplate = (point, destinations, offers) => {
</li>`;
};

export default class CreateForm {
export default class CreateFormView {
constructor(points, destinations, offers) {
this.points = points;
this.destinations = destinations;
Expand Down
8 changes: 4 additions & 4 deletions src/view/edit-form-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createElement } from '../render.js';
import { capitalize, humanizeDueDate } from '../util.js';

const dateFormat = {
fullDate: 'DD/MM/YY H:mm'
FULL_DATE: 'DD/MM/YY H:mm'
};

const createEditFormTemplate = (point, destionations, offers) => {
Expand Down Expand Up @@ -85,10 +85,10 @@ const createEditFormTemplate = (point, destionations, offers) => {
<div class="event__field-group event__field-group--time">
<label class="visually-hidden" for="event-start-time-1">From</label>
<input class="event__input event__input--time" id="event-start-time-1" type="text" name="event-start-time" value="${humanizeDueDate(dateFrom, dateFormat.fullDate)}">
<input class="event__input event__input--time" id="event-start-time-1" type="text" name="event-start-time" value="${humanizeDueDate(dateFrom, dateFormat.FULL_DATE)}">
&mdash;
<label class="visually-hidden" for="event-end-time-1">To</label>
<input class="event__input event__input--time" id="event-end-time-1" type="text" name="event-end-time" value="${humanizeDueDate(dateTo, dateFormat.fullDate)}">
<input class="event__input event__input--time" id="event-end-time-1" type="text" name="event-end-time" value="${humanizeDueDate(dateTo, dateFormat.FULL_DATE)}">
</div>
<div class="event__field-group event__field-group--price">
Expand Down Expand Up @@ -131,7 +131,7 @@ const createEditFormTemplate = (point, destionations, offers) => {
</li>`;
};

export default class EditForm {
export default class EditFormView {
constructor(points, destionations, offers) {
this.points = points;
this.destionations = destionations;
Expand Down
2 changes: 1 addition & 1 deletion src/view/filters-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const createFilterTemplate = () => `
<button class="visually-hidden" type="submit">Accept filter</button>
</form>`;

export default class Filters {
export default class FiltersView {
getTemplate () {
return createFilterTemplate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/sorting-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const createSortingTemplate = () => `
${sortingTypes.map((sortingType) => createSortingElement(sortingType)).join('')}
</form>`;

export default class Sorting {
export default class SortingView {
getTemplate () {
return createSortingTemplate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/trip-info-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createTripInfoTemplate = () => `
</p>
</section>`;

export default class TripInfo {
export default class TripInfoView {
getTemplate() {
return createTripInfoTemplate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/trip-list-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const createTripListTemplate = () => `
<ul class="trip-events__list">
</ul>`;

export default class TripList {
export default class TripListView {
getTemplate () {
return createTripListTemplate();
}
Expand Down
10 changes: 5 additions & 5 deletions src/view/trip-point-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { capitalize, humanizeDueDate, findDuration } from '../util.js';

const dateFormat = {
MMMD: 'MMM D',
Hmm: 'H:mm',
duration: 'duration'
HMM: 'H:mm',
DURATION: 'duration'
};

const createTripPointTemplate = (point, destionations, offers) => {
Expand All @@ -22,9 +22,9 @@ const createTripPointTemplate = (point, destionations, offers) => {
<h3 class="event__title">${capitalize(point.type)} ${pointDestination}</h3>
<div class="event__schedule">
<p class="event__time">
<time class="event__start-time" datetime="${dateFrom}">${humanizeDueDate(dateFrom, dateFormat.Hmm)}</time>
<time class="event__start-time" datetime="${dateFrom}">${humanizeDueDate(dateFrom, dateFormat.HMM)}</time>
&mdash;
<time class="event__end-time" datetime="${dateTo}">${humanizeDueDate(dateTo, dateFormat.Hmm)}</time>
<time class="event__end-time" datetime="${dateTo}">${humanizeDueDate(dateTo, dateFormat.HMM)}</time>
</p>
<p class="event__duration">${findDuration(dateTo, dateFrom)}</p>
</div>
Expand Down Expand Up @@ -53,7 +53,7 @@ const createTripPointTemplate = (point, destionations, offers) => {
</li>`;
};

export default class TripPoint {
export default class TripPointView {
constructor(points, destionations, offers) {
this.points = points;
this.destionations = destionations;
Expand Down

0 comments on commit 6db002c

Please sign in to comment.