From 61b54c40810910be9fb942a931f3e6a26fca30c2 Mon Sep 17 00:00:00 2001 From: Guus van Meerveld Date: Wed, 13 Mar 2024 13:41:55 +0100 Subject: [PATCH] basic trending page --- package.json | 65 +++++++++++++++-------------- src/app/(trending)/Trending.tsx | 73 +++++++++++++++++++++++++++++++++ src/app/(trending)/Video.tsx | 19 --------- src/app/(trending)/page.tsx | 7 ++-- src/app/providers.tsx | 10 ++++- src/hooks/useClient.ts | 16 ++++++++ src/utils/formatNumbers.ts | 14 +++++++ yarn.lock | 29 +++++++++++++ 8 files changed, 178 insertions(+), 55 deletions(-) create mode 100644 src/app/(trending)/Trending.tsx delete mode 100644 src/app/(trending)/Video.tsx create mode 100644 src/hooks/useClient.ts create mode 100644 src/utils/formatNumbers.ts diff --git a/package.json b/package.json index 3800c69..879393a 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,36 @@ { - "name": "materialtube", - "version": "0.1.0", - "private": true, - "scripts": { - "dev": "next dev", - "build": "next build", - "start": "next start", - "lint": "next lint" - }, - "dependencies": { - "@nextui-org/react": "^2.2.10", - "framer-motion": "^11.0.12", - "ky": "^1.2.2", - "next": "14.1.3", - "next-pwa": "^5.6.0", - "react": "^18", - "react-dom": "^18", - "zod": "^3.22.4" - }, - "devDependencies": { - "@types/next-pwa": "^5.6.9", - "@types/node": "^20", - "@types/react": "^18", - "@types/react-dom": "^18", - "autoprefixer": "^10.0.1", - "eslint": "^8", - "eslint-config-next": "14.1.3", - "postcss": "^8", - "tailwindcss": "^3.3.0", - "typescript": "^5" - } + "name": "materialtube", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "next lint" + }, + "dependencies": { + "@nextui-org/react": "^2.2.10", + "@tanstack/react-query": "^5.27.5", + "framer-motion": "^11.0.12", + "ky": "^1.2.2", + "next": "14.1.3", + "next-pwa": "^5.6.0", + "react": "^18", + "react-dom": "^18", + "react-icons": "^5.0.1", + "zod": "^3.22.4" + }, + "devDependencies": { + "@tanstack/react-query-devtools": "^5.27.8", + "@types/next-pwa": "^5.6.9", + "@types/node": "^20", + "@types/react": "^18", + "@types/react-dom": "^18", + "autoprefixer": "^10.0.1", + "eslint": "^8", + "eslint-config-next": "14.1.3", + "postcss": "^8", + "tailwindcss": "^3.3.0", + "typescript": "^5" + } } diff --git a/src/app/(trending)/Trending.tsx b/src/app/(trending)/Trending.tsx new file mode 100644 index 0000000..066ea95 --- /dev/null +++ b/src/app/(trending)/Trending.tsx @@ -0,0 +1,73 @@ +"use client"; + +import { Component } from "@/typings/component"; +import { useClient } from "@/hooks/useClient"; +import { useQuery } from "@tanstack/react-query"; +import { Card, CardFooter, CardBody } from "@nextui-org/card"; +import { Image } from "@nextui-org/image"; +import { Button } from "@nextui-org/button"; +import { CircularProgress } from "@nextui-org/progress"; +import { Divider } from "@nextui-org/divider"; +import Link from "next/link"; +import formatNumber from "@/utils/formatNumbers"; + +export const Trending: Component = ({}) => { + const client = useClient(); + + const { isLoading, error, data } = useQuery({ + queryKey: ["trending"], + queryFn: () => client.getTrending("NL") + }); + + return ( +
+ {isLoading && !data && ( +
+ +
+ )} + {data && ( +
+ {data.map((video) => ( + + + + {video.title} +

+ 20:41 +

+
+ + +
+

+ {video.title} +

+
+

+ {video.author.name} +

+

+ {video.uploaded.toLocaleDateString()} +

+ +

+ Views: {formatNumber(video.views)} +

+
+
+
+
+ + ))} +
+ )} +
+ ); +}; diff --git a/src/app/(trending)/Video.tsx b/src/app/(trending)/Video.tsx deleted file mode 100644 index 049892d..0000000 --- a/src/app/(trending)/Video.tsx +++ /dev/null @@ -1,19 +0,0 @@ -"use client"; - -import Client from "@/client"; -import { ApiType } from "@/client/adapters"; -import { Component } from "@/typings/component"; -import { useEffect } from "react"; - -export const Video: Component = ({}) => { - useEffect(() => { - const client = new Client([ - { baseUrl: "https://invidious.drgns.space", type: ApiType.Invidious }, - { baseUrl: "https://pipedapi.kavin.rocks", type: ApiType.Piped } - ]); - - client.getTrending("US").then(console.log); - }, []); - - return <>; -}; diff --git a/src/app/(trending)/page.tsx b/src/app/(trending)/page.tsx index 4068cd6..31944c4 100644 --- a/src/app/(trending)/page.tsx +++ b/src/app/(trending)/page.tsx @@ -1,10 +1,9 @@ -import { Button } from "@nextui-org/button"; -import { Video } from "./Video"; +import { Trending } from "./Trending"; -export default function Home() { +export default function Page() { return ( <> -