Skip to content

Commit

Permalink
Link device branch (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yousef-Taha1 committed Jun 17, 2024
1 parent 2625d16 commit bea4fbc
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 888 deletions.
820 changes: 19 additions & 801 deletions frontend/package-lock.json

Large diffs are not rendered by default.

20 changes: 5 additions & 15 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,21 @@ function App() {

if (auth.isAuthenticated) {
return (
<div style={{ backgroundColor: "#F5F5DC" }}>
<div style={{ backgroundColor: "#FFFFFF" }}>
<div>
<div>
<Navbar />{" "}
<LinkDevice />
</div>
{/*
<h1 >WELCOME TO TEAMAGOCHI GANG</h1>
<h1 className='font-extrabold text-9xl' >
<a href="https://www.youtube.com/watch?v=sf0PJsknZiM">CARTI </a>
</h1>
<img src={"./android-chrome-384x384.png"} alt="Logo" style={{ width: '384px', height: '384px', marginLeft: '5px' }} />
<img src={"./android-chrome-384x384.png"} alt="Logo" style={{ width: '384px', height: '384px', marginLeft: '5px' }} />
<img src={"./android-chrome-384x384.png"} alt="Logo" style={{ width: '384px', height: '384px', marginLeft: '5px' }} />
<img src={"./android-chrome-384x384.png"} alt="Logo" style={{ width: '384px', height: '384px', marginLeft: '5px' }} />
<img src={"./android-chrome-384x384.png"} alt="Logo" style={{ width: '384px', height: '384px', marginLeft: '5px' }} />
<img src={"./android-chrome-384x384.png"} alt="Logo" style={{ width: '384px', height: '384px', marginLeft: '5px' }} /> */}
</div>
<div>
{/* <div>
Hello USERNAME: {auth.user?.profile?.preferred_username || "User"}
</div>
</div> */}
<Footer />,
</div>
);
}
return [<Navbar />, <PetPage />, <Footer />];
return [<Navbar />, <Footer />];
}

export default App;
146 changes: 79 additions & 67 deletions frontend/src/Components/LinkDevice.tsx
Original file line number Diff line number Diff line change
@@ -1,80 +1,92 @@
import { SetStateAction, useState } from 'react';
import React, { useState } from 'react';
import Popup from 'reactjs-popup';
import 'reactjs-popup/dist/index.css';

function LinkDevice() {
const [open, setOpen] = useState(false);
const [deviceKey, setDeviceKey] = useState("");
const [deviceName, setDeviceName] = useState("");
interface LinkDeviceProps {
onClose: () => void; // onClose prop should be a function that closes the popup
}

const handleInputChangeKey = (e: { target: { value: SetStateAction<string>; }; }) => {
setDeviceKey(e.target.value);
};
function LinkDevice({ onClose }: LinkDeviceProps) {
const [deviceKey, setDeviceKey] = useState("");
const [deviceName, setDeviceName] = useState("");

const handleInputChangeDName = (e: {target: { value: SetStateAction<string>; }; }) => {
setDeviceName(e.target.value);
}
const handleInputChangeKey = (e: React.ChangeEvent<HTMLInputElement>) => {
setDeviceKey(e.target.value);
};

const handleSubmit = (e: { preventDefault: () => void; }) => {
e.preventDefault(); // Prevent form from reloading the page
if (deviceKey.trim() === "" || deviceName.trim() === "") {
return;
}
// TODO: Save the device ID or perform any action with the input value
console.log("Device ID:", deviceKey," Device Name:", deviceName);
setOpen(false); // Close the popup after submission
};
const handleInputChangeDName = (e: React.ChangeEvent<HTMLInputElement>) => {
setDeviceName(e.target.value);
}

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault(); // Prevent form from reloading the page
if (deviceKey.trim() === "") {
return;
}
// TODO: Save the device ID or perform any action with the input value
console.log("Device ID:", deviceKey, " Device Name:", deviceName);
onClose(); // Close the popup after submission
};

return (
<>
<div className='container-fluid d-flex justify-content-center align-items-center' style={{ height: '100vh' }}>
<button className="btn btn-primary" onClick={() => setOpen(true)}>Link Tomogachi</button>
</div>
<Popup
open={open}
onClose={() => setOpen(false)}
overlayStyle={{ background: 'rgba(0, 0, 0, 0.5)' }}
contentStyle={{ borderRadius: '10px', border: '2px solid grey', width: 'fit-content' }}
>
<div style={{ padding: '20px', position: 'relative' }}>
<button
type="button"
className="btn-close"
aria-label="Close"
style={{ position: 'absolute', top: '10px', right: '10px' }}
onClick={() => setOpen(false)}
></button>
<form className="row g-0 needs-validation" onSubmit={handleSubmit}>
<figure className='text-center'>
<p className='lead'>
<strong>Enter your device Key Registration and Name below:</strong>
</p>
</figure>
return (
<Popup
open={true} // Always open initially based on your original logic
onClose={onClose} // Pass the onClose function directly to Popup
overlayStyle={{ background: 'rgba(0, 0, 0, 0.5)' }}
contentStyle={{ borderRadius: '10px', border: '2px solid grey', width: 'fit-content' }}
>
<div style={{ padding: '20px', position: 'relative' }}>
<button
type="button"
className="btn-close"
aria-label="Close"
style={{ position: 'absolute', top: '10px', right: '10px' }}
onClick={onClose} // Also close on clicking the close button
></button>
<form className="row g-0 needs-validation" onSubmit={handleSubmit}>
<figure className='text-center'>
<p className='lead'>
<strong>Enter your device Key Registration and Name below:</strong>
</p>
</figure>

<div className="input-group mb-1">
<span className="input-group-text">#</span>
<label htmlFor="inputLink" className="visually-hidden">Device Key Registration</label>
<input type="text" className="form-control" id="inputDeviceId"
placeholder="Device Key Registration" required value={deviceKey} onChange={handleInputChangeKey}/>
<div className='invalid-feedback'>ok</div>
</div>
<div className="input-group mb-1">
<span className="input-group-text">#</span>
<label htmlFor="inputLink" className="visually-hidden">Device Key Registration</label>
<input
type="text"
className="form-control"
id="inputDeviceId"
placeholder="Device Key Registration"
required
value={deviceKey}
onChange={handleInputChangeKey}
/>
<div className='invalid-feedback'>ok</div>
</div>

<div className="input-group mb-1 py-2">
<span className="input-group-text">@</span>
<label htmlFor="inputLink" className="visually-hidden">Device Name</label>
<input type="text" className="form-control" id="inputDeviceName"
placeholder="Device Name" required value={deviceName} onChange={handleInputChangeDName}/>
<div className='invalid-feedback'>ok</div>
</div>
<div className="input-group mb-1 py-2">
<span className="input-group-text">@</span>
<label htmlFor="inputLink" className="visually-hidden">Device Name</label>
<input
type="text"
className="form-control"
id="inputDeviceName"
placeholder="Device Name"
required
value={deviceName}
onChange={handleInputChangeDName}
/>
<div className='invalid-feedback'>ok</div>
</div>

<button type='submit' className='btn btn-success mt-2 mb-2'>
Link device
</button>
</form>
</div>
</Popup>
</>
);
<button type='submit' className='btn btn-success mt-2 mb-2'>
Link device
</button>
</form>
</div>
</Popup>
);
}

export default LinkDevice;
6 changes: 3 additions & 3 deletions frontend/src/Components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Inventory from "../Inventory.tsx";
import Settings from "../Settings.tsx";
import Friends from "../Friends.tsx";
import PetPage from "../PetPage.tsx";
import LinkDevice from "../LinkDevice.tsx";
import { useAuth } from "react-oidc-context";
import "./navbar.css";

Expand Down Expand Up @@ -57,10 +58,9 @@ const Navbar = () => {
<ul className="navbar-nav">
{auth.isAuthenticated ? (
<>

<li
className={`nav-item ${
activePage === "Pet Page" ? "active" : ""
}`}

>
<Link
className="nav-link"
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Components/PetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import petImage from "../assets/pet_frog.png";
import { ProgressBar } from "react-progressbar-fancy";


// https://github.com/RavinRau/react-progressbar-fancy?tab=readme-ov-file

const Pet = () => {
Expand All @@ -22,7 +23,7 @@ const Pet = () => {
/>
</div>
<div>
<div className="h5 px-3">Hapiness</div>
<div className="h5 px-3">Happiness</div>
<ProgressBar
className="px-1 pb-3"
hideText={true}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/Components/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { useState } from 'react';
import profile_pic1 from '../Misc/8-bit-dog-nobg.png';
import 'bootstrap/dist/css/bootstrap.min.css';
import LinkDevice from "../Components/LinkDevice";

interface SettingsProps {
username: string;
}

function Settings({ username }: SettingsProps) {
const [items, setItems] = useState(['Device 1', 'Device 2', 'Device 3']);
const [showLinkDevice, setShowLinkDevice] = useState<boolean>(true);

const removeItem = (index: number) => {
setItems(items.filter((_, i) => i !== index));
Expand All @@ -30,7 +32,7 @@ function Settings({ username }: SettingsProps) {
<input type="text" className="form-control text-black" placeholder={username} disabled style={{ fontSize: "1.5rem", height: "60px" }}></input>
</div>
<div className='d-flex justify-content-center pt-2'>
<button type="button" className="btn btn-outline-danger btn-block w-100" style={{ fontSize: "1.5rem", height: "60px" }} >Logout</button>
<button type="button" className="btn btn-success btn-block w-100" style={{ fontSize: "1.5rem", height: "60px" }} onClick={() => setShowLinkDevice(false)} >Link Device</button>
</div>
<div className='pt-4' style={{ width: "100%" }}>
<ul className="list-group" style={{ fontSize: "1.2rem" }}>
Expand All @@ -46,6 +48,9 @@ function Settings({ username }: SettingsProps) {
</div>
</div>
</div>
{showLinkDevice==false && (
<LinkDevice onClose={() => setShowLinkDevice(true)} />
)}
</div>
);
}
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"dependencies": {
"bootstrap": "^5.3.3",
"jquery": "^3.7.1",
"oidc-client-ts": "^3.0.1",
"popper.js": "^1.16.1",
"react-bootstrap": "^2.10.2",
"react-oidc-context": "^3.1.0",
"react-progressbar-fancy": "^1.1.4",
Expand Down

0 comments on commit bea4fbc

Please sign in to comment.