Skip to content

Commit

Permalink
feat: Fetch localized Kantiinit menus, change infoscreen path
Browse files Browse the repository at this point in the history
- Infoscreen is now /infoscreen instead of /infonaytto/naytto
- Kanttiinit menus are now fetched in Finnish and English depending on locale
  • Loading branch information
IiroP committed Jan 17, 2025
1 parent abd1e57 commit ef05b67
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
16 changes: 0 additions & 16 deletions apps/web/src/app/[locale]/(infoscreen)/infonaytto/naytto/page.tsx

This file was deleted.

16 changes: 16 additions & 0 deletions apps/web/src/app/[locale]/(infoscreen)/infoscreen/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HSLcombinedSchedule } from "../../../../components/infoscreen/hsl-schedules-combined";
import { KanttiinitCombined } from "../../../../components/infoscreen/kanttiinit-combined";
import InfoScreenSwitcher from "../../../../components/infoscreen/infoscreen-switcher/index";
import EventListInfoscreen from "../../../../components/infoscreen/events-list";

export const dynamic = "force-dynamic";

export default function InfoScreenContents() {
return (
<InfoScreenSwitcher>
<HSLcombinedSchedule />
<KanttiinitCombined />
<EventListInfoscreen />
</InfoScreenSwitcher>
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Locale } from "../../../locales/server";
import type {
DayMenu,
Food,
Expand All @@ -10,11 +11,11 @@ type DayMenuResponse = Record<string, Food[]>;
// Single restaurant menu in Kanttiinit API, key is restaurant id
type RestaurantMenuResponse = Record<string, DayMenuResponse>;

export async function KanttiinitMenus() {
export async function KanttiinitMenus(locale?: Locale) {
const ids = [2, 7, 52];
const today = new Date().toISOString().split("T")[0];
const response: Response = await fetch(
`https://kitchen.kanttiinit.fi/menus?${ids.join(",")}&days=${today}`,
`https://kitchen.kanttiinit.fi/menus?lang=${locale ?? "fi"}&${ids.join(",")}&days=${today}`,
{ next: { revalidate: 3600 } }, // fetch only once per hour
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Locale } from "../../../locales/server";
import type { OpeningHour, Restaurant } from "../types/kanttiinit-types";

interface RestaurantResponse {
Expand All @@ -12,9 +13,9 @@ interface RestaurantResponse {
name: string;
}

export async function KanttiinitRestaurants() {
export async function KanttiinitRestaurants(locale?: Locale) {
const response: Response = await fetch(
"https://kitchen.kanttiinit.fi/restaurants?lang=fi&ids=2,7,52&priceCategories=student",
`https://kitchen.kanttiinit.fi/restaurants?lang=${locale ?? "fi"}&ids=2,7,52&priceCategories=student`,
{ next: { revalidate: 3600 } }, // fetch only once per hour
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getCurrentLocale } from "../../../locales/server";
import type {
Restaurant,
RestaurantMenu,
Expand All @@ -8,8 +9,9 @@ import { KanttiinitRestaurants } from "./restaurants";

export const fetchMenus = async (): Promise<RestaurantMenu[]> => {
try {
const restaurants = await KanttiinitRestaurants();
const menus = await KanttiinitMenus();
const locale = await getCurrentLocale();
const restaurants = await KanttiinitRestaurants(locale);
const menus = await KanttiinitMenus(locale);
const newMenus: RestaurantMenu[] = restaurants.map(
(restaurant: Restaurant) => {
return {
Expand Down

0 comments on commit ef05b67

Please sign in to comment.