Skip to content

Commit

Permalink
added searchbar dropdown component
Browse files Browse the repository at this point in the history
  • Loading branch information
akrakman committed Oct 26, 2022
1 parent ed363f4 commit 072ac44
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 40 deletions.
19 changes: 9 additions & 10 deletions src/frontend/db.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"home": [],
"mockdata": [
{
"id": 1,
Expand Down Expand Up @@ -43,7 +42,7 @@
},
{
"id": 5,
"name": "cool park",
"name": "Champaign park",
"address": "White St.",
"review": "Amazingly horrible",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -63,7 +62,7 @@
},
{
"id": 7,
"name": "not a park",
"name": "Champaign park",
"address": "Wright street",
"review": "Too yellow",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -73,7 +72,7 @@
},
{
"id": 8,
"name": "park park",
"name": "Champaign park",
"address": "West springfield",
"review": "Slightly below average horrible",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -83,7 +82,7 @@
},
{
"id": 9,
"name": "Urbana park",
"name": "Champaign park",
"address": "51 E John",
"review": "Purple",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -93,7 +92,7 @@
},
{
"id": 10,
"name": "Good park",
"name": "Champaign park",
"address": "Wright street",
"review": "Orange",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -103,7 +102,7 @@
},
{
"id": 11,
"name": "Bad park",
"name": "Champaign park",
"address": "West springfield",
"review": "AMAZING AMAZING average",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -113,7 +112,7 @@
},
{
"id": 12,
"name": "Spooky park",
"name": "Champaign park",
"address": "Green st.",
"review": "Slightly AMAZING AMAZING AMAZING",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -123,7 +122,7 @@
},
{
"id": 13,
"name": "Corporate park",
"name": "Champaign park",
"address": "202 E Daniel St.",
"review": "Extremely AMAZING AMAZING AMAZING",
"image": "https://upload.wikimedia.org/wikipedia/commons/7/7f/St_James_Town1.jpg",
Expand All @@ -139,4 +138,4 @@
"postId": 1
}
]
}
}
1 change: 0 additions & 1 deletion src/frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
15 changes: 0 additions & 15 deletions src/frontend/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ function App() {
return (
<div className="App">
{/*<LeftSection/>
<Header/>*/}
<Header/>
<Login/>*/}
<Searching />
{/*<Login/>*/}
</div>
);
}
Expand Down
34 changes: 34 additions & 0 deletions src/frontend/src/components/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import data from "../staticdata.json";
import "./SearchBarStyles.css";
import SingleCard from "./SingleCard";

interface Props {
props: string;
}

const List = ({ props }: Props) => {
// eslint-disable-next-line
const filteredData = data.filter((el: any) => {
if (props === '') {
return el;
} else if (el.name) {
return el.name.toLowerCase().includes(props);
}
})
return (
<div className="list">
{filteredData.splice(0, 5).map((apartment, index) => {
if (props !== '') {
return (
<div key={index} className="box">
<p key={apartment.id}>{apartment.name}</p>
</div>
);
}
})}
</div>
);
}

export default List;
22 changes: 10 additions & 12 deletions src/frontend/src/components/SearchAndDisplayResults.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { TextField, ToggleButton, ToggleButtonGroup } from '@mui/material';
import axios from 'axios';
import { ToggleButton, ToggleButtonGroup } from '@mui/material';
import React, {
useState,
useRef,
useCallback,
KeyboardEvent,
useEffect,
} from 'react';
import SingleCard from './SingleCard';
import useSearchApartment from './getsApartments';
import SearchBar from './SearchBar';

export default function Searching() {
const [query, setQuery] = useState('');
Expand Down Expand Up @@ -39,7 +38,7 @@ export default function Searching() {
[loading, hasMore]
);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
/*const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setQuery(e.target.value);
setPageNum(1);
setPress(false);
Expand All @@ -50,7 +49,6 @@ export default function Searching() {
if (e.key === 'Enter') {
e.preventDefault();
setPress(true);
handlePost(query, selected);
}
};
Expand All @@ -77,12 +75,12 @@ export default function Searching() {
console.log(error.response.headers);
}
});
}
}*/

useEffect(() => {
//useEffect(() => {
// triggers a post request whenever a button is selected
handlePost(query, selected);
}, [selected]);
// handlePost(query, selected);
//}, [selected]);

const handleToggle = (
event: React.MouseEvent<HTMLElement>,
Expand All @@ -104,10 +102,9 @@ export default function Searching() {

return (
<div className="App">
<h1>Search For Apartments</h1>
<div>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<div className="search" style={{ width: '800px' }}>
{/*<div className="search" style={{ width: '800px' }}>
<TextField
id="outlined-basic"
variant="outlined"
Expand All @@ -117,8 +114,9 @@ export default function Searching() {
onKeyDown={handlePress}
onChange={handleChange}
/>
</div>*/}
</div>
</div>
<SearchBar/>
<br />
<ToggleButtonGroup
color="primary"
Expand Down
29 changes: 29 additions & 0 deletions src/frontend/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import { useState } from "react";
import TextField from "@mui/material/TextField";
import List from "./List";
import "./SearchBarStyles.css";

const SearchBar = () => {
const [inputText, setInputText] = useState("");
return (
<div className="main">
<h1>Apartment Search</h1>
<div className="search">
<TextField
id="outlined-basic"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setInputText(e.target.value.toLowerCase())}
variant="outlined"
fullWidth
label="Search"
className="myInput"
/>
</div>
<div className="myDropdown">
<List props={inputText} />
</div>
</div>
);
}

export default SearchBar;
37 changes: 37 additions & 0 deletions src/frontend/src/components/SearchBarStyles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.search {
background-position: 14px 12px;
background-repeat: no-repeat;
font-size: 16px;
padding: 14px 20px 12px 45px;
border: none;
margin-left: 600px;
width: 500px;
}

.box {
text-align: center;
border: black ridge 1px;
border-radius: 10px;
margin: 3px;
width: 20rem;
padding-left: 10px;
}

.list {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-sizing: border-box;
}

.myDropdown {
min-width: 230px;
overflow: auto;
z-index: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-sizing: border-box;
}
Loading

3 comments on commit 072ac44

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
TOTAL1710100%

Tests Skipped Failures Errors Time
36 0 💤 0 ❌ 0 🔥 0.568s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
TOTAL1710100%

Tests Skipped Failures Errors Time
36 0 💤 0 ❌ 0 🔥 0.718s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
TOTAL1710100%

Tests Skipped Failures Errors Time
36 0 💤 0 ❌ 0 🔥 0.849s ⏱️

Please sign in to comment.