Skip to content

Commit

Permalink
Merge branch 'main' into eb-voice-to-text-issue-17
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaBin authored Sep 30, 2024
2 parents c42e43b + fed03fa commit 6426c08
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
29 changes: 27 additions & 2 deletions src/components/ListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import './ListItem.css';
import { updateItem, deleteItem } from '../api';

export function ListItem({ item }) {
const { name, dateLastPurchased, id } = item;
const { name, dateLastPurchased, dateNextPurchased, totalPurchases, id } =
item;
const [checked, setChecked] = useState(false);
const [isActive, setIsActive] = useState(false);

const handleDelete = async () => {
try {
Expand Down Expand Up @@ -57,8 +59,31 @@ export function ListItem({ item }) {
onChange={handleChange}
disabled={checked}
/>
{name}
<h2 style={{ fontSize: '20px' }}>{name}</h2>

<button onClick={handleDelete}>Delete</button>
<button onClick={() => setIsActive(!isActive)}>
View Purchase Details
</button>

<div style={{ display: isActive ? 'block' : 'none' }}>
<ul style={{ fontSize: '15px' }}>
<li>
Last Purchase:
<span>
{' '}
{dateLastPurchased
? dateLastPurchased.toDate().toDateString()
: 'N/A'}
</span>
</li>
<li>
Next Purchase:
<span> {dateNextPurchased?.toDate().toDateString()}</span>
</li>
<li>Total Purchases: {totalPurchases}</li>
</ul>
</div>
</li>
);
}
8 changes: 4 additions & 4 deletions src/views/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './Home.css';
import { SingleList } from '../components';
import { useState, useEffect } from 'react';
import { Fragment, useState } from 'react';
import { createList, useAuth } from '../api';
import { useNavigate } from 'react-router-dom';
import { useVoiceToText } from '../utils';
Expand Down Expand Up @@ -48,15 +48,15 @@ export function Home({ data, setListPath }) {
<ul>
{data &&
data.map((list) => {
const uniqueId = crypto.randomUUID();
return (
<>
<Fragment key={uniqueId}>
<SingleList
key={crypto.randomUUID()}
name={list.name}
setListPath={setListPath}
path={list.path}
/>
</>
</Fragment>
);
})}
</ul>
Expand Down
17 changes: 12 additions & 5 deletions src/views/List.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ListItem } from '../components';
import { useState, useEffect } from 'react';
import { useState, useEffect, Fragment } from 'react';
import BasicModal from './Modal';
import { comparePurchaseUrgency } from '../api';

Expand Down Expand Up @@ -51,6 +51,11 @@ export function List({ data, userId }) {
setFilteredObject(filteredObject);
}, [filterVal, sortedList]);

const addItemNavigate = (e) => {
e.preventDefault();
window.location.href = '/manage-list';
};

return (
<>
<p>
Expand All @@ -60,8 +65,10 @@ export function List({ data, userId }) {
<BasicModal dataEmpty={dataEmpty} message={message} />
)}

<button onClick={addItemNavigate}> Add item</button>

<form onSubmit={clearInput}>
<label htmlFor="item-name">Item name:</label>
<label htmlFor="item-name">Search item: </label>
<input
id="item-name"
name="item-name"
Expand All @@ -75,14 +82,14 @@ export function List({ data, userId }) {
<ul>
{filteredObject &&
Object.entries(filteredObject).map(([timeBucket, list]) => (
<>
<Fragment key={crypto.randomUUID()}>
<div>
<h3>{labels[timeBucket]}</h3>
</div>
{list.map((item) => (
<ListItem key={item.id} item={item} />
<ListItem item={item} key={crypto.randomUUID()} />
))}
</>
</Fragment>
))}
</ul>
</>
Expand Down
1 change: 1 addition & 0 deletions src/views/ManageList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function ManageList({ userId, list }) {
name: '',
frequency: '',
});
window.location.href = '/list';
})
.catch((error) => {
window.alert(`${formData.name} failed to add to your list.`);
Expand Down

0 comments on commit 6426c08

Please sign in to comment.