Skip to content

Commit

Permalink
Merge branch 'main' into bb/bootstrap-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bbland1 committed Sep 28, 2024
2 parents a2ebfae + e3772c3 commit 22cc8fd
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Add yourself as a contributor to this project as a Markdown link that links your
## Mentors

- [Alex D'Antonio](https://github.com/alex-andria) 👽
- [Tanner Gill](https://github.com/tannaurus) 🎈

## Code of Conduct Contacts

Expand Down
7 changes: 1 addition & 6 deletions src/components/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Form from "react-bootstrap/Form";

interface Props {
item: ListItem;
listPath: string | null;
listPath: string;
}
interface None {
kind: "none";
Expand Down Expand Up @@ -68,11 +68,6 @@ export function ListItemCheckBox({ item, listPath }: Props) {
// Temporarily store the updated check state
setUpdatedCheckState({ kind: "set", value: newCheckedState });

if (!listPath) {
toast.error("Error: listPath is missing or invalid.");
return;
}

try {
await toast.promise(updateItem(listPath, item), {
loading: `Marking ${item.name} as purchased!`,
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/AddItemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Form from "react-bootstrap/Form";
import { useNavigate } from "react-router-dom";

interface Props {
listPath: string | null;
listPath: string;
data: ListItem[];
}

Expand Down
8 changes: 2 additions & 6 deletions src/components/forms/ShareListForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InputGroup } from "react-bootstrap";
import toast from "react-hot-toast";

interface Props {
listPath: string | null;
listPath: string;
}

const ShareListForm = ({ listPath }: Props) => {
Expand All @@ -22,14 +22,10 @@ const ShareListForm = ({ listPath }: Props) => {

const handleInvite = async (
e: FormEvent<HTMLFormElement>,
listPath: string | null,
listPath: string,
) => {
e.preventDefault();

if (!listPath) {
return;
}

try {
await toast.promise(shareList(listPath, currentUser, emailName), {
loading: "sharing list with existing user",
Expand Down
8 changes: 4 additions & 4 deletions src/utils/validateTrimmedString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ export function validateItemName(
input: string,
existingItems: ListItem[],
): string | null {
const trimmedInput = input.trim(); //removes leading and trailing whitespaces
const trimmedInput = input.trim(); // removes leading and trailing white spaces

// Condition 1: Check if the input is empty
if (trimmedInput.length === 0) {
return "Item cannot be empty";
}

//Remove punctuation marks and normalize input
// Remove punctuation marks and normalize input
const punctuationRegex = /[^\p{L}]/gu;

const normalizedInputName = trimmedInput
.replace(punctuationRegex, "")
.toLowerCase();

//Create a list of normalized existing item names
// Create a list of normalized existing item names
const normalizedExistingItemNames = existingItems.map((existingItem) => {
return existingItem.name.replace(punctuationRegex, "").toLowerCase();
});
Expand All @@ -31,7 +31,7 @@ export function validateItemName(
);
};

//return error if the item already exists
// Return error if the item already exists
if (isDuplicateItem(normalizedInputName)) {
return ` ${normalizedInputName} already exists in the list`;
}
Expand Down
21 changes: 14 additions & 7 deletions src/views/authenticated/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
.sort(comparePurchaseUrgency);
}, [searchTerm, unfilteredListItems]);

const Header = () => {
return (
<p>
Hello from the <code>/list</code> page!
</p>
);
};

if (!listPath) {
return <Header />;
}

// Early return if the list is empty
if (unfilteredListItems.length === 0) {
return (
<>
<p>
Hello from the <code>/list</code> page!
</p>
<Header />
<section>
<h2>Your list is ready!</h2>
<h3>
You haven’t added any items yet.
<br />
Expand All @@ -50,9 +59,7 @@ export function List({ data: unfilteredListItems, listPath }: Props) {
// Main content when list is not empty
return (
<>
<p>
Hello from the <code>/list</code> page!
</p>
<Header />

<section className="sticky-top bg-dark">
{unfilteredListItems.length > 0 && (
Expand Down
14 changes: 12 additions & 2 deletions src/views/authenticated/ManageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ interface Props {
}

export function ManageList({ listPath, data }: Props) {
return (
<div>
const Header = () => {
return (
<p>
Hello from the <code>/manage-list</code> page!
</p>
);
};

if (!listPath) {
return <Header />;
}

return (
<div>
<Header />
<AddItemForm listPath={listPath} data={data || []} />
<ShareListForm listPath={listPath} />
</div>
Expand Down

0 comments on commit 22cc8fd

Please sign in to comment.