import { NextPage } from "next"; import { NextSeo } from "next-seo"; import { useState } from "react"; import { useQuery } from "react-query"; import axios, { AxiosError } from "axios"; import Box from "@mui/material/Box"; import Chip from "@mui/material/Chip"; import Typography from "@mui/material/Typography"; import { Error } from "@interfaces/api"; import VideoTrending from "@interfaces/api/trending"; import { apiToVideo } from "@utils/conversions"; import { useSettings } from "@utils/hooks"; import Layout from "@components/Layout"; import Loading from "@components/Loading"; import Grid from "@components/Video/Grid"; const Trending: NextPage = () => { const [selectedCategory, setCategory] = useState(); const [settings] = useSettings(); const { isLoading, error, data } = useQuery< VideoTrending[], AxiosError >("trendingData", () => axios .get(`https://${settings.invidiousServer}/api/v1/trending`, { params: { fields: [ "title", "description", "descriptionHtml", "videoId", "author", "authorId", "authorUrl", "lengthSeconds", "published", "publishedText", "viewCount", "videoThumbnails" ].join(","), type: selectedCategory } }) .then((res) => res.data) ); return ( <> {isLoading && } {error && {error.response?.data.error}} {!isLoading && !error && data && ( <> Categories: {["Music", "Gaming", "News", "Movies"].map((category) => { const name = category.toLowerCase(); const isSelected = name == selectedCategory; return ( setCategory(isSelected ? undefined : name)} /> ); })} )} ); }; export default Trending;