diff --git a/client/src/App.tsx b/client/src/App.tsx index 0f1d03c..c15c2a7 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -19,6 +19,8 @@ import CollectionBrowser from './components/pages/CollectionBrowser'; import { Navbar } from './components/ui'; import './sass/App.scss' import RichText from './components/ui/RichText'; +import GroceryList from './components/pages/GroceryList'; +import GroceryListCollection from './components/pages/GroceryListCollection'; function App() { const [user, setUser] = useState({ user: undefined }); @@ -65,6 +67,8 @@ function App() { } /> } /> + } /> + } /> diff --git a/client/src/components/derived/Friends.tsx b/client/src/components/derived/Friends.tsx index 80f009b..500c1f1 100644 --- a/client/src/components/derived/Friends.tsx +++ b/client/src/components/derived/Friends.tsx @@ -4,7 +4,8 @@ import { useAuthContext } from "../../context/AuthContext"; import { getAllUsers, getFriendships, getPendingFriendRequests, getUserByID } from "../../util/apiUtils"; import UserCard from "../ui/UserCard"; import { IUser, IFriendship } from "../../schemas"; -import { Panel } from "../ui"; +import { Card, Divider, Panel } from "../ui"; +import FriendSearchWidget from "../ui/Widgets/FriendSearchWidget"; export default function Friends() { const [friends, setFriends] = useState(); @@ -14,13 +15,16 @@ export default function Friends() { useEffect(() => { if (!user) return; (async function() { - const rawResult = await getFriendships(); - console.log(rawResult); - - const result = rawResult.filter((item: IFriendship) => (item.senderid == user.id) && !(item.pending)); - console.log(result); - - setFriends(result); + try { + const rawResult = await getFriendships(); + + if (rawResult.length) { + const result = rawResult.filter((item: IFriendship) => (item.senderid == user.id) && !(item.pending)); + setFriends(result); + } + } catch(e) { + console.error(e); + } })() }, [user]) @@ -38,13 +42,29 @@ export default function Friends() { }, [setUserList]) return ( - -

Your friendships:

- { - userList.map((user: IUser) => { - return - }) - } -
+ <> + { userList.length ? + ( + +

Your friendships:

+ { + userList.map((user: IUser) => { + return + }) + } +
+ ) : + ( + +

You don't have any friends!

+ +

We can fix that, if you'd like.

+

Use the widget below to search our users:

+ + +
+ ) + } + ) } \ No newline at end of file diff --git a/client/src/components/pages/GroceryList.tsx b/client/src/components/pages/GroceryList.tsx index e69de29..5b903bb 100644 --- a/client/src/components/pages/GroceryList.tsx +++ b/client/src/components/pages/GroceryList.tsx @@ -0,0 +1,11 @@ +import Protect from "../../util/Protect" + +const GroceryList = () => { + return ( + +

My grocery lists:

+
+ ) +} + +export default GroceryList; \ No newline at end of file diff --git a/client/src/components/pages/GroceryListCollection.tsx b/client/src/components/pages/GroceryListCollection.tsx new file mode 100644 index 0000000..eefbee0 --- /dev/null +++ b/client/src/components/pages/GroceryListCollection.tsx @@ -0,0 +1,11 @@ +import Protect from "../../util/Protect"; + +const GroceryListCollection = () => { + return ( + +

All of my grocery lists:

+
+ ) +} + +export default GroceryListCollection; \ No newline at end of file diff --git a/client/src/components/pages/Profile.tsx b/client/src/components/pages/Profile.tsx index 563bb79..35efc82 100644 --- a/client/src/components/pages/Profile.tsx +++ b/client/src/components/pages/Profile.tsx @@ -8,7 +8,6 @@ import Friends from "../derived/Friends"; export default function Profile() { const [message, setMessage] = useState(); - // const { user } = useAuthContext(); const { user } = useAuthContext(); const navigate = useNavigate(); diff --git a/client/src/components/pages/Register/addfriends.tsx b/client/src/components/pages/Register/addfriends.tsx index abdbd1e..8ca8b70 100644 --- a/client/src/components/pages/Register/addfriends.tsx +++ b/client/src/components/pages/Register/addfriends.tsx @@ -1,50 +1,12 @@ -import { Button, Divider, Page, Panel, TextField, UserCard } from "../../ui"; -import { ChangeEvent, useCallback, useEffect, useState } from "react"; +import { Button, Divider, Page, Panel } from "../../ui"; import { RegisterVariantType, VariantLabel } from "."; -import { IUser } from "../../../schemas"; -import { getAllUsers } from "../../../util/apiUtils"; -import { v4 } from 'uuid'; +import FriendSearchWidget from "../../ui/Widgets/FriendSearchWidget"; const AddFriends: RegisterVariantType = ({ transitionDisplay }) => { - const [searchTerm, setSearchTerm] = useState(); - const [userPool, setUserPool] = useState([]); - const [friendResults, setFriendResults] = useState([]); - const handleTransition = async () => { transitionDisplay(VariantLabel.FinishUp); } - // this isn't really working right now i don't think - const handleRequestSent = useCallback((targetid: string | number) => { - setUserPool((prev: IUser[]) => { - const newResults = prev.filter((user: IUser) => { - return user.id !== targetid; - }) - - return newResults; - }) - }, []) - - // load available user pool on mount - useEffect(() => { - (async function() { - const result = await getAllUsers(); - if (result) setUserPool(result); - })(); - }, []) - - useEffect(() => { - if (!searchTerm) { - setFriendResults(new Array()); - } else { - const narrowedPool = userPool?.filter((person: IUser) => { - if (person.firstname.toLowerCase().includes(searchTerm) || person.lastname.toLowerCase().includes(searchTerm) || person.handle.toLowerCase().includes(searchTerm)) return person; - }) - - setFriendResults(narrowedPool); - } - }, [userPool, searchTerm]) - return (

Cool, we'll keep all the recipes you post in that collection.

@@ -58,16 +20,7 @@ const AddFriends: RegisterVariantType = ({ transitionDisplay }) => {

This will allow you to share recipes and collections back and forth, and leave comments on each other's recipes.

If you know their email or unique handle, type it in below!

- -
- ) => setSearchTerm(e.target.value.toLowerCase())} placeholder={'Search'} /> - - { - friendResults && friendResults.map((friend: IUser) => { - return handleRequestSent(friend.id!)} /> - }) - } -
+ diff --git a/client/src/components/pages/Welcome.tsx b/client/src/components/pages/Welcome.tsx index 3eadcd7..6a0b3cb 100644 --- a/client/src/components/pages/Welcome.tsx +++ b/client/src/components/pages/Welcome.tsx @@ -13,7 +13,7 @@ const Welcome = () => { - + ) diff --git a/client/src/components/ui/Widgets/FriendSearchWidget.tsx b/client/src/components/ui/Widgets/FriendSearchWidget.tsx new file mode 100644 index 0000000..101c716 --- /dev/null +++ b/client/src/components/ui/Widgets/FriendSearchWidget.tsx @@ -0,0 +1,56 @@ +import { ChangeEvent, FC, useCallback, useEffect, useState } from "react"; +import { IUser } from "../../../schemas"; +import { TextField, UserCard } from ".."; +import { v4 } from "uuid"; +import { getAllUsers } from "../../../util/apiUtils"; + +const FriendSearchWidget: FC<{}> = () => { + const [searchTerm, setSearchTerm] = useState(); + const [userPool, setUserPool] = useState([]); + const [friendResults, setFriendResults] = useState([]); + + // this isn't really working right now i don't think + const handleRequestSent = useCallback((targetid: string | number) => { + setUserPool((prev: IUser[]) => { + const newResults = prev.filter((user: IUser) => { + return user.id !== targetid; + }) + + return newResults; + }) + }, []) + + // load available user pool on mount + useEffect(() => { + (async function() { + const result = await getAllUsers(); + if (result) setUserPool(result); + })(); + }, []) + + useEffect(() => { + if (!searchTerm) { + setFriendResults(new Array()); + } else { + const narrowedPool = userPool?.filter((person: IUser) => { + if (person.firstname.toLowerCase().includes(searchTerm) || person.lastname.toLowerCase().includes(searchTerm) || person.handle.toLowerCase().includes(searchTerm)) return person; + }) + + setFriendResults(narrowedPool); + } + }, [userPool, searchTerm]) + + return ( +
+ ) => setSearchTerm(e.target.value.toLowerCase())} placeholder={'Search'} /> + + { + friendResults && friendResults.map((friend: IUser) => { + return handleRequestSent(friend.id!)} /> + }) + } +
+ ) +} + +export default FriendSearchWidget; \ No newline at end of file diff --git a/server/controllers/UserCtl.ts b/server/controllers/UserCtl.ts index 8d268c3..4fa21ad 100644 --- a/server/controllers/UserCtl.ts +++ b/server/controllers/UserCtl.ts @@ -47,7 +47,7 @@ export default class UserCtl { async getFriends(id: number | string) { try { const result = await UserInstance.getFriends(id); - if (!result) throw createError(404, "You have no friends"); + if (!result) return createError(404, "You have no friends"); return result; } catch (e: any) { throw new Error(e);