mirror of
https://github.com/artegoser/ultyt.git
synced 2024-11-22 03:56:21 +03:00
feat: channels in channel
This commit is contained in:
parent
7721e04417
commit
46e121a037
6 changed files with 77 additions and 16 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -11,7 +11,7 @@
|
||||||
"@heroicons/react": "^2.0.18",
|
"@heroicons/react": "^2.0.18",
|
||||||
"@nextui-org/react": "^2.0.7",
|
"@nextui-org/react": "^2.0.7",
|
||||||
"framer-motion": "^10.15.1",
|
"framer-motion": "^10.15.1",
|
||||||
"piped-api": "^1.2.1",
|
"piped-api": "^1.2.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-router-dom": "^6.14.2"
|
"react-router-dom": "^6.14.2"
|
||||||
|
@ -4439,9 +4439,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/piped-api": {
|
"node_modules/piped-api": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/piped-api/-/piped-api-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/piped-api/-/piped-api-1.2.2.tgz",
|
||||||
"integrity": "sha512-HoJPQVEiDkwPFTwl29pg1zRcCm7GGZjW5pWt35A8uRRPb6475NgmZT0K+Z+GPtC4j78rbcGK2NEdkZceibW9gQ==",
|
"integrity": "sha512-eSzyanTMRGq3c9xCsSSlDXQ7jmd9auLvRIP5RNwv7yIkYBQjBxbQI5CR1vLcmKnD1tw4XdBF15aLIh0Jru3iIw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.4.0"
|
"axios": "^1.4.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
"@heroicons/react": "^2.0.18",
|
"@heroicons/react": "^2.0.18",
|
||||||
"@nextui-org/react": "^2.0.7",
|
"@nextui-org/react": "^2.0.7",
|
||||||
"framer-motion": "^10.15.1",
|
"framer-motion": "^10.15.1",
|
||||||
"piped-api": "^1.2.1",
|
"piped-api": "^1.2.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-router-dom": "^6.14.2"
|
"react-router-dom": "^6.14.2"
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { HashRouter, Navigate, Route, Routes } from "react-router-dom";
|
||||||
import TrendingPage from "./pages/trending";
|
import TrendingPage from "./pages/trending";
|
||||||
import { NavbarComponent } from "./components/navbar";
|
import { NavbarComponent } from "./components/navbar";
|
||||||
import ChannelPage from "./pages/channel";
|
import ChannelPage from "./pages/channel";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -12,9 +13,14 @@ declare global {
|
||||||
}
|
}
|
||||||
function App() {
|
function App() {
|
||||||
window.piped_api = new PipedAPI();
|
window.piped_api = new PipedAPI();
|
||||||
|
const [key, setKey] = useState(Math.random());
|
||||||
|
|
||||||
|
window.addEventListener("reRenderPage", () => {
|
||||||
|
setKey(Math.random());
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HashRouter>
|
<HashRouter key={key}>
|
||||||
<NavbarComponent />
|
<NavbarComponent />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Navigate to="/trending" />} />
|
<Route path="/" element={<Navigate to="/trending" />} />
|
||||||
|
|
44
src/components/channel.tsx
Normal file
44
src/components/channel.tsx
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import { Avatar, Card, CardBody, CardHeader, Link } from "@nextui-org/react";
|
||||||
|
import { Channel } from "piped-api/dist/types";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { CheckCircleIcon } from "@heroicons/react/24/solid";
|
||||||
|
import { shortenNumber } from "./utils";
|
||||||
|
export function ChannelComponent({
|
||||||
|
channel,
|
||||||
|
uploaderAvatar,
|
||||||
|
}: ChannelComponentProps) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
isPressable
|
||||||
|
onPress={() => {
|
||||||
|
navigate(channel.url || "");
|
||||||
|
}}
|
||||||
|
shadow="none"
|
||||||
|
>
|
||||||
|
<CardHeader>
|
||||||
|
<Avatar
|
||||||
|
className="flex-none"
|
||||||
|
src={uploaderAvatar ? uploaderAvatar : channel.thumbnail}
|
||||||
|
/>
|
||||||
|
<Link color="foreground" className="pl-4" href={`#${channel.url}`}>
|
||||||
|
<div className="flex flex-row items-center">
|
||||||
|
<p className="text-md">{channel.name}</p>
|
||||||
|
{channel.verified && <CheckCircleIcon className="w-6 h-6 p-1" />}
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</CardHeader>
|
||||||
|
<CardBody className="flex gap-3 flex-row">
|
||||||
|
<p className="flex-none text-md">
|
||||||
|
{`${shortenNumber(channel.videos || -1)} videos`}
|
||||||
|
</p>
|
||||||
|
</CardBody>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChannelComponentProps = {
|
||||||
|
channel: Channel;
|
||||||
|
uploaderAvatar?: string;
|
||||||
|
};
|
|
@ -20,3 +20,7 @@ export function getTheme() {
|
||||||
return "light";
|
return "light";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function reRenderPage() {
|
||||||
|
window.dispatchEvent(new Event("reRenderPage"));
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { capitalize } from "../components/utils";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { PlaylistComponent } from "../components/playlist";
|
import { PlaylistComponent } from "../components/playlist";
|
||||||
import { CheckCircleIcon } from "@heroicons/react/24/solid";
|
import { CheckCircleIcon } from "@heroicons/react/24/solid";
|
||||||
|
import { ChannelComponent } from "../components/channel";
|
||||||
|
|
||||||
export default function ChannelPage() {
|
export default function ChannelPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
@ -58,11 +59,20 @@ class ChannelPageСomponent extends React.Component<
|
||||||
this.setState({ channel, tab });
|
this.setState({ channel, tab });
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
async updateChannel() {
|
||||||
if (!this.state.tab) {
|
const channel = (await window.piped_api.channel(
|
||||||
this.updateTab();
|
this.props.id || ""
|
||||||
|
)) as Channel;
|
||||||
|
|
||||||
|
this.setState({ ...this.state, channel });
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidUpdate() {
|
||||||
|
if (this.props.id !== this.state?.channel?.id) {
|
||||||
|
await this.updateChannel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.state) {
|
if (!this.state) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -111,13 +121,10 @@ class ChannelPageСomponent extends React.Component<
|
||||||
{channel.tabs.map((tab, index) => {
|
{channel.tabs.map((tab, index) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
setSearchParams({ tabId: String(index) });
|
await setSearchParams({ tabId: String(index) });
|
||||||
|
|
||||||
this.setState({
|
await this.updateTab();
|
||||||
...this.state,
|
|
||||||
tab: undefined,
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
key={tab.name}
|
key={tab.name}
|
||||||
className="text-xl font-bold mt-4"
|
className="text-xl font-bold mt-4"
|
||||||
|
@ -151,7 +158,7 @@ class ChannelPageСomponent extends React.Component<
|
||||||
);
|
);
|
||||||
} else if (item.type === "channel") {
|
} else if (item.type === "channel") {
|
||||||
item = item as Channel;
|
item = item as Channel;
|
||||||
return <div>Soon...</div>;
|
return <ChannelComponent key={item.url} channel={item} />;
|
||||||
} else {
|
} else {
|
||||||
<div className="" key={Math.random()}>
|
<div className="" key={Math.random()}>
|
||||||
Idk how to render this
|
Idk how to render this
|
||||||
|
|
Loading…
Add table
Reference in a new issue