Working date changer!

This commit is contained in:
Anthony Cicchetti 2020-05-23 23:52:29 -04:00
parent 95eb73a166
commit 72318bb286
2 changed files with 31 additions and 4 deletions

View file

@ -1,13 +1,24 @@
'use strict'; 'use strict';
var Curry = require("bs-platform/lib/js/curry.js");
var React = require("react"); var React = require("react");
var Moment = require("moment"); var Moment = require("moment");
function DatePicker(Props) { function DatePicker(Props) {
var date = Moment().format("YYYY-MM-DD"); var match = React.useState((function () {
return Moment();
}));
var updateDate = match[1];
var handleChange = function ($$event) {
var value = $$event.target.value;
return Curry._1(updateDate, (function (param) {
return Moment(value, "YYYY-MM-DD");
}));
};
return React.createElement(React.Fragment, undefined, React.createElement("input", { return React.createElement(React.Fragment, undefined, React.createElement("input", {
type: "date", type: "date",
value: date value: match[0].format("YYYY-MM-DD"),
onChange: handleChange
})); }));
} }

View file

@ -1,5 +1,21 @@
type formattedString = string;
[@react.component] [@react.component]
let make = () => { let make = () => {
let date = MomentRe.momentNow() |> MomentRe.Moment.format("YYYY-MM-DD"); let (date: MomentRe.Moment.t, updateDate) =
<> <input type_="date" value=date /> </>; React.useState(MomentRe.momentNow);
let formatDate: MomentRe.Moment.t => formattedString =
(date: MomentRe.Moment.t) => {
date |> MomentRe.Moment.format("YYYY-MM-DD");
};
let handleChange = (event: ReactEvent.Form.t) => {
let value: formattedString = ReactEvent.Form.target(event)##value;
updateDate(_ => {value->MomentRe.momentWithFormat("YYYY-MM-DD")});
};
<>
<input type_="date" value={formatDate(date)} onChange=handleChange />
</>;
}; };