From ceb7b8646299d870c334114ee276b59d429bffd9 Mon Sep 17 00:00:00 2001 From: Cron1cle <118773725+Cron1cle@users.noreply.github.com> Date: Fri, 17 Oct 2025 11:53:45 +0200 Subject: [PATCH] api: update key to api --- .gitignore | 1 + apis/showApi.ts | 11 +++++--- apis/streamingServiceApi.ts | 8 +++++- app/(tabs)/index.tsx | 6 +++++ app/showDetails.tsx | 38 ++++++++++++++++++---------- app/stackStyles/showDetailStyles.tsx | 7 +++++ contexts/SeasonContext.tsx | 4 +-- 7 files changed, 55 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index ba575ae..81862ad 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ web-build/ expo-env.d.ts ios android +.env # Native .kotlin/ diff --git a/apis/showApi.ts b/apis/showApi.ts index 0661433..6e802e6 100644 --- a/apis/showApi.ts +++ b/apis/showApi.ts @@ -32,8 +32,15 @@ const SHOW_API_URL = "http://45.157.177.99:8080/shows"; export async function getShows(): Promise { try { - const response = await fetch(SHOW_API_URL); + const apiKey = process.env.EXPO_PUBLIC_API_KEY; + const response = await fetch(SHOW_API_URL, { + headers: { + "Content-Type": "application/json", + "X-API-Key": apiKey ?? "", + }, + }); if (!response.ok) { + console.error("Fetch error:", response); throw new Error("Network response was not ok"); } const data: unknown = await response.json(); @@ -52,8 +59,6 @@ export async function getShows(): Promise { concept: s.concept, running: s.running, logoUri: s.logoUrl ?? "", - startDate: s.startDate, - endDate: s.endDate, })); } catch (error) { console.error("Fetch error:", error); diff --git a/apis/streamingServiceApi.ts b/apis/streamingServiceApi.ts index f952007..0d98b55 100644 --- a/apis/streamingServiceApi.ts +++ b/apis/streamingServiceApi.ts @@ -8,7 +8,13 @@ const STREAMING_SERVICE_API_URL = "http://45.157.177.99:8080/config"; export async function getStreamingImages(): Promise { try { - const response = await fetch(STREAMING_SERVICE_API_URL); + const apiKey = process.env.EXPO_PUBLIC_API_KEY; + const response = await fetch(STREAMING_SERVICE_API_URL, { + headers: { + "Content-Type": "application/json", + "X-API-Key": apiKey ?? "", + }, + }); if (!response.ok) { throw new Error("Network response was not ok"); } diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 6e1ee17..43e8784 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -48,6 +48,11 @@ export default function HomeScreen() { return Array.from(uniqueServices); }, [shows]); + console.log( + "Start Dates:", + shows.map((show) => show.startDate) + ); + if (loading) { return ( (true); @@ -36,16 +35,17 @@ export default function ShowDetails() { const [participants, setParticipants] = React.useState< { id: number; name: string; imageUri: string }[] >([]); + const [startDate, setStartDate] = React.useState( + undefined + ); const [pLoading, setPLoading] = React.useState(false); const [pError, setPError] = React.useState(null); - const sortedParticipants = React.useMemo( - () => - [...participants].sort((a, b) => - a.name.localeCompare(b.name, "de", { sensitivity: "base" }) - ), - [participants] - ); + const sortedParticipants = React.useMemo(() => { + return participants.sort((a, b) => + a.name.localeCompare(b.name, "de", { sensitivity: "base" }) + ); + }, [participants]); React.useEffect(() => { if (!showId) return; @@ -82,6 +82,13 @@ export default function ShowDetails() { }; }, [showId, selectedSeason, fetchSeasonParticipants]); + const startDateObj = new Date(startDate as string); + const formattedStartDate = startDateObj.toLocaleDateString("de-DE", { + day: "2-digit", + month: "long", + year: "numeric", + }); + return ( @@ -91,6 +98,7 @@ export default function ShowDetails() { paddingBottom: Dimensions.get("window").height * 0.1, }} > + {formattedStartDate} setSelectedSeason(season)} + onPress={() => { + setSelectedSeason(season); + }} > {season} diff --git a/app/stackStyles/showDetailStyles.tsx b/app/stackStyles/showDetailStyles.tsx index d9d5ed9..804f553 100644 --- a/app/stackStyles/showDetailStyles.tsx +++ b/app/stackStyles/showDetailStyles.tsx @@ -137,5 +137,12 @@ const styles = StyleSheet.create({ marginLeft: 20, marginTop: 5, }, + startDate: { + color: "hsl(0, 0%, 80%)", + fontSize: 16, + textAlign: "center", + marginTop: 15, + fontStyle: "italic", + }, }); export default styles; diff --git a/contexts/SeasonContext.tsx b/contexts/SeasonContext.tsx index d31d2e6..b5e9394 100644 --- a/contexts/SeasonContext.tsx +++ b/contexts/SeasonContext.tsx @@ -1,10 +1,10 @@ import { getSeason, SeasonParticipant } from "@/apis/seasonApi"; import React, { createContext, + ReactNode, + useCallback, useContext, useState, - useCallback, - ReactNode, } from "react"; type SeasonContextType = {