- Refactor of StreamsContext:

Added `featuredCategories` section,
Added personalised variations of HomePage contents;
- Removal of redundant/unused files from backend;
- Update to README: Updated to current method for deploying;
- Known bug: StreamsContext is being called before AuthContext, leading to unpersonalised streams & categories each time, even when logged in;
This commit is contained in:
Chris-1010
2025-01-24 17:23:56 +00:00
parent b9e912af1d
commit 5c16092b1c
18 changed files with 200 additions and 121 deletions

View File

@@ -1,4 +1,5 @@
import { createContext, useContext, useState, useEffect } from "react";
import { useAuth } from "./AuthContext";
interface StreamItem {
id: number;
@@ -10,24 +11,46 @@ interface StreamItem {
interface StreamsContextType {
featuredStreams: StreamItem[];
featuredCategories: StreamItem[];
setFeaturedStreams: (streams: StreamItem[]) => void;
setFeaturedCategories: (categories: StreamItem[]) => void;
}
const StreamsContext = createContext<StreamsContextType | undefined>(undefined);
export function StreamsProvider({ children }: { children: React.ReactNode }) {
const [featuredStreams, setFeaturedStreams] = useState<StreamItem[]>([]);
const [featuredCategories, setFeaturedCategories] = useState<StreamItem[]>(
[]
);
const { isLoggedIn } = useAuth();
const fetch_url = isLoggedIn
? ["/api/get_recommended_streams", "/api/get_followed_categories"]
: ["/api/get_streams", "/api/get_categories"];
useEffect(() => {
fetch("/api/get_streams")
fetch(fetch_url[0])
.then((response) => response.json())
.then((data: StreamItem[]) => {
setFeaturedStreams(data);
});
fetch(fetch_url[1])
.then((response) => response.json())
.then((data: StreamItem[]) => {
setFeaturedCategories(data);
});
}, []);
return (
<StreamsContext.Provider value={{ featuredStreams, setFeaturedStreams }}>
<StreamsContext.Provider
value={{
featuredStreams,
featuredCategories,
setFeaturedStreams,
setFeaturedCategories,
}}
>
{children}
</StreamsContext.Provider>
);