FIX: end_stream route input data handling;
PATCH/UPDATE: Handle cases where content fetched is falsy/empty
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.5.0",
|
"version": "0.15.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --config vite.config.dev.ts",
|
"dev": "vite --config vite.config.dev.ts",
|
||||||
|
|||||||
@@ -225,13 +225,13 @@ const StreamDashboard: React.FC<StreamDashboardProps> = ({ username, userId, isL
|
|||||||
const handleEndStream = async () => {
|
const handleEndStream = async () => {
|
||||||
console.log("Ending stream...");
|
console.log("Ending stream...");
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("key", streamData.stream_key);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/end_stream", {
|
const response = await fetch("/api/end_stream", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ key: streamData.stream_key }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -375,7 +375,9 @@ const StreamDashboard: React.FC<StreamDashboardProps> = ({ username, userId, isL
|
|||||||
streamCategory={streamData.category_name || "Category"}
|
streamCategory={streamData.category_name || "Category"}
|
||||||
viewers={streamData.viewer_count}
|
viewers={streamData.viewer_count}
|
||||||
thumbnail={thumbnailPreview.url || ""}
|
thumbnail={thumbnailPreview.url || ""}
|
||||||
onItemClick={() => {}}
|
onItemClick={() => {
|
||||||
|
window.open(`/${username}`, "_blank");
|
||||||
|
}}
|
||||||
extraClasses="max-w-[20vw]"
|
extraClasses="max-w-[20vw]"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const processVodData = (data: any[]): VodType[] => {
|
|||||||
|
|
||||||
// Helper function to process API data into our consistent types
|
// Helper function to process API data into our consistent types
|
||||||
const processStreamData = (data: any[]): StreamType[] => {
|
const processStreamData = (data: any[]): StreamType[] => {
|
||||||
|
if (!data || data.length === 0 || !data[0] || !data[0].user_id) return [];
|
||||||
return data.map((stream) => ({
|
return data.map((stream) => ({
|
||||||
type: "stream",
|
type: "stream",
|
||||||
id: stream.user_id,
|
id: stream.user_id,
|
||||||
@@ -76,8 +77,9 @@ export function useFetchContent<T>(
|
|||||||
throw new Error(`Error fetching data: ${response.status}`);
|
throw new Error(`Error fetching data: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawData = await response.json();
|
const rawData = await response.json();
|
||||||
const processedData = processor(rawData);
|
let processedData = processor(Array.isArray(rawData) ? rawData : (rawData ? [rawData] : []));
|
||||||
|
console.log("processedData", processedData);
|
||||||
setData(processedData);
|
setData(processedData);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -126,7 +128,7 @@ export function useVods(customUrl?: string): {
|
|||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
} {
|
} {
|
||||||
const url = customUrl || "api/vods/all"; //TODO: Change this to the correct URL or implement it
|
const url = customUrl || "api/vods/all";
|
||||||
const { data, isLoading, error } = useFetchContent<VodType>(url, processVodData, [customUrl]);
|
const { data, isLoading, error } = useFetchContent<VodType>(url, processVodData, [customUrl]);
|
||||||
|
|
||||||
return { vods: data, isLoading, error };
|
return { vods: data, isLoading, error };
|
||||||
|
|||||||
Reference in New Issue
Block a user