Major: Added Authentication Functionality, interfaces with backend;

Added new styles to HomePage & VideoPage;
Added AuthContext to persist logged_in status;
This commit is contained in:
Chris-1010
2025-01-24 15:17:53 +00:00
parent ca2a7e9baf
commit 8ec60b1c41
24 changed files with 831 additions and 204 deletions

View File

@@ -0,0 +1,42 @@
import { createContext, useContext, useState, useEffect } from "react";
interface StreamItem {
id: number;
title: string;
streamer: string;
viewers: number;
thumbnail?: string;
}
interface StreamsContextType {
featuredStreams: StreamItem[];
setFeaturedStreams: (streams: StreamItem[]) => void;
}
const StreamsContext = createContext<StreamsContextType | undefined>(undefined);
export function StreamsProvider({ children }: { children: React.ReactNode }) {
const [featuredStreams, setFeaturedStreams] = useState<StreamItem[]>([]);
useEffect(() => {
fetch("/api/get_streams")
.then((response) => response.json())
.then((data: StreamItem[]) => {
setFeaturedStreams(data);
});
}, []);
return (
<StreamsContext.Provider value={{ featuredStreams, setFeaturedStreams }}>
{children}
</StreamsContext.Provider>
);
}
export function useStreams() {
const context = useContext(StreamsContext);
if (context === undefined) {
throw new Error("useStreams must be used within a StreamsProvider");
}
return context;
}