-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from jfhdgkjfh/module8-task3
- Loading branch information
Showing
46 changed files
with
1,566 additions
and
1,183 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ | |
"dayjs": "1.11.7", | ||
"flatpickr": "^4.6.13", | ||
"he": "^1.2.0", | ||
"nanoid": "^5.0.7", | ||
"style-loader": "^3.3.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,125 @@ | ||
const COLORS = ['black', 'yellow', 'blue', 'green', 'pink']; | ||
import dayjs from 'dayjs'; | ||
import { futurePoint, presentPoint, pastPoint, sortByDay, sortByPrice, sortByTime } from './utils/point-utils'; | ||
|
||
const DEFAULT_TYPE = 'taxi'; | ||
const CITIES_LENGTH_BORDER = 3; | ||
const AUTHORIZATION = 'Basic hS2sfS44wcl321211'; | ||
const END_POINT = 'https://21.objects.htmlacademy.pro/big-trip'; | ||
|
||
const DISABLED_SORTS = [ | ||
'event', | ||
'offers' | ||
]; | ||
|
||
const EMPTY_POINT = { | ||
type: DEFAULT_TYPE, | ||
basePrice: 0, | ||
dateFrom: dayjs().toDate(), | ||
dateTo: dayjs().toDate(), | ||
destination: null, | ||
isFavorite: false, | ||
offers: [] | ||
}; | ||
|
||
const EVENTS = [ | ||
'Bus', | ||
'Drive', | ||
'Flight', | ||
'Ship', | ||
'Taxi', | ||
'Train', | ||
'Check-in', | ||
'Restaurant', | ||
'Sightseeing' | ||
]; | ||
|
||
const FilterType = { | ||
ALL: 'all', | ||
OVERDUE: 'overdue', | ||
TODAY: 'today', | ||
FAVORITES: 'favorites', | ||
REPEATING: 'repeating', | ||
ARCHIVE: 'archive', | ||
EVERYTHING: 'everything', | ||
FUTURE: 'future', | ||
PRESENT: 'present', | ||
PAST: 'past', | ||
}; | ||
|
||
const filters = { | ||
[FilterType.EVERYTHING]: (points) => points, | ||
[FilterType.FUTURE]: (points) => points.filter((point) => futurePoint(point)), | ||
[FilterType.PRESENT]: (points) => points.filter((point) => presentPoint(point)), | ||
[FilterType.PAST]: (points) => points.filter((point) => pastPoint(point)), | ||
}; | ||
|
||
const Mode = { | ||
DEFAULT: 'DEFAULT', | ||
EDITING: 'EDITING', | ||
}; | ||
|
||
const SortType = { | ||
DEFAULT: 'default', | ||
DATE_DOWN: 'date-down', | ||
DATE_UP: 'date-up', | ||
DAY: 'day', | ||
EVENT: 'event', | ||
TIME: 'time', | ||
PRICE: 'price', | ||
OFFERS: 'offers' | ||
}; | ||
|
||
const UserAction = { | ||
UPDATE_TASK: 'UPDATE_TASK', | ||
ADD_TASK: 'ADD_TASK', | ||
DELETE_TASK: 'DELETE_TASK', | ||
UPDATE_POINT: 'UPDATE_POINT', | ||
ADD_POINT: 'ADD_POINT', | ||
DELETE_POINT: 'DELETE_POINT', | ||
}; | ||
|
||
const UpdateType = { | ||
PATCH: 'PATCH', | ||
MINOR: 'MINOR', | ||
MAJOR: 'MAJOR', | ||
INIT: 'INIT' | ||
}; | ||
|
||
const ButtonText = { | ||
CANCEL: 'Cancel', | ||
DELETE: 'Delete', | ||
DELETING: 'Deleting', | ||
SAVE: 'Save', | ||
SAVING: 'Saving', | ||
}; | ||
|
||
const Method = { | ||
GET: 'GET', | ||
PUT: 'PUT', | ||
DELETE: 'DELETE', | ||
POST: 'POST', | ||
}; | ||
|
||
const NoPointsTextType = { | ||
NOPOINTS: 'Click New Event to create your first point', | ||
LOADING: 'Loading...', | ||
}; | ||
|
||
const TimeLimit = { | ||
LOWER_LIMIT: 350, | ||
UPPER_LIMIT: 1000 | ||
}; | ||
|
||
const Sort = { | ||
[SortType.DAY]: (points) => [...points].sort(sortByDay), | ||
[SortType.TIME]: (points) => [...points].sort(sortByTime), | ||
[SortType.PRICE]: (points) => [...points].sort(sortByPrice), | ||
}; | ||
|
||
export { | ||
EVENTS, | ||
TimeLimit, | ||
FilterType, | ||
filters, | ||
Mode, | ||
SortType, | ||
Sort, | ||
EMPTY_POINT, | ||
UserAction, | ||
NoPointsTextType, | ||
UpdateType, | ||
ButtonText, | ||
DISABLED_SORTS, | ||
Method, | ||
CITIES_LENGTH_BORDER, | ||
AUTHORIZATION, | ||
END_POINT | ||
}; | ||
export {COLORS, FilterType, SortType, UserAction, UpdateType}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,18 @@ | ||
/** | ||
* Класс, реализующий паттерн Наблюдатель. | ||
*/ | ||
|
||
export default class Observable { | ||
/** @type {Set<observerCallback>} Множество функций типа observerCallback */ | ||
|
||
#observers = new Set(); | ||
|
||
/** | ||
* Метод, позволяющий подписаться на событие | ||
* @param {observerCallback} observer Функция, которая будет вызвана при наступлении события | ||
*/ | ||
addObserver(observer) { | ||
this.#observers.add(observer); | ||
} | ||
|
||
/** | ||
* Метод, позволяющий отписаться от события | ||
* @param {observerCallback} observer Функция, которую больше не нужно вызывать при наступлении события | ||
*/ | ||
|
||
removeObserver(observer) { | ||
this.#observers.delete(observer); | ||
} | ||
|
||
/** | ||
* Метод для оповещения подписчиков о наступлении события | ||
* @param {*} event Тип события | ||
* @param {*} payload Дополнительная информация | ||
*/ | ||
_notify(event, payload) { | ||
this.#observers.forEach((observer) => observer(event, payload)); | ||
} | ||
} | ||
|
||
/** | ||
* Функция, которая будет вызвана при наступлении события | ||
* @callback observerCallback | ||
* @param {*} event Тип события | ||
* @param {*} [payload] Дополнительная информация | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.