Skip to content

Commit

Permalink
modified settings and pet modal (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuaki-kumazaki committed Jul 1, 2024
2 parents 4e41ff0 + 8a1525f commit 20ae2eb
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 62 deletions.
34 changes: 18 additions & 16 deletions frontend/src/Components/CreatePetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ const CreatePetModal = () => {

const handleInputPetType = (e: { target: { value: SetStateAction<string>; }; }) => {
setPetType(e.target.value);
};
};

const handleSubmit = (e: { preventDefault: () => void; }) => {
e.preventDefault(); // Prevent form from reloading the page
if (petName.trim() === "" || petType === "") {
if (petName.trim() === "" || petName.trim() === "DEAD" || petType === "") {
return;
}
// TODO: Save the device ID or perform any action with the input value
console.log("Pet Name:", petName," Pet Type:", petType);
console.log("Pet Name:", petName, " Pet Type:", petType);
setOpen(false); // Close the popup after submission
};

return (
return (
<>
<div className='container-fluid d-flex justify-content-center align-items-center' style={{ height: '100vh' }}>
<button className="btn btn-success" onClick={() => setOpen(true)}>Create Teamagochi</button>
Expand All @@ -44,20 +44,22 @@ const CreatePetModal = () => {
onClose={handleClose}
overlayStyle={{ background: 'rgba(0, 0, 0, 0.5)' }}
contentStyle={{ borderRadius: '10px', border: '2px solid grey', width: '50%' }}
>
<div style={{padding: '20px', position: 'relative' }}>
<button
>
<div style={{ padding: '20px', position: 'relative' }}>
<button
type="button"
className="btn-close"
aria-label="Close"
style={{ position: 'absolute', top: '10px', right: '10px' }}
onClick={handleClose}
></button>
></button>

<form className="row g-0 needs-validation justify-content-center" onSubmit={handleSubmit}>
<figure className='text-center'>
<p className='lead'>
<strong>Enter your Pet Name below and choose it's Type:</strong>
<strong>Enter your Pet Name below and choose it's Type:
<p>Pet name cannot be "DEAD"</p>
</strong>
</p>
</figure>

Expand All @@ -82,21 +84,21 @@ const CreatePetModal = () => {
<div className="input-group mb-1">
<span className="input-group-text">@</span>
<label htmlFor="inputLink" className="visually-hidden">Pet Name</label>
<input type="text" className="form-control" id="inputPetName"
placeholder="Pet Name" required value={petName} onChange={handleInputPetName}/>
<input type="text" className="form-control" id="inputPetName"
placeholder="Pet Name" required value={petName} onChange={handleInputPetName} />
<div className='invalid-feedback'>ok</div>
</div>

<div className= "btn-group btn-group-toggle pt-2" data-toggle="buttons">
<input type="radio" className="btn-check" name="options" id="option1" value="Land" autoComplete="off"
<div className="btn-group btn-group-toggle pt-2" data-toggle="buttons">
<input type="radio" className="btn-check" name="options" id="option1" value="Land" autoComplete="off"
checked={petType === "Land"} onChange={handleInputPetType}></input>
<label className="btn btn-secondary" htmlFor="option1">Land</label>

<input type="radio" className="btn-check" name="options" id="option2" value="Air" autoComplete="off"
<input type="radio" className="btn-check" name="options" id="option2" value="Air" autoComplete="off"
checked={petType === "Air"} onChange={handleInputPetType}></input>
<label className="btn btn-secondary" htmlFor="option2">Air</label>

<input type="radio" className="btn-check" name="options" id="option3" value="Water" autoComplete="off"
<input type="radio" className="btn-check" name="options" id="option3" value="Water" autoComplete="off"
checked={petType === "Water"} onChange={handleInputPetType}></input>
<label className="btn btn-secondary" htmlFor='option3'>Water</label>
</div>
Expand All @@ -108,7 +110,7 @@ const CreatePetModal = () => {
</div>
</Popup>
</>
);
);
};

export default CreatePetModal;
142 changes: 96 additions & 46 deletions frontend/src/Components/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,110 @@
import { useState } from 'react';
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;
username: string;
}

function Settings(
{ username }: SettingsProps
{ 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));
};

// const resetItem = (index: number) => {
// setItems(items.map((item, i) => (i === index ? `Item ${index + 1}` : item)));
// };

return (
<div className='d-flex justify-content-center pt-4 pb-2'>
<div className="card align-items-center text-bg-light" style={{ width: "500px" }}>
<img src={profile_pic1} className="card-img-top py-3" alt="profile picture" style={{ width: "100%", height: "auto" }} />
<h2 className="card-title text-center"><kbd className='bg-success text-white'>PROFILE</kbd></h2>
<div className="card-body" style={{ width: "100%" }}>
<div className="input-group mb-4" style={{ height: "60px" }}>
<div className="input-group-prepend">
<div className="input-group-text" style={{ fontSize: "1.5rem", height: "60px", display: 'flex', alignItems: 'center' }}>@</div>
const [items, setItems] = useState(['Device 1', 'Device 2', 'Device 3']);
const [showLinkDevice, setShowLinkDevice] = useState<boolean>(true);
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
const [showModal, setShowModal] = useState<boolean>(false);
const [itemToRemove, setItemToRemove] = useState<number | null>(null);

const handleRemoveItem = (index: number) => {
setShowModal(true);
setItemToRemove(index);
};

const confirmRemoveItem = () => {
if (itemToRemove !== null) {
setItems(items.filter((_, i) => i !== itemToRemove));
if (selectedIndex === itemToRemove) {
setSelectedIndex(null);
}
setItemToRemove(null);
}
setShowModal(false);
};

const cancelRemoveItem = () => {
setShowModal(false);
setItemToRemove(null);
};

const resetItem = (index: number) => {
setItems(items.map((item, i) => (i === index ? `Item ${index + 1}` : item)));
};

const selectItem = (index: number) => {
setSelectedIndex(index);
};

return (
<div className='d-flex justify-content-center pt-4 pb-2'>
<div className="card align-items-center text-bg-light" style={{ width: "500px" }}>
<img src={profile_pic1} className="card-img-top py-3" alt="profile picture" style={{ width: "100%", height: "auto" }} />
<h2 className="card-title text-center"><kbd className='bg-success text-white'>PROFILE</kbd></h2>
<div className="card-body" style={{ width: "100%" }}>
<div className="input-group mb-4" style={{ height: "60px" }}>
<div className="input-group-prepend">
<div className="input-group-text" style={{ fontSize: "1.5rem", height: "60px", display: 'flex', alignItems: 'center' }}>@</div>
</div>
<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-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" }}>
{items.map((item, index) => (
<li key={index} className="list-group-item d-flex justify-content-between align-items-center py-3">
{item}
<div>
<button
className="btn btn-primary btn-lg mx-1"
onClick={() => selectItem(index)}
disabled={selectedIndex === index}
>
{selectedIndex === index ? 'Selected' : 'Select'}
</button>
<button className="btn btn-danger btn-lg mx-1" onClick={() => handleRemoveItem(index)}>Remove</button>
</div>
</li>
))}
</ul>
</div>
</div>
</div>
<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-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" }}>
{items.map((item, index) => (
<li key={index} className="list-group-item d-flex justify-content-between align-items-center py-3">
{item}
<div>
<button className="btn btn-danger btn-lg mx-1" onClick={() => removeItem(index)}>Remove</button>
</div>
</li>
))}
</ul>
</div>
{showLinkDevice === false && (
<LinkDevice onClose={() => setShowLinkDevice(true)} />
)}

{showModal && (
<div className="modal show d-block" tabIndex={-1} role="dialog">
<div className="modal-dialog" role="document">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title">Confirm Removal</h5>
</div>
<div className="modal-body">
<p>Are you sure you want to remove this pet?</p>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" onClick={cancelRemoveItem}>No</button>
<button type="button" className="btn btn-danger" onClick={confirmRemoveItem}>Yes</button>
</div>
</div>
</div>
</div>
)}
</div>
</div>
{showLinkDevice==false && (
<LinkDevice onClose={() => setShowLinkDevice(true)} />
)}
</div>
);
);
}

export default Settings;

0 comments on commit 20ae2eb

Please sign in to comment.