From e0f54e53d957022436e1c5616fda09016da45549 Mon Sep 17 00:00:00 2001
From: Stefano Pigozzi <256895@studenti.unimore.it>
Date: Fri, 30 Apr 2021 16:37:28 +0200
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20component=20BoxConditionDatet?=
=?UTF-8?q?ime?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/components/base/Button.module.css | 2 +-
.../components/base/ButtonIconOnly.module.css | 2 +
.../interactive/BoxConditionDatetime.js | 100 ++++++++++++++++++
.../interactive/ButtonToggleBeforeAfter.js | 25 +++++
.../ButtonToggleBeforeAfter.module.css | 4 +
code/frontend/src/routes/PageDashboard.js | 7 +-
6 files changed, 134 insertions(+), 6 deletions(-)
create mode 100644 code/frontend/src/components/interactive/BoxConditionDatetime.js
create mode 100644 code/frontend/src/components/interactive/ButtonToggleBeforeAfter.js
create mode 100644 code/frontend/src/components/interactive/ButtonToggleBeforeAfter.module.css
diff --git a/code/frontend/src/components/base/Button.module.css b/code/frontend/src/components/base/Button.module.css
index 7d30299..3976477 100644
--- a/code/frontend/src/components/base/Button.module.css
+++ b/code/frontend/src/components/base/Button.module.css
@@ -5,7 +5,7 @@
border-radius: 25px;
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25);
- padding: 10px;
+ padding: 5px;
margin: 0 2px;
cursor: pointer;
diff --git a/code/frontend/src/components/base/ButtonIconOnly.module.css b/code/frontend/src/components/base/ButtonIconOnly.module.css
index fb80757..1230401 100644
--- a/code/frontend/src/components/base/ButtonIconOnly.module.css
+++ b/code/frontend/src/components/base/ButtonIconOnly.module.css
@@ -2,4 +2,6 @@
width: 40px;
height: 40px;
border-radius: 20px;
+
+ flex-shrink: 0;
}
diff --git a/code/frontend/src/components/interactive/BoxConditionDatetime.js b/code/frontend/src/components/interactive/BoxConditionDatetime.js
new file mode 100644
index 0000000..e2d3d33
--- /dev/null
+++ b/code/frontend/src/components/interactive/BoxConditionDatetime.js
@@ -0,0 +1,100 @@
+import React, { useState } from "react"
+import BoxFull from "../base/BoxFull"
+import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
+import { faAt, faClock, faPlus } from "@fortawesome/free-solid-svg-icons"
+import InputWithIcon from "../base/InputWithIcon"
+import FormInline from "../base/FormInline"
+import Style from "./BoxConditionHashtag.module.css"
+import ButtonIconOnly from "../base/ButtonIconOnly"
+import useRepositoryEditor from "../../hooks/useRepositoryEditor"
+import FormLabelled from "../base/FormLabelled"
+import FormLabel from "../base/formparts/FormLabel"
+import Radio from "../base/Radio"
+import ButtonToggleBeforeAfter from "./ButtonToggleBeforeAfter"
+
+
+const INVALID_USER_CHARACTERS = /[^0-9TZ:-]/g
+
+
+/**
+ * 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 }) {
+ const [datetime, setDatetime] = useState("")
+ const [ba, setBa] = useState(false)
+ const {conditions, appendCondition} = useRepositoryEditor()
+
+ const onInputChange = event => {
+ let text = event.target.value
+ text = text.toUpperCase()
+ text = text.replace(INVALID_USER_CHARACTERS, "")
+ return setDatetime(text)
+ }
+
+ const onButtonClick = () => {
+
+
+ const newCond = {
+ "id": null,
+ "type": 2,
+ "content": `${ba ? ">" : "<"} ${datetime}`
+ }
+
+ const date = new Date(datetime)
+ if(date.toString() === "Invalid Date") {
+ console.debug("Refusing to append ", newCond, " to the Conditions list, as it is invalid.")
+ return
+ }
+
+ if(datetime === "") {
+ console.debug("Refusing to append ", newCond, " to the Conditions list, as it is empty.")
+ return
+ }
+
+ let duplicate = null;
+ for(const oldCond of conditions) {
+ if(newCond.type === oldCond.type && newCond.content === oldCond.content) {
+ duplicate = oldCond;
+ break;
+ }
+ }
+
+ if(duplicate) {
+ console.debug("Refusing to append ", newCond, " to the Conditions list, as ", duplicate, " already exists.")
+ }
+ else {
+ console.debug("Appending ", newCond, " to the Conditions list")
+ appendCondition(newCond)
+ }
+
+ setDatetime("")
+ }
+
+ return (
+ Search by time period} {...props}>
+
+
+
+
+
+
+ )
+}
diff --git a/code/frontend/src/components/interactive/ButtonToggleBeforeAfter.js b/code/frontend/src/components/interactive/ButtonToggleBeforeAfter.js
new file mode 100644
index 0000000..14f5667
--- /dev/null
+++ b/code/frontend/src/components/interactive/ButtonToggleBeforeAfter.js
@@ -0,0 +1,25 @@
+import React, { useState } from "react"
+import Style from "./ButtonToggleBeforeAfter.module.css"
+import classNames from "classnames"
+import Button from "../base/Button"
+
+
+export default function ButtonToggleBeforeAfter({ onUpdate, className, ...props }) {
+ const [value, setValue] = useState(false)
+
+ const onButtonClick = () => {
+ onUpdate(!value)
+ setValue(value => !value)
+ }
+
+ return (
+
+ )
+}
diff --git a/code/frontend/src/components/interactive/ButtonToggleBeforeAfter.module.css b/code/frontend/src/components/interactive/ButtonToggleBeforeAfter.module.css
new file mode 100644
index 0000000..f65612d
--- /dev/null
+++ b/code/frontend/src/components/interactive/ButtonToggleBeforeAfter.module.css
@@ -0,0 +1,4 @@
+.ButtonToggleBeforeAfter {
+ width: 75px;
+ height: 28px;
+}
diff --git a/code/frontend/src/routes/PageDashboard.js b/code/frontend/src/routes/PageDashboard.js
index aa476bf..3e53db2 100644
--- a/code/frontend/src/routes/PageDashboard.js
+++ b/code/frontend/src/routes/PageDashboard.js
@@ -13,6 +13,7 @@ import FormLabel from "../components/base/formparts/FormLabel"
import RepositoryEditor from "../components/providers/RepositoryEditor"
import BoxConditionHashtag from "../components/interactive/BoxConditionHashtag"
import BoxConditions from "../components/interactive/BoxConditions"
+import BoxConditionDatetime from "../components/interactive/BoxConditionDatetime"
export default function PageDashboard({ children, className, ...props }) {
@@ -28,11 +29,7 @@ export default function PageDashboard({ children, className, ...props }) {
🚧 Not implemented.
- Search by time period
- }>
- 🚧 Not implemented.
-
+