aboutsummaryrefslogtreecommitdiff
path: root/frontend/src
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src')
-rw-r--r--frontend/src/DateInput.js35
-rw-r--r--frontend/src/SECAPIData.js85
2 files changed, 53 insertions, 67 deletions
diff --git a/frontend/src/DateInput.js b/frontend/src/DateInput.js
new file mode 100644
index 0000000..b5962f0
--- /dev/null
+++ b/frontend/src/DateInput.js
@@ -0,0 +1,35 @@
+// React import
+import { useEffect, useState, useRef } from "react";
+
+/**
+ * Componenet for checkins. Has a toggle to show more info.
+ * @param {Object} props The props of the component.
+ * @returns {import('react').HtmlHTMLAttributes} A list element holding a checkin's info.
+ */
+function DateInput(props) {
+ const startInput = useRef();
+ const endInput = useRef();
+
+ const toValue = date => date.toISOString().slice(0, 10);
+
+ useEffect(() => setInitDates(), []);
+
+ const setInitDates = () => {
+ startInput.current.value = toValue(new Date());
+
+ // Two weeks away -> from stack overflow,
+ const fortnightAway = toValue(new Date(Date.now() - 12096e5));
+ endInput.current.value = fortnightAway;
+ }
+
+ return (
+ <>
+ <label for="start">Start date:</label>
+ <input type="date" id="start" ref={startInput} onChange={(e) => props.setStart(e.target.value)}/>
+ <label for="end">End date:</label>
+ <input type="date" id="end" ref={endInput} onChange={(e) => props.setEnd(e.target.value)}/>
+ </>
+ );
+}
+
+export default DateInput; \ No newline at end of file
diff --git a/frontend/src/SECAPIData.js b/frontend/src/SECAPIData.js
index a209ff2..d14ee1f 100644
--- a/frontend/src/SECAPIData.js
+++ b/frontend/src/SECAPIData.js
@@ -1,89 +1,40 @@
import React, {useState, useEffect} from 'react';
import Button from './Button';
-import HubList from './HubList'
+import HubList from './HubList';
+import DateInput from './DateInput';
function SECAPIData() {
+ const [displayData, setDisplayData] = useState({});
+ const [startDate, setStartDate] = useState("");
+ const [endDate, setEndDate] = useState("");
- const [dataToBackend, setDataToBackend] = useState([]);
- const [displayData, setDisplayData] = useState("");
+ const toEpochMilli = date => Date.parse(date);
- const requestData = () => {
- // End early in debug to avoid too many requests.
- if (dataToBackend.length !== 0) {
- sendToBackend();
- return;
- }
-
- console.log("Makig request...");
-
- let date = new Date()
- let today = date.toISOString().slice(0, 10);
-
- let pastDate = new Date();
- pastDate.setDate(date.getDate() - 14);
- let past = pastDate.toISOString().slice(0, 10);
-
- fetch("https://api.sec-api.io?token=4d6ff81353d665c975d443e30020879b1ea882bc96a00cd8774a95bddd838fe5", {
+ const getLinks = () => {
+ fetch("http://localhost:4567/susrank", {
method: "POST",
- body: JSON.stringify({
- "query": { "query_string": { "query": "formType:4 AND filedAt:{"+ past +" TO "+ today +"} AND formType:(NOT \"N-4\") AND formType:(NOT \"4/A\")" } },
- "from": "0",
- "size": "1000",
- "sort": [{ "filedAt": { "order": "desc" } }]
- }),
- headers: {
- "Content-Type": "application/json"
- },
- credentials: "same-origin"
- })
- .then(res => res.json())
- .then(data => {
- let list = [];
- data.filings.forEach(filing => {
- if (filing.ticker === "") {
- // TODO: why are there repitions of urls.
- list.push({
- timestamp: filing.filedAt,
- url: filing.documentFormatFiles[1].documentUrl
- });
- }
- })
- setDataToBackend(list);
- })
- .catch(error => {
- console.log(error);
- });
- }
-
- const sendToBackend = () => {
- console.log(dataToBackend);
-
- fetch("http://localhost:4567/data", {
- method: "POST",
- body: JSON.stringify({
- "data" : dataToBackend
- }),
+ body: JSON.stringify(
+ {
+ "start" : toEpochMilli(startDate),
+ "end" : toEpochMilli(endDate)
+ }),
headers: {
"Content-Type": "application/json",
},
credentials: "same-origin"
})
-
- .then(response => response.json().then(data => setDisplayData(data)))
- .catch(function (error) {
- console.log(error);
- });
+ .then(res => res.json())
+ .then(data => setDisplayData(data))
+ .catch(err => console.log(err));
}
-
- // This hook is autocalled once the setDataToBackend takes effect.
- useEffect(() => sendToBackend(), [dataToBackend]);
return (
<div>
<h1>SECAPIData</h1>
- <Button onPress={requestData}></Button>
+ <DateInput setStart={setStartDate} setEnd={setEndDate}></DateInput>
+ <Button onPress={getLinks}></Button>
<HubList data={displayData}></HubList>
</div>
);