Skip to content

Commit

Permalink
FAIR SHARE 1.0.0
Browse files Browse the repository at this point in the history
Add Feature Update Info
  • Loading branch information
DavidGomezToca committed Aug 30, 2024
1 parent 164920e commit 0e2e8ff
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

- **STACK :**

- **Fair Share** : `0.8.0`
- **Fair Share** : `1.0.0`
- **React** : `18.3.1`
- **React Dom** : `18.3.1`

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fair-share",
"version": "0.8.0",
"version": "1.0.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
Expand Down
Binary file modified resources/img/Thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 17 additions & 6 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ export default function App() {
setShowAddFriend(false);
}

function handleSplitBill(value) {
setFriends((friends) => friends.map((friend) => friend.id === selectedFriend.id ? { ...friend, balance: friend.balance + value } : friend));
setSelectedFriend(null);
}

return (
<div className='app'>
<div className='sidebar'>
<FriendList friends={friends} selectedFriend={selectedFriend} onSelection={handleSelection} />
{showAddFriend && <FormAddFriend onAddFriend={handleAddFriend} />}
<Button onClick={handleShowAddFriend}>{showAddFriend ? "Close" : "Add friend"}</Button>
</div>
{selectedFriend && <FormSplitBill selectedFriend={selectedFriend.name} />}
{selectedFriend && <FormSplitBill selectedFriend={selectedFriend} onSplitBill={handleSplitBill} />}
</div>
)
}
Expand Down Expand Up @@ -107,21 +112,27 @@ function InputText({ children, value, setValue }) {
)
}

function FormSplitBill({ selectedFriend }) {
function FormSplitBill({ selectedFriend, onSplitBill }) {
const [bill, setBill] = useState("");
const [paidByUser, setPaidByUser] = useState("");
const paidByFriend = bill ? bill - paidByUser : "";
const [whoIsPaying, setWhoIsPaying] = useState("user");

function handleSubmit(e) {
e.preventDefault();
if (!bill || !paidByUser) return;
onSplitBill(whoIsPaying === "user" ? paidByFriend : -paidByUser);
}

return (
<form className="form-split-bill">
<h2>Split a bill with {selectedFriend}</h2>
<form className="form-split-bill" onSubmit={handleSubmit}>
<h2>Split a bill with {selectedFriend.name}</h2>
<label>πŸ’° Bill value</label>
<input type="number" value={bill} onChange={(e) => setBill(Number(e.target.value))} maxLength={10} />
<label>πŸ™β€β™‚οΈ Your expense</label>
<input type="number" value={paidByUser} onChange={(e) => setPaidByUser(Number(e.target.value) > bill ? paidByUser : Number(e.target.value))} maxLength={10} />
<InputReadOnly paidByFriend={paidByFriend}>πŸ‘¬ {selectedFriend}'s expense</InputReadOnly>
<InputSelect selectedFriend={selectedFriend} whoIsPaying={whoIsPaying} setWhoIsPaying={setWhoIsPaying}>πŸ€‘ Who is paying the bill</InputSelect>
<InputReadOnly paidByFriend={paidByFriend}>πŸ‘¬ {selectedFriend.name}'s expense</InputReadOnly>
<InputSelect selectedFriend={selectedFriend.name} whoIsPaying={whoIsPaying} setWhoIsPaying={setWhoIsPaying}>πŸ€‘ Who is paying the bill</InputSelect>
<Button>Split bill</Button>
</form>
)
Expand Down

0 comments on commit 0e2e8ff

Please sign in to comment.