Skip to content

Commit

Permalink
Merge pull request #50 from anna-huang17/add_button
Browse files Browse the repository at this point in the history
Add a button to load more dockets
  • Loading branch information
NateGaray authored Apr 25, 2024
2 parents 2579788 + d8a4f6a commit 873b651
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
6 changes: 6 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ h1{

}

.load-docket-button {
position: fixed;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
36 changes: 28 additions & 8 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState} from "react";
import React, {useState, useEffect} from "react";
import "./App.css";
// import {getDummyDataDemo} from "./static/script";
import {fetchDockets} from "./static/script";
Expand All @@ -7,29 +7,35 @@ import DocketList from "./components/DocketList";
import EmailVisibleInvisible from "./components/emailVisibleInvisible";

function App() {
const [dockets, setDockets] = useState(); // Initialize docket state to false
const [dockets, setDockets] = useState([]); // Initialize docket state to false
const [email, setEmail] = useState();
const [validTerm, setValidTerm] = useState(false);

const [totalResults, setTotalResults] = useState(0);
const [page, setPage] = useState(1);
const [term, setTerm] = useState("");

const handleOnClick = async (term) => {
const handleOnClick = async (newTerm) => {
try {
// This will display a message if the search term is invalid or no results are found
// It still has issues with some search terms such as ' ' (a single space)
if (!term) {

if (!newTerm) {
alert("Please enter a valid search term.");
return;
} else {
const data = await fetchDockets(term);
const data = await fetchDockets(newTerm, page);

if (data.data.dockets.length === 0) {
alert("No results found for: '" + term + "'");
alert("No results found for: '" + newTerm + "'");
return;
} else {
setDockets(data.data.dockets);
term === newTerm
? setDockets([...dockets, ...data.data.dockets])
: setDockets([...data.data.dockets]);
setValidTerm(true);
setTotalResults(data.meta.total_results);
term !== newTerm ? setPage(page + 1) : setPage(1);
}
}
} catch (error) {
Expand All @@ -52,13 +58,27 @@ function App() {
/> */}
<h1>Mirrulations Search</h1>
<div>
<SearchBar handleOnClick={handleOnClick} />
<SearchBar
handleOnClick={handleOnClick}
setPage={setPage}
setDockets={setDockets}
setTerm={setTerm}
/>
<EmailVisibleInvisible isVisible={validTerm} handleInputChange={handleInputChange} />
{/* list total number of dockets found for the term */}
{totalResults > 0 && <h2>{totalResults} Results Found</h2>}
{dockets && <DocketList dockets={dockets} email={email} />}{" "}
{/* Render SearchResultsList only if dockets is true */}
</div>
<div></div>
{dockets && dockets.length > 0 && (
<button
onClick={() => {
handleOnClick(term);
}}>
Show More Dockets
</button>
)}
</div>
);
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/SearchBar.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, {useState} from "react";
import "../styles/SearchBar.css";

const SearchBar = ({handleOnClick}) => {
const SearchBar = ({handleOnClick, setPage, setDockets, setTerm}) => {
const [query, setQuery] = useState("");

const handleInputChange = (event) => {
setQuery(event.target.value);
};

const handleSearch = () => {
setTerm(query);
handleOnClick(query);
};

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/ZipButton.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React, {useState} from "react";
import React, {useState, useEffect} from "react";
import "../styles/ZipButton.css";
import {zipFiles} from "../static/script";

const ZipButton = ({email, id}) => {
const [clicked, setClicked] = useState(false);

useEffect(() => {
setClicked(false);
}, [id]);

const handleClick = () => {
alert(`An email containing a downloadable version of the docket has been sent`);
setClicked(true);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/static/script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const URL = window.location.href;

// api.js
export const fetchDockets = async (searchTerm) => {
export const fetchDockets = async (searchTerm, page) => {
try {
const search =
URL +
`api/search_dockets?term=${searchTerm.replaceAll("/", "").replaceAll("'", "").replaceAll('"', "")}`;
`api/search_dockets?term=${searchTerm.replaceAll("/", "").replaceAll("'", "").replaceAll('"', "")}&page=${page}`;
const response = await fetch(search);

const data = await response.json();
Expand Down
1 change: 1 addition & 0 deletions frontend/src/styles/Docket.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
.h-row2 {
display: flex;
flex-direction: row;
font-weight: bold;
width: 100%;
height: inherit;
text-align: left;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/styles/ZipButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
button:hover {
background-color: #45a049;
}

0 comments on commit 873b651

Please sign in to comment.