Files
Jellystat/src/pages/components/library/recently-added.js
Thegan Govender e7912397d2 Code clean-up + API Keys
Cleaned up redundant code and moved around classes to be better grouped eg routes folder

Moved endpoints to other route files to better represent their actions

Removed redundant endpoints

Renamed endpoints to be more meaningful

Added API Key authorisations to utilize the API outside of Jellystat UI (Still need to document Endpoints)

Added new column to app_config to store api keys

New API Section under settings

Updated backups route name
2023-07-01 22:52:19 +02:00

75 lines
1.6 KiB
JavaScript

import React, { useState, useEffect } from "react";
import axios from "axios";
import RecentlyAddedCard from "./RecentlyAdded/recently-added-card";
import "../../css/users/user-details.css";
import ErrorBoundary from "../general/ErrorBoundary";
function RecentlyAdded(props) {
const [data, setData] = useState();
const token = localStorage.getItem('token');
useEffect(() => {
const fetchData = async () => {
try {
let url=`/proxy/getRecentlyAdded`;
if(props.LibraryId)
{
url+=`?libraryid=${props.LibraryId}`;
}
const itemData = await axios.get(url, {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});
if(itemData && typeof itemData.data === 'object' && Array.isArray(itemData.data))
{
setData(itemData.data.filter((item) => ["Series", "Movie","Audio","Episode"].includes(item.Type)));
}
} catch (error) {
console.log(error);
}
};
if (!data) {
fetchData();
}
const intervalId = setInterval(fetchData, 60000 * 5);
return () => clearInterval(intervalId);
}, [data, props.LibraryId]);
if (!data) {
return <></>;
}
return (
<div className="last-played">
<h1 className="my-3">Recently Added</h1>
<div className="last-played-container">
{data && data.map((item) => (
<ErrorBoundary key={item.Id}>
<RecentlyAddedCard data={item}/>
</ErrorBoundary>
))}
</div>
</div>
);
}
export default RecentlyAdded;