1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 13:34:19 +00:00
pds-2021-g2-nest/nest_frontend/components/interactive/BoxConditionDatetime.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

import React, { useContext } from "react"
2021-04-30 14:37:28 +00:00
import BoxFull from "../base/BoxFull"
2021-05-11 14:37:15 +00:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faClock } from "@fortawesome/free-solid-svg-icons"
2021-04-30 14:37:28 +00:00
import useRepositoryEditor from "../../hooks/useRepositoryEditor"
2021-05-07 03:02:20 +00:00
import Condition from "../../utils/Condition"
import convertToLocalISODate from "../../utils/convertToLocalISODate"
2021-05-18 00:04:06 +00:00
import ContextLanguage from "../../contexts/ContextLanguage"
import FormInlineBADatetime from "./FormInlineBADatetime"
2021-04-30 14:37:28 +00:00
/**
* A {@link BoxFull} that allows the user to select a Twitter user to search for, and then to add it as a Condition
* to the {@link ContextRepositoryEditor}.
*
* @param props - Additional props to pass to the box.
* @returns {JSX.Element}
* @constructor
*/
export default function BoxConditionDatetime({ ...props }) {
2021-05-11 14:37:15 +00:00
const { addCondition } = useRepositoryEditor()
2021-05-18 00:48:34 +00:00
const { strings } = useContext(ContextLanguage)
2021-04-30 14:37:28 +00:00
const submit = ({ date, isBefore }) => {
if(date.toString() === "Invalid Date") {
console.debug("Refusing to add condition: ", date, " is an Invalid Date.")
2021-04-30 14:37:28 +00:00
return
}
const aware = convertToLocalISODate(date)
addCondition(new Condition("TIME", `${isBefore ? "<" : ">"} ${aware}`))
2021-04-30 14:37:28 +00:00
}
return (
2021-05-17 23:33:08 +00:00
<BoxFull
header={
<span>
2021-05-18 00:04:06 +00:00
{strings.searchBy}
2021-05-17 23:33:08 +00:00
&nbsp;
<FontAwesomeIcon icon={faClock}/>
&nbsp;
2021-05-18 00:04:06 +00:00
{strings.byTimePeriod}
2021-05-17 23:33:08 +00:00
</span>
}
{...props}
>
<FormInlineBADatetime
submit={submit}
/>
2021-04-30 14:37:28 +00:00
</BoxFull>
)
}