-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replaced moment with dayjs fixed issue #34 #47
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This configuration file was automatically generated by Gitpod. | ||
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) | ||
# and commit this file to your remote git repository to share the goodness with others. | ||
|
||
tasks: | ||
- init: yarn install && yarn run build | ||
command: yarn run start | ||
vscode: | ||
extensions: | ||
- dbaeumer.vscode-eslint | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,28 +13,35 @@ import { | |
Alert, | ||
AlertIcon, | ||
} from "@chakra-ui/react"; | ||
import moment from "moment"; | ||
import Datetime from "react-datetime"; | ||
import constants from "../../utils/constants"; | ||
import { useTimeQuerierStore } from "../../store/timeQuerier"; | ||
import dayjs from "dayjs"; | ||
import DateFnsUtils from "@date-io/date-fns"; | ||
import { | ||
MuiPickersUtilsProvider, | ||
KeyboardDatePicker, | ||
} from "@material-ui/pickers"; | ||
|
||
const TimeQuerier: React.FC = () => { | ||
const styles = useStyleConfig("DateTime", {}); | ||
const { selectedStartTimestamp, selectedEndTimestamp, changeTimeQuerier } = | ||
useTimeQuerierStore(); | ||
const { | ||
selectedStartTimestamp, | ||
selectedEndTimestamp, | ||
changeTimeQuerier, | ||
} = useTimeQuerierStore(); | ||
const { defaultStepValue, minStepValue, dateFormat, timeFormat } = constants; | ||
const [startTime, setStartTime] = useState(moment(selectedStartTimestamp)); | ||
const [endTime, setEndTime] = useState(moment(selectedEndTimestamp)); | ||
const [startTime, setStartTime] = useState(dayjs(selectedStartTimestamp)); | ||
const [endTime, setEndTime] = useState(dayjs(selectedEndTimestamp)); | ||
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say keep the start and end times in the redux store (and persist them too) so that it is maintained across refreshes (mostly people do not like dates getting reset) |
||
const [stepTime, setStepTime] = useState(defaultStepValue); | ||
const [error, setError] = useState<undefined | string>(undefined); | ||
|
||
const handleStartChange = (date: moment.Moment | string) => { | ||
const handleStartChange = (date: dayjs.Dayjs | string) => { | ||
if (typeof date !== "string") { | ||
setStartTime(date); | ||
setError(undefined); | ||
} | ||
}; | ||
const handleEndChange = (date: moment.Moment | string) => { | ||
const handleEndChange = (date: dayjs.Dayjs | string) => { | ||
if (typeof date !== "string") { | ||
setEndTime(date); | ||
setError(undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error is either |
||
|
@@ -44,13 +51,13 @@ const TimeQuerier: React.FC = () => { | |
if (valueAsString !== "" && valueAsNumber >= minStepValue) | ||
setStepTime(valueAsNumber); | ||
}; | ||
const valid = (current: moment.Moment) => { | ||
return current.isBefore(moment()); | ||
const valid = (current: dayjs.Dayjs) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the |
||
return current.isBefore(dayjs()); | ||
}; | ||
const handleFetchTimeSeriesData = () => { | ||
if ( | ||
endTime.isBefore(startTime) || | ||
endTime.isAfter(moment()) || | ||
endTime.isAfter(dayjs()) || | ||
stepTime < minStepValue | ||
) | ||
setError("Kindy check your input"); | ||
|
@@ -74,14 +81,21 @@ const TimeQuerier: React.FC = () => { | |
> | ||
<Text>Start Time</Text> | ||
<Box sx={styles}> | ||
<Datetime | ||
value={startTime} | ||
dateFormat={dateFormat} | ||
timeFormat={timeFormat} | ||
inputProps={{ className: "custom-datepicker start-time" }} | ||
onChange={handleStartChange} | ||
isValidDate={valid} | ||
/> | ||
<MuiPickersUtilsProvider utils={DateFnsUtils}> | ||
<KeyboardDatePicker | ||
disableToolbar | ||
variant="inline" | ||
format="MM/dd/yyyy" | ||
margin="normal" | ||
id="date-picker-inline" | ||
value={startTime} | ||
isValidDate={valid} | ||
onChange={handleStartChange} | ||
KeyboardButtonProps={{ | ||
"aria-label": "change date", | ||
}} | ||
/> | ||
</MuiPickersUtilsProvider> | ||
</Box> | ||
</Box> | ||
<Box | ||
|
@@ -93,14 +107,21 @@ const TimeQuerier: React.FC = () => { | |
> | ||
<Text>End Time</Text> | ||
<Box sx={styles}> | ||
<Datetime | ||
value={endTime} | ||
dateFormat={dateFormat} | ||
timeFormat={timeFormat} | ||
inputProps={{ className: "custom-datepicker end-time" }} | ||
onChange={handleEndChange} | ||
isValidDate={valid} | ||
/> | ||
<MuiPickersUtilsProvider utils={DateFnsUtils}> | ||
<KeyboardDatePicker | ||
disableToolbar | ||
variant="inline" | ||
format="MM/dd/yyyy" | ||
margin="normal" | ||
id="date-picker-inline" | ||
value={endTime} | ||
isValidDate={valid} | ||
onChange={handleEndChange} | ||
KeyboardButtonProps={{ | ||
"aria-label": "change date", | ||
}} | ||
/> | ||
</MuiPickersUtilsProvider> | ||
</Box> | ||
</Box> | ||
<Box | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be a part of this PR