Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/controllers/userDataController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getUser = async (req, res) => {
//add a new user
const addUser = async (req, res) => {
const { name, guestList, favoriteRecipes } = req.body;
const existingUser = await User.find({ name: name });
const existingUser = await User.find({ name });
if (existingUser.length > 0) {
return res.status(400).json({ error: "This user already exists." });
}
Expand All @@ -31,7 +31,7 @@ const deleteUser = async (req, res) => {
const { username } = req.params;
try {
await User.deleteOne({ name: username });
res.status(200).json({ msg: username + " was deleted successfully." });
res.status(200).json({ msg: `${username} was deleted successfully.` });
} catch (error) {
res.status(400).json({ error: error.message });
}
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/CompareArrays.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom";
import CompareArrays from "../util/CompareArrays";

test("Function to compare two arrays works", async () => {
test("Function to compare two arrays works", () => {
const array1 = [
{ id: 1, name: 20342 },
{ id: 2, name: "dum" },
Expand All @@ -20,7 +20,7 @@ test("Function to compare two arrays works", async () => {
]);
});

test("Edge case 1 comparing two arrays", async () => {
test("Edge case 1 comparing two arrays", () => {
const array1 = [
{ id: 1, name: 20342 },
{ id: 2, name: "dum" },
Expand All @@ -38,7 +38,7 @@ test("Edge case 1 comparing two arrays", async () => {
]);
});

test("Edge case 2 comparing two arrays", async () => {
test("Edge case 2 comparing two arrays", () => {
const array1 = [
{ id: 1, name: 20342 },
{ id: 2, name: "dum" },
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/GetSelectedGuestsIntolerances.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom";
import GetSelectedGuestsIntolerances from "../util/GetSelectedGuestsIntolerances.js";

test("return intolerances from all selected guests - no double intolerances", async () => {
test("return intolerances from all selected guests - no double intolerances", () => {
const testArray = [
{
id: 1,
Expand Down Expand Up @@ -33,7 +33,7 @@ test("return intolerances from all selected guests - no double intolerances", as
expect(result).toEqual(["Dairy-Free", "Gluten-Free", "Kosher"]);
});

test("return intolerances from all selected guests - double intolerances", async () => {
test("return intolerances from all selected guests - double intolerances", () => {
const testArray = [
{
id: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/GuestNameInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("input field requires valid usernames", () => {
expect(form).not.toBeValid();
});

it("should require an input", async () => {
it("should require an input", () => {
render(
<form data-testid="form">
<GuestNameInput />
Expand Down
5 changes: 4 additions & 1 deletion src/components/BasicButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";
import backIcon from "../assets/icons/arrow-left-circle.svg";
import checkIcon from "../assets/icons/ph_check-circle.svg";

export default function BasicButton({ description, handleClick }) {
function BasicButton({ description, handleClick }) {
return (
<button
type={description === "submit" ? "submit" : "button"}
Expand All @@ -12,3 +13,5 @@ export default function BasicButton({ description, handleClick }) {
</button>
);
}

export default React.memo(BasicButton);
9 changes: 5 additions & 4 deletions src/components/DisplaySelectedGuests.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useContext } from "react";
import React, { useContext } from "react";
import styled from "styled-components";
import { UserContext } from "../context/UserContext";
import getIntolerances from "../util/GetSelectedGuestsIntolerances";

export default function DisplaySelectedGuests() {
function DisplaySelectedGuests() {
const { guestArray } = useContext(UserContext);
const selectedGuests = guestArray.filter((guest) => guest.selected);
let intolerances = getIntolerances(guestArray);

const intolerances = getIntolerances(guestArray);
return (
<StyledSection>
{intolerances.length > 0 ? (
Expand Down Expand Up @@ -46,3 +45,5 @@ const StyledSubSection = styled.section`
margin-right: 10px;
}
`;

export default React.memo(DisplaySelectedGuests);
28 changes: 4 additions & 24 deletions src/components/GuestCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from "styled-components";
import { useNavigate } from "react-router-dom";
import { useContext, useState } from "react";
import React, { useContext, useState } from "react";
import { UserContext } from "../context/UserContext";
import emptyCircle from "../assets/icons/circle_empty.svg";
import checkedCircle from "../assets/icons/circle-check.svg";
Expand All @@ -12,31 +12,11 @@ export default function GuestCard({ personalData }) {
const { name, intolerances, notes, _id, selected } = personalData;
const [showGuestInfo, setShowGuestInfo] = useState(false);
const navigate = useNavigate();

const { guestArray, setGuestArray, deleteGuest } = useContext(UserContext);

function handleDelete() {
deleteGuest(_id);
navigate("/");
}

function toggleSelected(guestId) {
setGuestArray(
guestArray.map((guest) =>
guest._id === guestId
? {
...guest,
selected: !guest.selected,
}
: guest
)
);
}

const { toggleSelectGuest, deleteGuest } = useContext(UserContext);
return (
<StyledArticle>
<StyledBasicSection>
<StyledCheckButton type="button" onClick={() => toggleSelected(_id)}>
<StyledCheckButton type="button" onClick={() => toggleSelectGuest(_id)}>
{selected ? (
<img src={checkedCircle} alt="selected" />
) : (
Expand All @@ -63,7 +43,7 @@ export default function GuestCard({ personalData }) {
<StyledInfoP>{notes.length > 0 && "Further Notes:"}</StyledInfoP>
<StyledNotes>{notes}</StyledNotes>
<StyledButtonContainer>
<StyledDeleteButton onClick={handleDelete}>
<StyledDeleteButton onClick={() => deleteGuest(_id)}>
<img src={deleteIcon} alt="delete guest" />
<p>delete</p>
</StyledDeleteButton>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from "styled-components";
import React from "react";

export default function Header({ title }) {
function Header({ title }) {
return (
<StyledHeader>
<h1>{title}</h1>
Expand All @@ -23,3 +24,5 @@ const StyledHeader = styled.header`
font-weight: unset;
}
`;

export default React.memo(Header);
47 changes: 21 additions & 26 deletions src/components/InfoModal.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import styled from "styled-components";
import { useEffect } from "react";
import React, { useContext, useEffect } from "react";
import IntoleranceFilterInformation from "./IntoleranceFilterTable";
import { UserContext } from "../context/UserContext";

export default function InfoModal({ isInfoModalOpen, setIsInfoModalOpen }) {
function closeModal(event) {
setIsInfoModalOpen(false);
event.stopPropagation();
}

function InfoModal() {
const { toggleModal } = useContext(UserContext);
useEffect(() => {
function keyListener(e) {
if (e.keyCode === 27) {
setIsInfoModalOpen(false);
toggleModal("info");
}
}
document.addEventListener("keydown", keyListener);
Expand All @@ -20,24 +17,20 @@ export default function InfoModal({ isInfoModalOpen, setIsInfoModalOpen }) {

return (
<>
{isInfoModalOpen && (
<Backdrop onClick={() => setIsInfoModalOpen(false)}></Backdrop>
)}
{isInfoModalOpen && (
<ModalContainer onClick={() => setIsInfoModalOpen(false)}>
<h2>Intolerance filters</h2>
<StyledIntro>
Find out what all the available filters for intolerances, diets,
etc. mean exactly:
</StyledIntro>
<IntoleranceFilterInformation />
{
<StyledCloseButton onClick={(event) => closeModal(event)}>
X
</StyledCloseButton>
}
</ModalContainer>
)}
<Backdrop onClick={(event) => toggleModal("info", event)}></Backdrop>
<ModalContainer onClick={(event) => toggleModal("info", event)}>
<h2>Intolerance filters</h2>
<StyledIntro>
Find out what all the available filters for intolerances, diets, etc.
mean exactly:
</StyledIntro>
<IntoleranceFilterInformation />
{
<StyledCloseButton onClick={(event) => toggleModal("info", event)}>
X
</StyledCloseButton>
}
</ModalContainer>
</>
);
}
Expand Down Expand Up @@ -86,3 +79,5 @@ const StyledIntro = styled.p`
margin: 10px 0;
font-size: 1.1rem;
`;

export default React.memo(InfoModal);
2 changes: 0 additions & 2 deletions src/components/Layout.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import styled from "styled-components";
import WarningModal from "./WarningModal";
import { Outlet } from "react-router-dom";

export default function Layout() {
return (
<>
<Container>
<WarningModal />
<Outlet />
</Container>
</>
Expand Down
51 changes: 23 additions & 28 deletions src/components/LoginSection.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
import { useContext } from "react";
import React, { useContext } from "react";
import { UserContext } from "../context/UserContext";
import styled from "styled-components";

export default function LoginSection() {
const { fetchUserData, username, setUsername, isLoggedIn, handleNewUser } =
function LoginSection() {
const { fetchUserData, updateUsername, handleNewUser } =
useContext(UserContext);
return (
<LoginContainer>
{isLoggedIn && <h2>Hello {username}!</h2>}
{!isLoggedIn && (
<StyledUsernameInput
name="username"
id="username"
type="text"
//this pattern prevents users from submiting empty whitespace-filled names (from stackoverflow)
pattern=".*[^\s]{1,}.*"
title="max. 15 letters, no empty usernames"
placeholder="your username"
minLength="1"
maxLength="15"
onChange={(event) => setUsername(event.target.value.trim())}
/>
)}
{!isLoggedIn && (
<button type="button" onClick={fetchUserData}>
Login
</button>
)}
{!isLoggedIn && (
<button type="button" onClick={handleNewUser}>
Login as new user
</button>
)}
<StyledUsernameInput
name="username"
id="username"
type="text"
//this pattern prevents users from submiting empty whitespace-filled names (from stackoverflow)
pattern=".*[^\s]{1,}.*"
title="max. 15 letters, no empty usernames"
placeholder="your username"
minLength="1"
maxLength="15"
onChange={(event) => updateUsername(event)}
/>
<button type="button" onClick={fetchUserData}>
Login
</button>
<button type="button" onClick={handleNewUser}>
Login as new user
</button>
</LoginContainer>
);
}
Expand Down Expand Up @@ -74,3 +67,5 @@ const StyledUsernameInput = styled.input`
border: 2px solid red;
}
`;

export default React.memo(LoginSection);
13 changes: 10 additions & 3 deletions src/components/MoreFilters.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from "react";
import React, { useState } from "react";
import styled from "styled-components";
import { filterData } from "../assets/data";

export default function MoreFilters({
function MoreFilters({
selectedMealType,
setSelectedMealType,
selectedDishType,
Expand All @@ -13,7 +13,6 @@ export default function MoreFilters({
const [isMealTypeOpen, setIsMealTypeOpen] = useState(false);
const [isDishTypeOpen, setIsDishTypeOpen] = useState(false);
const [isCuisineTypeOpen, setIsCuisineTypeOpen] = useState(false);

function handleSelect(event, type) {
if (type === "mealTypes") {
if (!selectedMealType.includes(event.target.value)) {
Expand Down Expand Up @@ -127,7 +126,9 @@ export default function MoreFilters({
<label
key={type.label}
htmlFor={type.label}
role="button"
onClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
<input
key={index}
Expand All @@ -149,7 +150,9 @@ export default function MoreFilters({
<label
key={type.label}
htmlFor={type.label}
role="button"
onClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
<input
key={index}
Expand All @@ -171,7 +174,9 @@ export default function MoreFilters({
<label
key={type.label}
htmlFor={type.label}
role="button"
onClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
<input
key={index}
Expand Down Expand Up @@ -269,3 +274,5 @@ const StyledSubSection = styled.section`
gap: 10px;
}
`;

export default React.memo(MoreFilters);
Loading