diff --git a/package-lock.json b/package-lock.json index 495d0bf..1f92b65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,10 @@ "name": "ultyt", "version": "0.0.0", "dependencies": { + "@heroicons/react": "^2.0.18", "@nextui-org/react": "^2.0.7", "framer-motion": "^10.15.1", - "piped-api": "^1.1.2", + "piped-api": "^1.1.6", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.14.2" @@ -529,6 +530,14 @@ "tslib": "^2.4.0" } }, + "node_modules/@heroicons/react": { + "version": "2.0.18", + "resolved": "https://registry.npmjs.org/@heroicons/react/-/react-2.0.18.tgz", + "integrity": "sha512-7TyMjRrZZMBPa+/5Y8lN0iyvUU/01PeMGX2+RE7cQWpEUIcb4QotzUObFkJDejj/HUH4qjP/eQ0gzzKs2f+6Yw==", + "peerDependencies": { + "react": ">= 16" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", @@ -4430,9 +4439,9 @@ } }, "node_modules/piped-api": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/piped-api/-/piped-api-1.1.2.tgz", - "integrity": "sha512-5eEGjsehCG/uazk6yPzv1FuPm9pe7HYyFBgAzJoHcCLVROwOifk5+qdQMCqEeVL0d5rtdiB2i+KOozZzmsUZqg==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/piped-api/-/piped-api-1.1.6.tgz", + "integrity": "sha512-Tyn6/x/nBass469Io5zyILKylQI6sHE0MIYPYgD5nD232TmBF3G0OU+AQrvqU6cCla+Bkff3oFo+4GhnJKeiuA==", "dependencies": { "axios": "^1.4.0" } diff --git a/package.json b/package.json index 4c03776..8c2f628 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,10 @@ "preview": "vite preview" }, "dependencies": { + "@heroicons/react": "^2.0.18", "@nextui-org/react": "^2.0.7", "framer-motion": "^10.15.1", - "piped-api": "^1.1.2", + "piped-api": "^1.1.6", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.14.2" diff --git a/src/App.tsx b/src/App.tsx index 3f9febc..6d92040 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,10 +1,9 @@ +import "./App.css"; -import './App.css' - -import {NextUIProvider} from "@nextui-org/react"; +import { NextUIProvider } from "@nextui-org/react"; import { PipedAPI } from "piped-api"; -import { BrowserRouter, Route, Routes } from 'react-router-dom'; -import Trending from './pages/trending'; +import { BrowserRouter, Route, Routes } from "react-router-dom"; +import Trending from "./pages/trending"; declare global { interface Window { @@ -12,7 +11,7 @@ declare global { } } function App() { - window.piped_api = new PipedAPI("https://ytapi.dc09.ru"); + window.piped_api = new PipedAPI(); //"https://ytapi.dc09.ru"); return ( @@ -22,7 +21,7 @@ function App() { - ) + ); } -export default App +export default App; diff --git a/src/components/utils.ts b/src/components/utils.ts new file mode 100644 index 0000000..f68727a --- /dev/null +++ b/src/components/utils.ts @@ -0,0 +1,8 @@ +export function shortenNumber(number: number) { + if (number >= 1000000) { + return (number / 1000000).toFixed(2) + "M"; + } else if (number >= 1000) { + return (number / 1000).toFixed(1) + "k"; + } + return number.toString(); +} diff --git a/src/components/video.tsx b/src/components/video.tsx new file mode 100644 index 0000000..3447078 --- /dev/null +++ b/src/components/video.tsx @@ -0,0 +1,47 @@ +import { Avatar, Card, CardBody, CardHeader, Link } from "@nextui-org/react"; +import { Video } from "piped-api/dist/types"; +import { useNavigate } from "react-router-dom"; +import { CheckCircleIcon, EyeIcon } from "@heroicons/react/24/solid"; +import { shortenNumber } from "./utils"; +export function VideoComponent({ video }: VideoComponentProps) { + const navigate = useNavigate(); + + return ( + navigate(video.url)} + shadow="none" + > + + + + + +
+ + {video.title} + + +
+

{video.uploaderName}

+ {video.uploaderVerified && ( + + )} +
+ +
+ +

+ {`${shortenNumber(video.views)} • ${video.uploadedDate}`} +

+
+
+
+
+ ); +} + +type VideoComponentProps = { + video: Video; +}; diff --git a/src/pages/trending.tsx b/src/pages/trending.tsx index 64c9380..f26443a 100644 --- a/src/pages/trending.tsx +++ b/src/pages/trending.tsx @@ -1,17 +1,14 @@ -import { Video } from "piped-api/dist/responses.interface"; +import { Video } from "piped-api/dist/types"; import { useEffect, useState } from "react"; +import { VideoComponent } from "../components/video"; -import {Avatar, Badge, Card, CardHeader, CardBody, CardFooter, Divider, Link, Image} from "@nextui-org/react"; export default function Trending() { - const [trending, setTrending] = useState([] as Video[]); useEffect(() => { - async function getTrending(){ - - const trending = await window.piped_api.trending("US"); - setTrending(trending); - console.log(trending); + async function getTrending() { + const trending = await window.piped_api.trending("US"); //await window.piped_api.search("artegoser"); + setTrending(trending); } if (trending.length === 0) { @@ -19,12 +16,11 @@ export default function Trending() { } }); - return
{trending.map((video) => - - - - -

{video.uploaderName}

-
-
)}
; + return ( +
+ {trending.map((video) => ( + + ))} +
+ ); }