diff --git a/package.json b/package.json index d30587d3..4d375e7c 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "website:build:css": "cp ./node_modules/minireset.css/minireset.min.css ./website/styles/", "website:build:ts": "tsc --project ./website", "test": "run-s test:*", - "test:jest": "cross-env TZ=GMT jest", + "test:jest": "jest", "test:types": "tsc --noEmit && tsc --project ./website --noEmit", "lint:css": "stylelint --fix --ignore-path ./.gitignore --max-warnings 0 '**/*.{css,sass,scss}'", "lint:ts": "eslint --ext .ts,.tsx --fix --ignore-path ./.gitignore --max-warnings 0 '**/*.{ts,tsx}'", @@ -98,7 +98,6 @@ "@typescript-eslint/eslint-plugin": "^2.26.0", "@typescript-eslint/parser": "^2.26.0", "babel-loader": "^8.1.0", - "cross-env": "^7.0.2", "css-loader": "^3.4.0", "electron": "^8.2.0", "electron-builder": "^22.4.1", diff --git a/src/renderer/components/elements/editor/editor-toolbar/word-count/WordCount.tsx b/src/renderer/components/elements/editor/editor-toolbar/word-count/WordCount.tsx index 94bc7175..4f74c12c 100644 --- a/src/renderer/components/elements/editor/editor-toolbar/word-count/WordCount.tsx +++ b/src/renderer/components/elements/editor/editor-toolbar/word-count/WordCount.tsx @@ -1,3 +1,4 @@ +import { Moment } from "moment"; import React, { ReactElement } from "react"; import countWords from "word-count"; @@ -5,7 +6,7 @@ import { Entries } from "../../../../../types"; import { toIndexDate } from "../../../../../utils/dateFormat"; export interface StateProps { - dateSelected: Date; + dateSelected: Moment; entries: Entries; } diff --git a/src/renderer/components/elements/editor/editor/Editor.tsx b/src/renderer/components/elements/editor/editor/Editor.tsx index 901aa0d6..ba86bd58 100644 --- a/src/renderer/components/elements/editor/editor/Editor.tsx +++ b/src/renderer/components/elements/editor/editor/Editor.tsx @@ -14,6 +14,7 @@ import createListPlugin from "draft-js-list-plugin"; import PluginEditor from "draft-js-plugins-editor"; import debounce from "lodash.debounce"; import { draftToMarkdown, markdownToDraft } from "markdown-draft-js"; +import { Moment } from "moment"; import React, { KeyboardEvent, PureComponent, ReactNode } from "react"; import { Entries, IndexDate } from "../../../../types"; @@ -30,7 +31,7 @@ const listPlugin = createListPlugin(); const plugins = [listPlugin]; export interface StateProps { - dateSelected: Date; + dateSelected: Moment; entries: Entries; } @@ -41,7 +42,7 @@ export interface DispatchProps { type Props = StateProps & DispatchProps; interface State { - dateSelected: Date; + dateSelected: Moment; textEditorState: EditorState; titleEditorState: EditorState; } @@ -63,7 +64,7 @@ export default class Editor extends PureComponent { static getStateFromEntry( entries: Entries, - date: Date, + date: Moment, ): { textEditorState: EditorState; titleEditorState: EditorState } { const indexDate = toIndexDate(date); const entry = entries[indexDate]; diff --git a/src/renderer/components/elements/sidebar/calendar-nav/CalendarNav.tsx b/src/renderer/components/elements/sidebar/calendar-nav/CalendarNav.tsx index 8a28a750..07ed173b 100644 --- a/src/renderer/components/elements/sidebar/calendar-nav/CalendarNav.tsx +++ b/src/renderer/components/elements/sidebar/calendar-nav/CalendarNav.tsx @@ -1,16 +1,16 @@ import PrevIcon from "feather-icons/dist/icons/chevron-left.svg"; import NextIcon from "feather-icons/dist/icons/chevron-right.svg"; -import moment from "moment"; +import { Moment } from "moment"; import React, { ReactElement } from "react"; import { MAX_DATE, MIN_DATE } from "../../../../constants"; -import { toMonthYear } from "../../../../utils/dateFormat"; +import { createDate, parseDate, toMonthYear } from "../../../../utils/dateFormat"; import { translations } from "../../../../utils/i18n"; import { iconProps } from "../../../../utils/icons"; export interface StateProps { allowFutureEntries: boolean; - monthSelected: Date; + monthSelected: Moment; } export interface DispatchProps { @@ -28,11 +28,11 @@ export default function CalendarNav(props: Props): ReactElement { setMonthSelectedPrevious, } = props; - const today = moment(); + const today = createDate(); // Check if buttons for switching to previous/next month should be enabled. Determined based on // the min/max dates and whether future diary entries are allowed - const month = moment(monthSelected); + const month = parseDate(monthSelected); const canClickPrev = month.isAfter(MIN_DATE, "month"); const canClickNext = month.isBefore(MAX_DATE, "month") && (allowFutureEntries || month.isBefore(today, "month")); diff --git a/src/renderer/components/elements/sidebar/calendar/Calendar.tsx b/src/renderer/components/elements/sidebar/calendar/Calendar.tsx index 3f238935..b75696c7 100644 --- a/src/renderer/components/elements/sidebar/calendar/Calendar.tsx +++ b/src/renderer/components/elements/sidebar/calendar/Calendar.tsx @@ -1,23 +1,23 @@ -import moment from "moment"; +import { Moment } from "moment"; import React, { PureComponent, ReactNode } from "react"; import DayPicker from "react-day-picker"; import MomentLocaleUtils from "react-day-picker/moment"; import { Entries, Weekday } from "../../../../types"; -import { toIndexDate } from "../../../../utils/dateFormat"; +import { createDate, parseDate, toIndexDate } from "../../../../utils/dateFormat"; import { lang } from "../../../../utils/i18n"; import CalendarNavContainer from "../calendar-nav/CalendarNavContainer"; export interface StateProps { allowFutureEntries: boolean; - dateSelected: Date; + dateSelected: Moment; entries: Entries; firstDayOfWeek: Weekday | null; - monthSelected: Date; + monthSelected: Moment; } export interface DispatchProps { - setDateSelected: (date: Date) => void; + setDateSelected: (date: Moment) => void; } type Props = StateProps & DispatchProps; @@ -32,28 +32,31 @@ export default class Calendar extends PureComponent { onDateSelection(date: Date): void { const { allowFutureEntries, setDateSelected } = this.props; + const parsedDate = parseDate(date); + const today = createDate(); - if (allowFutureEntries || moment(date).isSameOrBefore(moment(), "day")) { - setDateSelected(date); + if (allowFutureEntries || parseDate(date).isSameOrBefore(today, "day")) { + setDateSelected(parsedDate); } } render(): ReactNode { const { allowFutureEntries, dateSelected, entries, firstDayOfWeek, monthSelected } = this.props; - const today = new Date(); + const today = createDate(); const daysWithEntries = Object.keys(entries); - const hasEntry = (day: Date): boolean => { - const indexDate = toIndexDate(day); + + const hasEntry = (date: Date): boolean => { + const indexDate = toIndexDate(parseDate(date)); return daysWithEntries.includes(indexDate); }; return ( null} modifiers={{ hasEntry }} firstDayOfWeek={firstDayOfWeek ?? undefined} diff --git a/src/renderer/components/elements/sidebar/calendar/CalendarContainer.tsx b/src/renderer/components/elements/sidebar/calendar/CalendarContainer.tsx index ddeef8fc..db38071c 100644 --- a/src/renderer/components/elements/sidebar/calendar/CalendarContainer.tsx +++ b/src/renderer/components/elements/sidebar/calendar/CalendarContainer.tsx @@ -1,3 +1,4 @@ +import { Moment } from "moment"; import { connect } from "react-redux"; import { setDateSelected } from "../../../../store/diary/actionCreators"; @@ -14,7 +15,7 @@ const mapStateToProps = (state: RootState): StateProps => ({ }); const mapDispatchToProps = (dispatch: ThunkDispatchT): DispatchProps => ({ - setDateSelected: (date: Date): SetDateSelectedAction => dispatch(setDateSelected(date)), + setDateSelected: (date: Moment): SetDateSelectedAction => dispatch(setDateSelected(date)), }); export default connect(mapStateToProps, mapDispatchToProps)(Calendar); diff --git a/src/renderer/components/elements/sidebar/search-bar/SearchBar.tsx b/src/renderer/components/elements/sidebar/search-bar/SearchBar.tsx index bd809839..1ad28ea9 100644 --- a/src/renderer/components/elements/sidebar/search-bar/SearchBar.tsx +++ b/src/renderer/components/elements/sidebar/search-bar/SearchBar.tsx @@ -1,21 +1,22 @@ import ClearIcon from "feather-icons/dist/icons/x.svg"; import debounce from "lodash.debounce"; -import moment from "moment"; +import { Moment } from "moment"; import React, { ChangeEvent, PureComponent, ReactNode } from "react"; import TodayIcon from "../../../../assets/icons/today.svg"; +import { createDate, parseDate } from "../../../../utils/dateFormat"; import { translations } from "../../../../utils/i18n"; import { iconProps } from "../../../../utils/icons"; export interface StateProps { - dateSelected: Date; - monthSelected: Date; + dateSelected: Moment; + monthSelected: Moment; searchKey: string; } export interface DispatchProps { search: (searchKey: string) => void; - setDateSelected: (date: Date) => void; + setDateSelected: (date: Moment) => void; } type Props = StateProps & DispatchProps; @@ -56,7 +57,7 @@ export default class SearchBar extends PureComponent { onTodaySelection(): void { const { setDateSelected } = this.props; - const today = new Date(); + const today = createDate(); setDateSelected(today); } @@ -77,9 +78,9 @@ export default class SearchBar extends PureComponent { const { dateSelected, monthSelected } = this.props; const { newSearchKey } = this.state; - const today = moment(); - const isToday = moment(dateSelected).isSame(today, "day"); - const isCurrentMonth = moment(monthSelected).isSame(today, "month"); + const today = createDate(); + const isToday = parseDate(dateSelected).isSame(today, "day"); + const isCurrentMonth = parseDate(monthSelected).isSame(today, "month"); return (
diff --git a/src/renderer/components/elements/sidebar/search-bar/SearchBarContainer.tsx b/src/renderer/components/elements/sidebar/search-bar/SearchBarContainer.tsx index 2c06ebf8..fb9336f2 100644 --- a/src/renderer/components/elements/sidebar/search-bar/SearchBarContainer.tsx +++ b/src/renderer/components/elements/sidebar/search-bar/SearchBarContainer.tsx @@ -1,3 +1,4 @@ +import { Moment } from "moment"; import { connect } from "react-redux"; import { search, setDateSelected } from "../../../../store/diary/actionCreators"; @@ -13,7 +14,7 @@ const mapStateToProps = (state: RootState): StateProps => ({ const mapDispatchToProps = (dispatch: ThunkDispatchT): DispatchProps => ({ search: (searchKey: string): void => dispatch(search(searchKey)), - setDateSelected: (date: Date): SetDateSelectedAction => dispatch(setDateSelected(date)), + setDateSelected: (date: Moment): SetDateSelectedAction => dispatch(setDateSelected(date)), }); export default connect(mapStateToProps, mapDispatchToProps)(SearchBar); diff --git a/src/renderer/components/elements/sidebar/search-results/SearchResults.tsx b/src/renderer/components/elements/sidebar/search-results/SearchResults.tsx index 58602a63..2cffcc7a 100644 --- a/src/renderer/components/elements/sidebar/search-results/SearchResults.tsx +++ b/src/renderer/components/elements/sidebar/search-results/SearchResults.tsx @@ -1,18 +1,19 @@ +import { Moment } from "moment"; import React, { PureComponent, ReactNode } from "react"; import { Entries } from "../../../../types"; -import { momentIndex, toDateString } from "../../../../utils/dateFormat"; +import { fromIndexDate, toDateString } from "../../../../utils/dateFormat"; import { translations } from "../../../../utils/i18n"; import Banner from "../../general/banner/Banner"; export interface StateProps { - dateSelected: Date; + dateSelected: Moment; entries: Entries; searchResults: string[]; } export interface DispatchProps { - setDateSelected: (date: Date) => void; + setDateSelected: (date: Moment) => void; } type Props = StateProps & DispatchProps; @@ -36,7 +37,7 @@ export default class SearchResults extends PureComponent { // Create search result element if a corresponding diary entry exists // (When deleting a diary entry after a search, it is still part of the search results // until a new search is performed. That's why it needs to be filtered out here) - const date = momentIndex(searchResult); + const date = fromIndexDate(searchResult); const { title } = entries[searchResult]; const isSelected = date.isSame(dateSelected, "day"); r.push( @@ -44,7 +45,7 @@ export default class SearchResults extends PureComponent {