Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapped out search results upon click #55

Merged
merged 23 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c4bf6d4
Create README.md
Noodulz Sep 25, 2023
638da54
Wireframe of user profile page
Noodulz Sep 25, 2023
ebaf640
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 2, 2023
c8770de
Update Register.tsx
Noodulz Oct 9, 2023
4bac53a
Update Login.tsx
Noodulz Oct 9, 2023
7defa77
Update Login.tsx
Noodulz Oct 9, 2023
4bbfce3
Update Login.tsx
Noodulz Oct 9, 2023
7617239
Update Login.tsx
Noodulz Oct 9, 2023
1b158f9
Update Login.tsx
Noodulz Oct 9, 2023
e531fcc
Update Login.tsx
Noodulz Oct 9, 2023
444956e
Update Login.tsx
Noodulz Oct 9, 2023
32a1f7d
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 11, 2023
b43128a
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 11, 2023
e77cd01
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 11, 2023
8618656
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 11, 2023
7e177be
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 16, 2023
987b572
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 16, 2023
8a6795b
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 23, 2023
cbc83d7
Merge branch 'master' of https://github.com/Noodulz/roommate-finder
Noodulz Oct 23, 2023
3d32f7c
Added select boxes and implemented search query to backend
Noodulz Oct 23, 2023
87efe70
Merge branch 'lesterfernandez:master' into master
Noodulz Oct 25, 2023
9735c7d
Merge branch 'lesterfernandez:master' into master
Noodulz Oct 25, 2023
69f4169
Applied search schema and mapped out search results
Noodulz Oct 25, 2023
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
11 changes: 9 additions & 2 deletions client/src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import { Box, HStack, FormControl, FormLabel, Button, Select } from "@chakra-ui/react";
import { useState } from "react";
import UserCard from "./UserCard";
import { UserProfile } from "../types";
import { searchResultSchema } from "../schemas";

export default function Search() {
const [results, setResults] = useState<UserProfile[]>([]);
const [budget, setBudget] = useState("");
const [cleanliness, setCleanliness] = useState("");
const [loudness, setLoudness] = useState("");
const [coed, setCoed] = useState("");
const [searchLoading, setSearchLoading] = useState(false);

const handleSearch = async () => {
const query = `?budget=${budget}&cleanliness=${cleanliness}&loudness=${loudness}&coEd=${coed}`;
try {
const response = await fetch(`${import.meta.env.VITE_BACKEND_URL}/search${query}`);
const data = await response.json();
const dataResults = searchResultSchema.parse(data);
setResults(dataResults);
console.log(data);
} catch (error) {
console.error("Error fetching search results:", error);
}
};

return (
<Box bg="#156087" minH="100vh">
<HStack textColor="white" gap="60px" mx="70px" p="30px" alignItems="flex-end">
Expand Down Expand Up @@ -69,7 +76,7 @@ export default function Search() {
colorScheme="orange"
width="100%"
borderRadius="6px"
onClick={() => {
onClick={async () => {
setSearchLoading(true);
handleSearch().then(() => setSearchLoading(false));
}}
Expand All @@ -79,7 +86,7 @@ export default function Search() {
</Button>
</FormControl>
</HStack>
<UserCard />
{results.map(result => <UserCard profile={result}/>)}
</Box>
);
}
15 changes: 9 additions & 6 deletions client/src/components/UserCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Card, Image, Stack, CardBody, Heading, Text, Box, Button } from "@chakra-ui/react";
import { UserProfile } from "../types";

export default function UserCard() {
export default function UserCard(props: {profile: UserProfile}) {
return (
<Card
bg="#07354f"
Expand All @@ -12,8 +13,8 @@ export default function UserCard() {
>
<Box margin="20px" display="flex" justifyContent="center" alignItems="center">
<Image
src="https://images.unsplash.com/photo-1667489022797-ab608913feeb?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw5fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=800&q=60"
alt="Caffe Latte"
src={props.profile.profilePic}
alt="Profile Picture"
borderRadius="full"
boxSize="100px"
/>
Expand All @@ -22,9 +23,11 @@ export default function UserCard() {
<Stack>
<CardBody px="0">
<Heading size="md">First Name Last Name</Heading>
<Text>Gender:</Text>
<Text>About:</Text>
<Text>Preferences:</Text>
<Text>Gender: {props.profile.gender}</Text>
<Text>Budget: {props.profile.budget}</Text>
<Text>Loudness: {props.profile.loudness}</Text>
<Text>Cleanliness: {props.profile.cleanliness}</Text>
<Text>Co-Ed: {props.profile.cleanliness}</Text>
</CardBody>
</Stack>

Expand Down
24 changes: 14 additions & 10 deletions client/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ export const apiErrorSchema = z.object({
errorMessage: z.string(),
});

export const userProfileSchema = z
.object({
profilePic: z.string().optional(),
displayName: z.string().min(1),
budget: z.literal(1).or(z.literal(2)).or(z.literal(3)).or(z.literal(4)),
gender: z.string().min(1),
cleanliness: z.literal(1).or(z.literal(2)).or(z.literal(3)),
loudness: z.literal(1).or(z.literal(2)).or(z.literal(3)),
coed: z.boolean(),
})
const userProfileBodySchema = z
.object({
profilePic: z.string().optional(),
budget: z.literal(1).or(z.literal(2)).or(z.literal(3)).or(z.literal(4)),
cleanliness: z.literal(1).or(z.literal(2)).or(z.literal(3)),
coed: z.boolean(),
displayName: z.string().min(1),
gender: z.string().min(1),
loudness: z.literal(1).or(z.literal(2)).or(z.literal(3)),
});

export const userProfileSchema = userProfileBodySchema
.or(apiErrorSchema);

export const searchResultSchema = z.array(userProfileBodySchema);

export const tokenMessageSchema = z.object({
token: z.string(),
});
Expand Down