Skip to content

Commit 38f16ae

Browse files
authored
Merge pull request #132 from HungrySlugs-CSE115A/rating
Rating ui
2 parents bace5fe + 26cffd0 commit 38f16ae

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

app/foods/[food]/page.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export default function Page({ params }: { params: { food: string } }) {
2828
>,
2929
i,
3030
) => [
31-
category as string,
32-
(<Component key={i} food={food} />) as JSX.Element,
33-
],
31+
category as string,
32+
(<Component key={i} food={food} />) as JSX.Element,
33+
],
3434
);
3535

3636
useEffect(() => {
@@ -53,7 +53,10 @@ export default function Page({ params }: { params: { food: string } }) {
5353

5454
return (
5555
<main className="flex flex-col items-center">
56-
<ul className="flex font-medium text-2xl text-[#003C6C] items-center justify-center py-5">
56+
<h1 className="font-normal py-4 text-2xl text-[#003C6C]">
57+
{food.name}
58+
</h1>
59+
<ul className="flex font-medium text-2xl text-[#003C6C] items-center justify-center pb-5">
5760
{tabs.map(([category, _]: Array<string | JSX.Element>, i) => (
5861
<li key={i} className="">
5962
<button

components/food/comments.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ export default function Comments({ food }: { food: Food }) {
8686

8787
return (
8888
<div>
89-
<h1 className="text-2xl text-[#003C6C] flex items-center justify-center py-3 mr-2 mb-1">
90-
{food && food.name}
91-
</h1>
92-
<div>
89+
90+
<div className="pt-5">
9391
{comments.map((comment, i) => (
9492
<div
9593
key={comment.id}
@@ -158,11 +156,10 @@ export default function Comments({ food }: { food: Food }) {
158156
comment: textField,
159157
})
160158
}
161-
className={`ml-2 text-white ${
162-
textField.length === 0
163-
? "bg-gray-300 cursor-default"
164-
: "bg-blue-500 hover:bg-blue-700"
165-
} rounded-md px-4 py-2`}
159+
className={`ml-2 text-white ${textField.length === 0
160+
? "bg-gray-300 cursor-default"
161+
: "bg-blue-500 hover:bg-blue-700"
162+
} rounded-md px-4 py-2`}
166163
disabled={textField.length === 0}
167164
>
168165
Post

components/food/ratings.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import { Food } from "@/interfaces/Food";
2+
import { Doppio_One } from "next/font/google";
3+
24

35
export default function Ratings({ food }: { food: Food }) {
6+
console.log(food);
47
return (
5-
<div>
6-
<h1>{food && food.name}</h1>
7-
<h2>Ratings</h2>
8-
<div>
9-
<p>Rating 1</p>
10-
<p>Rating 2</p>
11-
<p>Rating 3</p>
8+
<div className="w-screen "> {/* Yes I know this is horribly written and inefficent -Noah*/}
9+
<h1 className="flex justify-center font-normal py-2 text-xl text-[#003C6C]">
10+
<div className="flex w-1/3 pl-5">
11+
User
12+
</div>
13+
<div className="flex w-3/2 ">
14+
Rating
15+
</div>
16+
</h1>
17+
18+
<div className="flex flex-col justify-center ">
19+
{/* convert ratings obj to array and map */
20+
Object.entries(food.ratings).map(([user_id, rating]) => (
21+
<p key={user_id} className="flex flex-row justify-center pb-2 my-1 text-med">
22+
<div className="px-5 flex w-1/3 border-white border bg-[#F9F9F9] font-medium text-[#003C6C]">{user_id}</div>
23+
<div className="px-5 flex w-3/2 border-white border bg-[#F9F9F9] font-medium text-gray-700">{rating.rating}</div>
24+
</p>
25+
26+
))}
1227
</div>
1328
</div>
1429
);

components/location/food.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ export default function LocationFood({
4242
))}
4343
</ul>
4444

45-
<div>
46-
<h4 className="flex justify-center"> {average ? average : "?"} </h4>
45+
<div className="bg-gray-200 ">
46+
47+
<h4 className="flex justify-center px-2">Score: {average ? average : "?"} </h4>
4748
</div>
4849
<div>
49-
<h4 className="flex justify-center">
50-
<form>
51-
<select
50+
<h4 className="flex justify-center pl-2">
51+
<form className="text-center">
52+
<select className=" text-center py-0.5 px-2 w-20"
5253
name="rating"
5354
id="rating"
5455
onChange={(e) =>
@@ -58,16 +59,17 @@ export default function LocationFood({
5859
food_rating: parseInt(e.target.value),
5960
}).then((data) => {
6061
const newAverage = data.average;
62+
food_average = newAverage;
6163
setAverage(newAverage);
6264
})
6365
}
6466
>
65-
<option value={user_rating ? user_rating : 5}>
66-
{user_rating ? user_rating : "Rate"}
67+
<option className="font-sans" value={user_rating ? user_rating : 5}>
68+
{user_rating ? user_rating : "Rating"}
6769
</option>
6870
{ratings.map((rating, index) => (
6971
<option
70-
className="flex justify-center"
72+
className="flex justify-center font-sans"
7173
key={index}
7274
value={rating}
7375
>

interfaces/Food.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
export interface Comment {
24
id: number;
35
user_id: string;
@@ -6,9 +8,12 @@ export interface Comment {
68
}
79

810
export interface Rating {
9-
user_id: string;
1011
rating: number;
11-
date: string;
12+
13+
}
14+
15+
export interface Ratings {
16+
[user_id: string]: Rating;
1217
}
1318

1419
export interface Image {
@@ -21,6 +26,6 @@ export interface Food {
2126
name: string;
2227
restrictions: Array<string> | never[];
2328
comments: Array<Comment> | never[];
24-
ratings: Array<Rating> | never[];
29+
ratings: Ratings | never[];
2530
images: Array<Image> | never[];
2631
}

0 commit comments

Comments
 (0)