Skip to content

Added new documentation #134

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

Merged
merged 10 commits into from
Jun 3, 2024
Merged
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
210 changes: 183 additions & 27 deletions README.md

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions app/foods/[food]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default function Page({ params }: { params: { food: string } }) {
>,
i,
) => [
category as string,
(<Component key={i} food={food} />) as JSX.Element,
],
category as string,
(<Component key={i} food={food} />) as JSX.Element,
],
);

useEffect(() => {
Expand All @@ -53,9 +53,7 @@ export default function Page({ params }: { params: { food: string } }) {

return (
<main className="flex flex-col items-center">
<h1 className="font-normal py-4 text-2xl text-[#003C6C]">
{food.name}
</h1>
<h1 className="font-normal py-4 text-2xl text-[#003C6C]">{food.name}</h1>
<ul className="flex font-medium text-2xl text-[#003C6C] items-center justify-center pb-5">
{tabs.map(([category, _]: Array<string | JSX.Element>, i) => (
<li key={i} className="">
Expand Down
74 changes: 37 additions & 37 deletions app/global_search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios from "axios";
import Image from "next/image";
import Link from "next/link";
import styles from "./Search.module.css";
import { fetchLocations } from "@/app/db";
import { fetchLocations } from "@/app/requests";
import { Location, Food } from "@/interfaces/Location";

interface FoodWithCategory {
Expand Down Expand Up @@ -41,40 +41,40 @@ const GlobalSearch = () => {
() => {
const storedRestrictions = localStorage.getItem("selectedRestrictions");
return storedRestrictions ? JSON.parse(storedRestrictions) : [];
}
},
);
const [filterApplied, setFilterApplied] = useState<boolean>(false);

useEffect(() => {
fetchLocations().then((locations: Location[]) => {
setLocations(locations);

const allFoods = locations.flatMap(location =>
location.categories.flatMap(category =>
category.sub_categories.flatMap(subCategory =>
subCategory.foods.map(food => ({
const allFoods = locations.flatMap((location) =>
location.categories.flatMap((category) =>
category.sub_categories.flatMap((subCategory) =>
subCategory.foods.map((food) => ({
food: food,
category: category.name,
diningHall: location.name // Added dining hall name
}))
)
)
diningHall: location.name, // Added dining hall name
})),
),
),
);
setFoods(allFoods);
});
}, []);

const searchForFood = (food_name: string) => {
const foundFoods = foods.filter(foodWithCategory =>
const foundFoods = foods.filter((foodWithCategory) =>
foodWithCategory.food.name
.toLowerCase()
.includes(food_name.toLowerCase())
.includes(food_name.toLowerCase()),
);

const filteredFoods = foundFoods.filter(({ food }) =>
selectedRestrictions.every(restriction =>
food.restrictions.includes(restriction)
)
selectedRestrictions.every((restriction) =>
food.restrictions.includes(restriction),
),
);

setFoundFoods(filteredFoods);
Expand All @@ -87,11 +87,11 @@ const GlobalSearch = () => {
const handleRestrictionChange = (restriction: string, checked: boolean) => {
const newRestrictions = checked
? [...selectedRestrictions, restriction]
: selectedRestrictions.filter(r => r !== restriction);
: selectedRestrictions.filter((r) => r !== restriction);
setSelectedRestrictions(newRestrictions);
localStorage.setItem(
"selectedRestrictions",
JSON.stringify(newRestrictions)
JSON.stringify(newRestrictions),
);
};

Expand All @@ -109,14 +109,14 @@ const GlobalSearch = () => {
Global Search
</h1>
</div>

<div className={styles.flexCenter}>
<div className="search-bar flex justify-center items-center mb-2">
<input
type="text"
placeholder="Search foods..."
className="border border-gray-400 p-2 rounded"
onChange={e => setSearchInput(e.target.value)}
onChange={(e) => setSearchInput(e.target.value)}
/>
<button
onClick={() => searchForFood(searchInput)}
Expand All @@ -126,7 +126,7 @@ const GlobalSearch = () => {
</button>
</div>
</div>

<div className={styles.flexCenter}>
<button
onClick={toggleFilterPopup}
Expand All @@ -143,7 +143,7 @@ const GlobalSearch = () => {
Filter by Restrictions
</h2>
<div className="flex flex-wrap">
{restrictions.map(restriction => (
{restrictions.map((restriction) => (
<div
key={restriction}
className="flex items-center mr-4 mb-2"
Expand All @@ -153,7 +153,7 @@ const GlobalSearch = () => {
id={restriction}
className="mr-2"
checked={selectedRestrictions.includes(restriction)}
onChange={e =>
onChange={(e) =>
handleRestrictionChange(restriction, e.target.checked)
}
/>
Expand Down Expand Up @@ -200,7 +200,8 @@ const GlobalSearch = () => {
>
<h4 className="px-2">{foodWithCategory.food.name}</h4>
<h5 className="font-normal text-gray-400 px-2">
{foodWithCategory.category} @ {foodWithCategory.diningHall} {/* Added dining hall name */}
{foodWithCategory.category} @ {foodWithCategory.diningHall}{" "}
{/* Added dining hall name */}
</h5>
</Link>
<ul className="flex flex-row mr-3">
Expand All @@ -214,17 +215,16 @@ const GlobalSearch = () => {
height={25}
/>
</li>
)
)}
</ul>
</div>
))
)}
</div>
</div>
</main>
);
};

export default GlobalSearch;

),
)}
</ul>
</div>
))
)}
</div>
</div>
</main>
);
};

export default GlobalSearch;
10 changes: 6 additions & 4 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={monst.className}>
<Navbar height={navbarHeight} />
<div className="" style={{ paddingTop: navbarHeight }}>
{children}
<body className="font-sans">
<div className={`${monst.className}`}>
<Navbar height={navbarHeight} />
<div className="" style={{ paddingTop: navbarHeight }}>
{children}
</div>
</div>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion app/locations/[location]/DH_Search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
import Image from "next/image";
import Link from "next/link";

import { fetchLocations } from "@/app/db";
import { fetchLocations } from "@/app/requests";
import { Location, Food } from "@/interfaces/Location";

interface FoodWithCategory {
Expand Down
7 changes: 5 additions & 2 deletions app/locations/[location]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use client";
import { fetchLocations, fetchFoodReviewsBulk } from "@/app/db";
import {
fetchLocations,
fetchFoodReviewsBulk,
fetchUserInfo,
} from "@/app/requests";
import { Location } from "@/interfaces/Location";
import { FrontEndReviews } from "@/interfaces/Review";

import { useState, useEffect } from "react";

import LocationCategories from "@/components/location/categories";
import Link from "next/link";
import { fetchUserInfo } from "@/app/user_info";

export default function Page({ params }: { params: { location: number } }) {
const [location, setLocation] = useState<Location | null>(null);
Expand Down
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server";

import { fetchLocations } from "@/app/db";
import { fetchLocations } from "@/app/requests";
import LocationsClient from "@/components/LocationsClient";
import { Location } from "@/interfaces/Location";

Expand Down
4 changes: 2 additions & 2 deletions app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import { useEffect, useState } from "react";
import { googleLogout } from "@react-oauth/google";
import axios from "axios";
import { fetchUserInfo } from "@/app/user_info";
import { fetchUserInfo } from "@/app/requests";

interface User {
name: string;
Expand Down Expand Up @@ -68,4 +68,4 @@ const Page = () => {
);
};

export default Page;
export default Page;
28 changes: 28 additions & 0 deletions app/db.ts → app/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,31 @@ export async function updateReview(data: {

return res.data;
}

export async function fetchUserInfo() {
try {
const access_token = sessionStorage.getItem("token");

if (!access_token) {
throw new Error("No access token found in session storage.");
}

const response = await axios.get(
"https://www.googleapis.com/oauth2/v3/userinfo",
{
headers: { Authorization: `Bearer ${access_token}` },
},
);

const userInfo = response.data;

return {
name: userInfo.name,
email: userInfo.email,
picture: userInfo.picture,
};
} catch (error) {
console.error("Error fetching user info:", error);
throw error; // Re-throw the error so it can be handled by the calling code
}
}
28 changes: 0 additions & 28 deletions app/user_info.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@
"use client";
import axios from "axios";

export const fetchUserInfo = async () => {
try {
const access_token = sessionStorage.getItem("token");

if (!access_token) {
throw new Error("No access token found in session storage.");
}

const response = await axios.get(
"https://www.googleapis.com/oauth2/v3/userinfo",
{
headers: { Authorization: `Bearer ${access_token}` },
},
);

const userInfo = response.data;

return {
name: userInfo.name,
email: userInfo.email,
picture: userInfo.picture,
};
} catch (error) {
console.error("Error fetching user info:", error);
throw error; // Re-throw the error so it can be handled by the calling code
}
};
1 change: 1 addition & 0 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def upload_image(request):
# Return a JSON response with an error message if no image is provided or method is not POST
return JsonResponse({"success": False, "message": "Image upload failed"})


# @api_view(["GET"])
# def get_user_rating(request):
# user = get_rating(request.user_ids)
Expand Down
Loading