Skip to content

Commit

Permalink
Added front end for target matching mechanism.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHsu1 committed Jun 7, 2024
1 parent 8b4c5f1 commit ca91960
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 2 deletions.
4 changes: 3 additions & 1 deletion houston/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import Layout from './pages/Layout';
import Report from './pages/Report';
import NoPage from './pages/NoPage';
import Settings from './pages/Settings'

import TargetMatch from "./pages/TargetMatch";

import { ConnectionType, ConnectionStatus } from "./utilities/temp";
import { SettingsConfig, loadSettings } from "./utilities/settings";
import { LatLng } from "leaflet";
import Drop from "./pages/Drop";


/**
* Main React function
* @returns App
Expand Down Expand Up @@ -106,6 +107,7 @@ function App() {
<Route path="report" element={<Report />} />
<Route path="settings" element={<Settings settings={config} setSettings={setConfig}/>} />
<Route path="drop" element={<Drop/>}/>
<Route path="targetmatch" element={<TargetMatch/>} />

<Route path="*" element={<NoPage />} />
</Route>
Expand Down
2 changes: 1 addition & 1 deletion houston/src/pages/Layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ li:has(a.active) {
transition: background-color var(--std-transition);
}

nav.topbar li:nth-child(6) {
nav.topbar li:nth-child(7) {
margin-right: auto;
}

Expand Down
3 changes: 3 additions & 0 deletions houston/src/pages/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ function Layout({statuses}:{statuses:ConnectionStatus[]}) {
<li>
<NavLink to="/drop" className={checkForActive}>Drop</NavLink>
</li>
<li>
<NavLink to="/targetmatch" className={checkForActive}>Target</NavLink>
</li>
<Button onClick={handleBottleConnectionStatusModal}>
<img
src={bottleIcon}
Expand Down
95 changes: 95 additions & 0 deletions houston/src/pages/TargetMatch.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
.flex-box {
display: flex;
flex:19;
justify-content: center;
justify-items: center;
align-content: center;
align-items: center;
width: 100%;
height: 100%;
}

.left-box {
justify-content: center;
justify-items: center;
align-items: center;
align-content: center;
display: flex;
flex: 1;
}

.right-box {
justify-content: center;
justify-items: center;
align-items: center;
align-content: center;
display: flex;
flex: 2;
}

.form-container {
background-color: goldenrod;
border-radius: 20px;
padding: 20px;
text-align: center;
}

.bottle {
display: flex;
align-items: center;
gap: 30px;
}

.input-field {
margin: 30px 0;
font-size: 30px;
padding: 10px;
width: 250px;
border: 1px solid rgb(253, 76, 0, 0.5);
border-top: none;
border-left: none;
border-right: none;
background: rgba(20, 20, 20, .2);
color: white;
outline: none;
caret-color: black;
}

.submit-button {
background-color: initial;
background-image: linear-gradient(-180deg, #FF7E31, #E62C03);
border-radius: 6px;
box-shadow: rgba(0, 0, 0, 0.1) 0 2px 4px;
color: #FFFFFF;
cursor: pointer;
display: inline-block;
font-family: Inter,-apple-system,system-ui,Roboto,"Helvetica Neue",Arial,sans-serif;
font-size: x-large;
height: 50px;
line-height: 40px;
outline: 0;
overflow: hidden;
padding: 0 20px;
pointer-events: auto;
position: relative;
text-align: center;
touch-action: manipulation;
user-select: none;
-webkit-user-select: none;
vertical-align: top;
white-space: nowrap;
width: 25%;
z-index: 9;
border: 0;
transition: box-shadow .2s;
margin-top: 5px;
}

.submit-button:hover {
box-shadow: rgba(253, 76, 0, 0.5) 0 3px 8px;
}

.image-gallery {
width: 90%;
height: auto;
}
93 changes: 93 additions & 0 deletions houston/src/pages/TargetMatch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import "./TargetMatch.css"

import ReactImageGallery from "react-image-gallery";
import { useState } from "react";

interface LatLng {
lat: string;
lng: string;
}

interface BottleData {
[key: string]: LatLng;
}

/**
* @returns Returns manual target matching page.
*/
function TargetMatch() {
const bottle_list = ['A', 'B', 'C', 'D', 'E'];

const [lat_lng, set_lat_lng] = useState([
{ lat: '', lng: '', setLat: (value:number) => handleUpdate(0, 'lat', value), setLng: (value:number) => handleUpdate(0, 'lng', value) },
{ lat: '', lng: '', setLat: (value:number) => handleUpdate(1, 'lat', value), setLng: (value:number) => handleUpdate(1, 'lng', value) },
{ lat: '', lng: '', setLat: (value:number) => handleUpdate(2, 'lat', value), setLng: (value:number) => handleUpdate(2, 'lng', value) },
{ lat: '', lng: '', setLat: (value:number) => handleUpdate(3, 'lat', value), setLng: (value:number) => handleUpdate(3, 'lng', value) },
{ lat: '', lng: '', setLat: (value:number) => handleUpdate(4, 'lat', value), setLng: (value:number) => handleUpdate(4, 'lng', value) }
]);

const handleUpdate = (index:number, key:string, value:number) => {
set_lat_lng(pre_lat_lng => {
const new_lat_lng = [...pre_lat_lng];
new_lat_lng[index] = { ...new_lat_lng[index], [key]: value };
return new_lat_lng;
});
};

const images = [
{
original: "https://picsum.photos/id/1018/1000/600/",
thumbnail: "https://picsum.photos/id/1018/250/150/",
},
{
original: "https://picsum.photos/id/1015/1000/600/",
thumbnail: "https://picsum.photos/id/1015/250/150/",
},
{
original: "https://picsum.photos/id/1019/1000/600/",
thumbnail: "https://picsum.photos/id/1019/250/150/",
},
];

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

const bottle_data: BottleData = {};

bottle_list.forEach((bottle:string, index: number) => {
bottle_data[`bottle${bottle}`] = {'lat': lat_lng[index].lat, 'lng': lat_lng[index].lng}
});

console.log('Form Data:', bottle_data);
};

return (
<div className="flex-box">
<div className="left-box">
<div className="form-container">
<form onSubmit={handleSubmit} >
{
bottle_list.map((bottle, index) => {
return (
<div className="bottle" key={index}>
<h1>Bottle {bottle}</h1>
<input className="input-field" type="number" placeholder="lat" value={lat_lng[index].lat} onChange={(e) => lat_lng[index].setLat(parseInt(e.target.value))} ></input>
<input className="input-field" type="number" placeholder="lng" value={lat_lng[index].lng} onChange={(e) => lat_lng[index].setLng(parseInt(e.target.value))} ></input>
</div>
)
})
}
<input className="submit-button" type="submit" value="Submit"></input>
</form>
</div>
</div>
<div className="right-box">
<ReactImageGallery items={images} showPlayButton={false}>

</ReactImageGallery>
</div>
</div>

)
}
export default TargetMatch;

0 comments on commit ca91960

Please sign in to comment.