Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/SilveerDusk/Gather
Browse files Browse the repository at this point in the history
  • Loading branch information
zmattes04 committed Jun 4, 2024
2 parents 06cacc2 + 562a5dd commit 9ecc37c
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 160 deletions.
8 changes: 7 additions & 1 deletion backend/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export function authenticateUser(req: Request, res: Response, next: any) {
export const loginUser = async (req: Request, res: Response) => {
connectDB();
const { username, password } = req.body; // from form
const existingUser = await User.findOne({ username }).orFail();
let existingUser: IUser | null = null;
try {
existingUser = await User.findOne({ username }).orFail();
} catch (error) {
console.log("Failed to find user");
return res.status(401).send("Unauthorized: Failed to find user");
}
console.log("Existing user:", existingUser);

if (existingUser == null) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/edits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type updatedItem = {
name: string;
notes: string;
toShare: string;
isPrivate: string;
isPrivate: boolean;
price: string;
quantity: string;
};
Expand Down
8 changes: 2 additions & 6 deletions frontend/lib/fetches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IBasket } from "../../backend/models/basketSchema";
import { ObjectId } from "mongoose";
import { addUserToGroup, addGroupToUser } from "./edits";

// const vite_backend_url = import.meta.env.VITE_BACKEND_URL as string;
//const vite_backend_url = import.meta.env.VITE_BACKEND_URL as string;
const vite_backend_url = "https://gather-app-307.azurewebsites.net";

export const fetchBasket = async (basketId: string) => {
Expand Down Expand Up @@ -253,9 +253,5 @@ export const loginUser = async (credentials: {
};

export const fetchUserByUsername = async (username: string) => {
return fetch(`${vite_backend_url}/users/username/${username}`, {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
});
return fetch(`${vite_backend_url}/users/username/${username}`);
};
14 changes: 13 additions & 1 deletion frontend/src/components/AddFriendToBasket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,19 @@ const AddFriendToBasket: React.FC<Props> = ({

return (
<div>
<Popover>
<Popover
placement="auto"
modifiers={[
{
name: "preventOverflow",
options: {
boundary: "viewport",
altBoundary: true,
padding: 8,
},
},
]}
>
<PopoverTrigger>
<Button
bgColor="var(--col-secondary)"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Basket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const BasketComp = ({
});
fetchMembers(data.members)
.then((res) => {
let temp = []; // extract just the usernames from response
const temp = []; // extract just the usernames from response
for (let i = 0; i < res.length; i++) {
temp.push(res[i].username);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ const BasketComp = ({
<VStack alignItems="start">
<Text as="b">
{basketObj?.created
? "Created " + basketObj?.created?.toDateString()
? "Created " + basketObj?.created?.toLocaleDateString()
: ""}
</Text>
<Text>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CompactGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const CompactGroupV1 = ({
/>
<VStack justifyContent="end" spacing="5px">
<Text textAlign="center" fontSize="0.8rem">
Created {new Date(group.created).toDateString()}
Created {new Date(group.created).toLocaleDateString()}
</Text>
{memberNames?.length > 1 ? (
<HStack spacing="20px">
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/EditBasket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,19 @@ const EditBasket: React.FC<Props> = ({ basketId, groupId }) => {
};

return (
<Popover>
<Popover
placement="auto"
modifiers={[
{
name: "preventOverflow",
options: {
boundary: "viewport",
altBoundary: true,
padding: 8,
},
},
]}
>
<PopoverTrigger>
<Button onClick={() => setIsEditing(true)}>Edit</Button>
</PopoverTrigger>
Expand Down
65 changes: 14 additions & 51 deletions frontend/src/components/EditGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import {
Input,
Box,
HStack,
Stack,
Radio,
RadioGroup,
Text,
} from "@chakra-ui/react";
import React, { useState, useEffect } from "react";
Expand Down Expand Up @@ -132,7 +129,19 @@ const Editgroup: React.FC<Props> = ({
};

return (
<Popover>
<Popover
placement="auto"
modifiers={[
{
name: "preventOverflow",
options: {
boundary: "viewport",
altBoundary: true,
padding: 8,
},
},
]}
>
<PopoverTrigger>
<Button onClick={() => setIsEditing(true)}>Edit Group</Button>
</PopoverTrigger>
Expand Down Expand Up @@ -178,53 +187,7 @@ const Editgroup: React.FC<Props> = ({
_hover={{ bg: "var(--col-tertiary)" }}
/>
</FormControl>
<FormControl>
<FormLabel fontWeight="bold">Visible to Others?</FormLabel>
<RadioGroup onChange={setEditedPub} value={editedPub}>
<Stack direction="row">
<Radio
value="false"
borderColor="var(--col-dark)"
_checked={{
borderColor: "var(--col-bright)",
bg: "var(--col-bright)",
color: "var(--col-dark)",
_before: {
content: '""',
display: "inline-block",
width: "100%",
height: "100%",
borderRadius: "50%",
bg: "var(--col-dark)",
},
}}
_hover={{ bg: "var(--col-tertiary)" }}
>
Public
</Radio>
<Radio
value="true"
borderColor="var(--col-dark)"
_checked={{
borderColor: "var(--col-bright)",
bg: "var(--col-bright)",
color: "var(--col-dark)",
_before: {
content: '""',
display: "inline-block",
width: "100%",
height: "100%",
borderRadius: "50%",
bg: "var(--col-dark)",
},
}}
_hover={{ bg: "var(--col-tertiary)" }}
>
Private
</Radio>
</Stack>
</RadioGroup>
</FormControl>

<HStack width="100%" spacing={4}>
<Button
bgColor="var(--col-secondary)"
Expand Down
85 changes: 22 additions & 63 deletions frontend/src/components/EditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ const EditItem: React.FC<Props> = ({ itemId, editable = true }) => {
const [editedDesc, setEditedDesc] = useState("");
const [editedQuant, setEditedQuant] = useState("");
const [editedPrice, setEditedPrice] = useState("");
const [editedPub, setEditedPub] = useState("");
const [editedPub, setEditedPub] = useState(false);
const [editedSharable, setEditedSharable] = useState("");
const [ItemData, setItemData] = useState({
itemId: "",
itemName: "",
itemDesc: "",
itemQuant: "",
itemPrice: "",
itemPub: "",
itemPub: false,
itemSharable: "",
});

Expand All @@ -69,14 +69,14 @@ const EditItem: React.FC<Props> = ({ itemId, editable = true }) => {
itemDesc: data.notes,
itemQuant: data.quantity,
itemPrice: data.price,
itemPub: data.isPrivate,
itemPub: data.isPrivate === "true" || data.isPrivate === true,
itemSharable: data.toShare,
});
setEditedName(data.name);
setEditedDesc(data.notes);
setEditedQuant(data.quantity);
setEditedPrice(data.price);
setEditedPub(data.isPrivate);
setEditedPub(data.isPrivate === "true" || data.isPrivate === true);
setEditedSharable(data.toShare);
} else {
console.error("Failed to fetch user data");
Expand Down Expand Up @@ -126,7 +126,19 @@ const EditItem: React.FC<Props> = ({ itemId, editable = true }) => {
};

return (
<Popover>
<Popover
placement="auto"
modifiers={[
{
name: "preventOverflow",
options: {
boundary: "viewport",
altBoundary: true,
padding: 8,
},
},
]}
>
<PopoverTrigger>
<IconButton aria-label="More" icon={<SearchIcon />} />
</PopoverTrigger>
Expand Down Expand Up @@ -204,7 +216,10 @@ const EditItem: React.FC<Props> = ({ itemId, editable = true }) => {
</FormControl>
<FormControl>
<FormLabel fontWeight="bold">Visible to Others?</FormLabel>
<RadioGroup onChange={setEditedPub} value={editedPub}>
<RadioGroup
onChange={(val) => setEditedPub(val === "true")}
value={editedPub ? "true" : "false"}
>
<Stack direction="row">
<Radio
value="false"
Expand Down Expand Up @@ -249,56 +264,6 @@ const EditItem: React.FC<Props> = ({ itemId, editable = true }) => {
</Stack>
</RadioGroup>
</FormControl>
<FormControl>
<FormLabel fontWeight="bold">Sharable?</FormLabel>
<RadioGroup
onChange={setEditedSharable}
value={editedSharable}
>
<Stack direction="row">
<Radio
value="true"
borderColor="var(--col-dark)"
_checked={{
borderColor: "var(--col-bright)",
bg: "var(--col-bright)",
color: "var(--col-dark)",
_before: {
content: '""',
display: "inline-block",
width: "100%",
height: "100%",
borderRadius: "50%",
bg: "var(--col-dark)",
},
}}
_hover={{ bg: "var(--col-tertiary)" }}
>
Yes
</Radio>
<Radio
value="false"
borderColor="var(--col-dark)"
_checked={{
borderColor: "var(--col-bright)",
bg: "var(--col-bright)",
color: "var(--col-dark)",
_before: {
content: '""',
display: "inline-block",
width: "100%",
height: "100%",
borderRadius: "50%",
bg: "var(--col-dark)",
},
}}
_hover={{ bg: "var(--col-tertiary)" }}
>
No
</Radio>
</Stack>
</RadioGroup>
</FormControl>
<HStack
display={"flex"}
width="100%"
Expand Down Expand Up @@ -356,13 +321,7 @@ const EditItem: React.FC<Props> = ({ itemId, editable = true }) => {
<Text as="span" fontWeight="bold">
Viewability:
</Text>{" "}
{ItemData.itemPub === "true" ? "Private" : "Public"}
</Box>
<Box>
<Text as="span" fontWeight="bold">
Sharable:
</Text>{" "}
{ItemData.itemSharable === "true" ? "Yes" : "No"}
{ItemData.itemPub ? "Private" : "Public"}
</Box>
<HStack width="100%">
<Button
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/NavbarSignedIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import logo from "../../public/TheLeaf.png";
import { ReactNode } from "react";
import { useNavigate, Link as ReactLink } from "react-router-dom";

// const vite_backend_url = import.meta.env.VITE_BACKEND_URL as string;
const vite_backend_url = "https://gather-app-307.azurewebsites.net";

const NavLink = ({
children,
handleClick,
Expand Down Expand Up @@ -99,7 +102,7 @@ const NavbarSignedIn = ({ stateVariable, updateState }: Props) => {
>
<Avatar
name={stateVariable.username}
src={`http://localhost:3001/${stateVariable._id}/avatar`}
src={`${vite_backend_url}/${stateVariable._id}/avatar`}
/>
</MenuButton>
<MenuList>
Expand Down
Loading

0 comments on commit 9ecc37c

Please sign in to comment.