From 5f6cb0350a6e0bdf8519e65a18be895d7f9afb29 Mon Sep 17 00:00:00 2001 From: sancodes Date: Mon, 21 Jun 2021 21:49:42 -0700 Subject: [PATCH] add changes to variable and function names --- src/components/Header/Header.js | 4 +- src/components/TimeTable/TimeTableView.js | 4 +- src/components/utils.js | 58 ++++++++++++----------- src/index.js | 4 +- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/components/Header/Header.js b/src/components/Header/Header.js index 9bf0295..7957271 100644 --- a/src/components/Header/Header.js +++ b/src/components/Header/Header.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { Text, View } from 'react-native'; import moment from 'moment'; -import { getFormattedDate } from '../utils'; +import { formatDate } from '../utils'; import styles from './Header.styles'; @@ -39,7 +39,7 @@ const Column = ({ return ( - {getFormattedDate(column, format)} + {formatDate(column, format)} ); diff --git a/src/components/TimeTable/TimeTableView.js b/src/components/TimeTable/TimeTableView.js index 58643c8..39d9fcb 100644 --- a/src/components/TimeTable/TimeTableView.js +++ b/src/components/TimeTable/TimeTableView.js @@ -6,7 +6,7 @@ import { Text, } from 'react-native'; import moment from 'moment'; -import { setLocale, addColor, genTimeBlock } from '../utils'; +import { setLocale, assignColor, genTimeBlock } from '../utils'; import Events from '../Events/Events'; import Header from '../Header/Header'; import styles from './TimeTableView.styles'; @@ -55,7 +55,7 @@ export default class TimeTableView extends Component { onEventPress, pivotTime, } = this.props; - const events = addColor(this.props.events); + const events = assignColor(this.props.events); const { currentMoment } = this.state; // const dates = this.prepareDates(currentMoment, numberOfDays); const date = moment(currentMoment); diff --git a/src/components/utils.js b/src/components/utils.js index 176b72f..1816baa 100644 --- a/src/components/utils.js +++ b/src/components/utils.js @@ -1,6 +1,6 @@ import moment from 'moment/min/moment-with-locales.js'; -export const getFormattedDate = (date, format) => { +export const formatDate = (date, format) => { return moment(date).format(format); }; @@ -8,19 +8,21 @@ export const setLocale = (locale) => { moment.locale(locale); }; -export const getCurrentMonth = (date) => { - return moment(date).format('MMMM Y'); -}; +//this function should be removed +// export const getCurrentMonth = (date) => { +// return moment(date).format('MMMM Y'); +// }; -const genDayOfWeek = (DayOfWeekString) => { +const genDateBlock = (dayOW) => { /* DayOfWeekString : SUN, MON, TUE, WED, THU, FRI, SAT type : string */ if (typeof DayOfWeekString !== 'string') { - throw new Error(`genDayOfWeek got parameter type: ${typeof DayOfWeekString}, but string expected`); + throw new Error(`genDateBlock got parameter type: ${typeof dayOW}, but string expected`); } - const str2numberString = { + + const dayOWMap = { 'mon': '01', 'tue': '02', 'wed': '03', @@ -36,11 +38,11 @@ const genDayOfWeek = (DayOfWeekString) => { '토': '06', }; - return new Date(`2019-07-${str2numberString[DayOfWeekString.toLowerCase()]}T00:00:00`); + return new Date(`2019-07-${dayOWMap[DayOfWeekString.toLowerCase()]}T00:00:00`); }; -const genTimeBlock = (dayOfWeek, hours = 0, minutes = 0) => { - const date = genDayOfWeek(dayOfWeek); +const genTimeBlock = (dayOW, hours = 0, minutes = 0) => { + const date = genDateBlock(dayOW); date.setHours(hours); if (minutes != null) { date.setMinutes(minutes); @@ -48,7 +50,7 @@ const genTimeBlock = (dayOfWeek, hours = 0, minutes = 0) => { return date; }; -const addColor = (events) => { +const assignColor = (events) => { // add color to item return events.reduce((acc, item, idx) => { const sameOne = acc.find((elem) => { @@ -62,28 +64,28 @@ const addColor = (events) => { }, []).length; acc.push({ ...item, - color: sameOne === undefined ? colorGenerator(count) : sameOne.color, + color: sameOne === undefined ? pickColor(count) : sameOne.color, id: idx, }); return acc; }, []); }; +//this function should be removed +// const hashString = (s) => { +// /** +// * String -> Number +// */ +// let h, i; +// for (i = 0, h = 0; i < s.length; i++) { +// // eslint-disable-next-line no-bitwise +// h = Math.imul(31, h) + s.charCodeAt(i) | 0; +// } +// return Math.abs(h); +// }; -const hashString = (s) => { - /** - * String -> Number - */ - let h, i; - for (i = 0, h = 0; i < s.length; i++) { - // eslint-disable-next-line no-bitwise - h = Math.imul(31, h) + s.charCodeAt(i) | 0; - } - return Math.abs(h); -}; - -const colorGenerator = (num) => { - const color_list = [ +const pickColor = (num) => { + const colorList = [ // apple calendar color 'rgba(246,206,218,1)', 'rgba(250,227,209,1)', @@ -122,8 +124,8 @@ const colorGenerator = (num) => { 'rgba(129,199,132,1)', 'rgba(184,0,0,1)', ]; - return color_list[num % color_list.length]; + return colorList[num % colorList.length]; }; -export {genDayOfWeek, genTimeBlock, colorGenerator, addColor}; +export { genDateBlock, genTimeBlock, pickColor, assignColor }; diff --git a/src/index.js b/src/index.js index 58ea850..616288c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ import TimeTableView from './components/TimeTable/TimeTableView'; -import { genTimeBlock, addColor } from './components/utils'; +import { genTimeBlock, assignColor } from './components/utils'; export { TimeTableView as default }; -export { genTimeBlock, addColor }; +export { genTimeBlock, assignColor };