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

fixed many errors related to main pages #78

Merged
merged 3 commits into from
May 14, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Formatting Code

- For Python code run `black backend/**/*.py`
- For All other code run `bun run prettier * --write`

Expand Down
32 changes: 0 additions & 32 deletions app/[dh_choice]/accordian.css

This file was deleted.

188 changes: 0 additions & 188 deletions app/[dh_choice]/page.tsx

This file was deleted.

79 changes: 79 additions & 0 deletions app/[location]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"use client";
import { useState, useEffect, use } from "react";
import axios from "axios";

interface Food {
name: string;
restrictions: Array<string>;
}

interface subCategory {
name: string;
foods: Array<Food>;
}

interface Category {
name: string;
sub_categories: Array<subCategory>;
}

interface Location {
name: string;
categories: Category[];
}

export default function Page({ params }: { params: { location: number } }) {
const [location, setLocation] = useState<Location>();

// fetch location data
useEffect(() => {
axios
.get("http://localhost:8000/myapi/locations/")
.then((response) => {
// Fetch the locations data
const locations: Location[] = response.data["locations"];

// get the location data
const location = locations[params.location];

// Set the location
setLocation(location);
})
.catch((error) => {
console.log(error);
});
}, []);

return (
<main>
<div className="container mx-auto">
<h1 className="font-semibold py-5 text-4xl text-[#003C6C]">
{location && location.name}
</h1>
{location &&
location.categories.map((category, i) => (
<div key={i}>
<h2>{category.name}</h2>
{category.sub_categories.map((subCategory, j) => (
<div key={j}>
<h3>{subCategory.name}</h3>
{subCategory.foods.map((food, k) => (
<div key={k}>
<h4>{food.name}</h4>
<ul>
{food.restrictions.map((restrictions, l) => (
// note the restrictions is an array of strings
// this should probably be displayed in a different way for the images
<li key={l}>{restrictions}</li>
))}
</ul>
</div>
))}
</div>
))}
</div>
))}
</div>
</main>
);
}
13 changes: 6 additions & 7 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios from "axios";

interface Food {
name: string;
extra_data: Array<string>;
restrictions: Array<string>;
}

interface subCategory {
Expand All @@ -17,22 +17,21 @@ interface Category {
sub_categories: Array<subCategory>;
}

interface DiningHall {
interface Location {
name: string;
categories: Category;
}

import DhBar from "@/components/dh_bar_main";

export default function Home() {
const [dhs, setDhs] = useState<DiningHall[]>([]);
const [locations, setLocations] = useState<Location[]>([]);

useEffect(() => {
axios
.get("http://localhost:8000/myapi/locations/")
.then((response) => {
const dhs: DiningHall[] = response.data["locations"];
setDhs(dhs);
setLocations(response.data["locations"]);
})
.catch((error) => {
console.log(error);
Expand Down Expand Up @@ -65,9 +64,9 @@ export default function Home() {

<h3 className="w-full">
<ul className="">
{dhs.map((dh, i) => (
{locations.map((location, i) => (
<li key={i}>
<DhBar name={dh.name} />
<DhBar name={location.name} index={i} />
</li>
))}
</ul>
Expand Down
8 changes: 4 additions & 4 deletions backend/myapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def get_locations(request):
# check if the last update time doesn't exist
if last_update is None:
task = set_task(task_name="locations")
last_update = str_to_datetime(task["last_update"])

# get the current time and make it naive
time_now: datetime = timezone.now().replace(tzinfo=None)
time_now = str_to_datetime(task["last_update"])
else:
# get the current time and make it naive
time_now: datetime = timezone.now().replace(tzinfo=None)

print("Last time : ", last_update)
print("Current time: ", time_now)
Expand Down
2 changes: 1 addition & 1 deletion backend/webscraper/food.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def __str__(self) -> str:

def to_dict(self) -> dict:
# foodObj = {self.name: self.allergies}
return {"name": self.name, "allergies": self.allergies}
return {"name": self.name, "restrictions": self.allergies}
Loading