Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed May 27, 2024
1 parent f5aa5fa commit 7acb4e4
Show file tree
Hide file tree
Showing 50 changed files with 422 additions and 117 deletions.
1 change: 1 addition & 0 deletions src/api/player/VideoPlayerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const VideoPlayerProvider = ({
const videoElement = useMemo(() => {
let el = document.createElement("video");
el.autoplay = true;
el.crossOrigin = "anonymous";
el.style.width = "100%";
el.style.height = "100%";
return el;
Expand Down
26 changes: 26 additions & 0 deletions src/api/pref/History.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useLocalStorage } from "@mantine/hooks";
import { usePreference } from "./Preferences";

export type HistoryItem = {
t: "v" | "s",
d: string,
};

export const useNekoTubeHistory = () => {
const useLocalHistory = usePreference("useLocalHistory");
const [value, setValue] = useLocalStorage<HistoryItem[]>({
key: "nekotube:history",
defaultValue: [],
});

return {
history: value,
setHistory: setValue,
add: (item: HistoryItem) => {
if(!useLocalHistory) return;

setValue(v => [...v, item]);
},
clear: () => setValue([]),
};
};
2 changes: 2 additions & 0 deletions src/api/pref/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Preferences {
useSponsorBlock: boolean;
useDeArrow: boolean;
useReturnYoutubeDislike: boolean;
useLocalHistory: boolean;
autoplay: boolean;
};

Expand All @@ -20,6 +21,7 @@ export const DefaultPreferences: Preferences = {
useSponsorBlock: true,
useDeArrow: false,
useReturnYoutubeDislike: true,
useLocalHistory: true,
autoplay: true,
};

Expand Down
1 change: 0 additions & 1 deletion src/components/cards/ChannelCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const ChannelCard = ({
src={(channel.thumbnails || [])[(channel.thumbnails || []).length]?.url || ``}
imageProps={{ loading: "lazy" }}
size="sm"
color="violet"
>
{getInitials(channel.title)}
</Avatar>
Expand Down
15 changes: 12 additions & 3 deletions src/components/cards/CommentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ActionIcon, Box, CopyButton, Grid, Group, Paper, Stack, Tooltip } from "@mantine/core";
import { ActionIcon, Box, Button, CopyButton, Grid, Group, Paper, Stack, Tooltip } from "@mantine/core";
import { Comment } from "../../api/types/comment";
import { MarkdownText } from "../ui/MarkdownText";
import { ChannelCard } from "./ChannelCard";
import { VotingCard } from "./VotingCard";
import { IconCopy, IconPencil, IconPinned, IconTableImport, IconTableOff } from "@tabler/icons-react";
import { IconArrowDown, IconCopy, IconPencil, IconPinned, IconTableImport, IconTableOff } from "@tabler/icons-react";
import { parseChapters } from "../../utils/parseChapters";
import { useContext } from "react";
import { VideoPlayerContext } from "../../api/player/VideoPlayerContext";
Expand Down Expand Up @@ -54,10 +54,19 @@ export const CommentCard = ({
/>
</Box>
<Group justify="space-between">
<Group>
<Group gap="xs">
<VotingCard
{...comment}
/>
{comment.replyKey && (
<Button
variant="subtle"
size="compact-md"
leftSection={<IconArrowDown />}
>
{comment.replyCount} replies
</Button>
)}
</Group>
<Group>
{hasChapters && (
Expand Down
2 changes: 0 additions & 2 deletions src/components/cards/VotingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const VotingCard = ({
<Button
leftSection={<IconThumbUp />}
variant="subtle"
color="violet"
size="compact-md"
>
{likeCount}
Expand All @@ -24,7 +23,6 @@ export const VotingCard = ({
<Button
leftSection={<IconThumbDown />}
variant="subtle"
color="violet"
size="compact-md"
>
{dislikeCount}
Expand Down
88 changes: 88 additions & 0 deletions src/components/extra/Spectrum.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// yippieee

import { Box, BoxProps } from "@mantine/core";
import { useCanvas } from "../../utils/useCanvas";
import { useContext, useEffect, useMemo, useRef } from "react";
import { VideoPlayerContext } from "../../api/player/VideoPlayerContext";

const RAINBOW = [ "#ef5350", "#f48fb1", "#7e57c2", "#2196f3", "#26c6da", "#43a047", "#eeff41", "#f9a825", "#ff5722" ];

export const Spectrum = (props: BoxProps) => {
const { videoElement } = useContext(VideoPlayerContext);

const audioContextRef = useRef<AudioContext>();
const analyserRef = useRef<AnalyserNode>();

useEffect(() => {
(async () => {
if(audioContextRef.current) {
await audioContextRef.current.close();
}

audioContextRef.current = new AudioContext();
let source = audioContextRef.current.createMediaElementSource(videoElement);
let analyser = audioContextRef.current.createAnalyser();

analyser.fftSize = 2048 * 2;

source.connect(analyser);
source.connect(audioContextRef.current.destination);

analyserRef.current = analyser;
})();
}, [videoElement]);

const bufferLength = analyserRef.current?.frequencyBinCount || 0;
const dataArray = new Uint8Array(bufferLength);
let gradientOffset = 0;

const ref = useCanvas((ctx, dt) => {
if(!analyserRef.current) return;

analyserRef.current.getByteFrequencyData(dataArray);

if(gradientOffset > ctx.canvas.width / 2) gradientOffset = 0;

const gradient = ctx.createLinearGradient(
(ctx.canvas.width * -0.5) + gradientOffset,
0,
(ctx.canvas.width * 1.5) + gradientOffset,
0
);
RAINBOW.forEach((c, i, a) => gradient.addColorStop((i / (a.length-1)) / 2, c));
RAINBOW.forEach((c, i, a) => gradient.addColorStop((i / (a.length-1) / 2 + 0.5), c));

gradientOffset += 15;

ctx.fillStyle = "black";
ctx.strokeStyle = gradient;
ctx.lineWidth = 2;

ctx.beginPath();
ctx.moveTo(0, ctx.canvas.height);

let scale = (Math.log(bufferLength) / ctx.canvas.width);
for (let i = 1; i < bufferLength; i++) {
let x = Math.log(i) / scale;
const v = dataArray[i] / 256;
const y = v * v * v* (ctx.canvas.height);

ctx.lineTo(x, ctx.canvas.height - y);
}

ctx.lineTo(ctx.canvas.width, ctx.canvas.height);
ctx.stroke();
}, [analyserRef.current]);

return (
<Box {...props}>
<canvas
style={{
width: "100%",
height: "100%",
}}
ref={ref}
/>
</Box>
);
};
1 change: 0 additions & 1 deletion src/components/options/OptionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const OptionsProvider = ({ children }: React.PropsWithChildren) => {
{view !== "main" && (
<Button
variant="light"
color="violet"
leftSection={<IconArrowLeft />}
onClick={() => setView("main")}
fullWidth
Expand Down
3 changes: 1 addition & 2 deletions src/components/options/comps/DebuggingSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const DebuggingSection = () => {
{({ copied, copy }) => (
<Button
variant="light"
color={copied ? "green" : "violet"}
color={copied ? "green" : undefined}
onClick={() => copy()}
fullWidth
>
Expand All @@ -21,7 +21,6 @@ export const DebuggingSection = () => {
</CopyButton>
<Button
variant="light"
color="violet"
onClick={() => fetchVideoInfo()}
fullWidth
>
Expand Down
1 change: 0 additions & 1 deletion src/components/options/comps/FormatSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const FormatSelect = () => {
<UnstyledButton
className="hoverable"
variant="subtle"
color="violet"
onClick={() => setView("formatSelect")}
>
{activeFormat ? (
Expand Down
1 change: 0 additions & 1 deletion src/components/options/comps/InstanceSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const InstanceSelect = () => {
<UnstyledButton
className="hoverable"
variant="subtle"
color="violet"
onClick={() => setView("instanceSelect")}
>
<Grid align="center" m="sm">
Expand Down
35 changes: 35 additions & 0 deletions src/components/options/comps/ThemeSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ColorPicker, ColorSwatch, LoadingOverlay, SimpleGrid, Stack, Tooltip, useMantineTheme } from "@mantine/core";
import { useColorScheme } from "@mantine/hooks";
import { IconCheck } from "@tabler/icons-react";
import { useContext, useEffect, useState } from "react";
import { ThemeContext } from "../../../theme";

export const ThemeSection = () => {
const { primaryColor, setPrimaryColor } = useContext(ThemeContext);
const theme = useMantineTheme();
const shade = 8;

return (
<Stack w="100%">
<SimpleGrid cols={7}>
{Object.keys(theme.colors).map((color) => (
<Tooltip
key={color}
withArrow
label={(
color[0].toUpperCase() + color.slice(1) + (primaryColor == color ? " (Active)" : "")
)}>
<ColorSwatch
color={theme.colors[color][shade]}
onClick={() => {
setPrimaryColor(color);
}}
>
{primaryColor == color && <IconCheck />}
</ColorSwatch>
</Tooltip>
))}
</SimpleGrid>
</Stack>
);
};
1 change: 0 additions & 1 deletion src/components/options/links/ChangeInstanceButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const ChangeInstanceButton = () => {

return (
<Button
color="violet"
variant="light"
leftSection={<IconSettings />}
onClick={() => {
Expand Down
1 change: 0 additions & 1 deletion src/components/options/links/FormatsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const FormatsButton = () => {
<Tooltip label="Select Format">
<ActionIcon
variant="light"
color="violet"
onClick={() => {
open();
setView("formatSelect");
Expand Down
1 change: 0 additions & 1 deletion src/components/options/links/OpenWithButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const OpenWithButton = (props: ButtonProps) => {

return (
<Button
color="violet"
variant="light"
rightSection={<IconExternalLink />}
onClick={() => {
Expand Down
1 change: 0 additions & 1 deletion src/components/options/links/OptionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const OptionsButton = () => {
<Tooltip label="Options (o)">
<ActionIcon
variant="light"
color="violet"
onClick={() => open()}
>
<IconSettings />
Expand Down
1 change: 0 additions & 1 deletion src/components/options/views/InstanceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ const InstanceSearch = ({
<Tooltip label="Refresh public instances">
<ActionIcon
variant="light"
color="violet"
onClick={() => refreshAvailableInstances()}
>
<IconReload />
Expand Down
3 changes: 3 additions & 0 deletions src/components/options/views/MainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PreferencesList } from "../comps/PreferencesList";
import { DebuggingSection } from "../comps/DebuggingSection";
import { OpenWithButton } from "../links/OpenWithButton";
import { LoopVideo } from "../comps/LoopVideo";
import { ThemeSection } from "../comps/ThemeSection";

export const OptionsMainView = () => {
const { videoInfo } = useContext(VideoPlayerContext);
Expand All @@ -30,6 +31,8 @@ export const OptionsMainView = () => {
{loaded && <LoopVideo />}
<Divider w="100%" label="Preferences" labelPosition="left" />
<PreferencesList />
<Divider w="100%" label="Theme" labelPosition="left" />
<ThemeSection />
<Divider w="100%" label="Debugging" labelPosition="left" />
<DebuggingSection />
<Space h="20vh" />
Expand Down
12 changes: 6 additions & 6 deletions src/components/player/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { VideoPlayerContext } from "../../api/player/VideoPlayerContext"
import { Box, Stack, Transition } from "@mantine/core";
import { useDebouncedCallback, useHotkeys, useHover, useMergedRef } from "@mantine/hooks";
import { usePreference } from "../../api/pref/Preferences";
import { LayoutTop } from "./layout/LayoutTop";
import { LayoutMiddle } from "./layout/LayoutMiddle";
import { LayoutBottom } from "./layout/LayoutBottom";
import { PlayerLayoutTop } from "./layout/LayoutTop";
import { PlayerLayoutMiddle } from "./layout/LayoutMiddle";
import { PlayerLayoutBottom } from "./layout/LayoutBottom";
import { useIsMobile } from "../../hooks/useIsMobile";

export const VideoPlayer = () => {
Expand Down Expand Up @@ -117,10 +117,10 @@ export const VideoPlayer = () => {
}}
className="clickListener"
>
<LayoutTop />
<LayoutMiddle />
<PlayerLayoutTop />
<PlayerLayoutMiddle />
<div ref={ref}>
<LayoutBottom />
<PlayerLayoutBottom />
</div>
</Stack>
)}
Expand Down
1 change: 0 additions & 1 deletion src/components/player/controls/FullscreenButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const FullscreenButton = () => {
<ActionIcon
onClick={() => toggle()}
variant="light"
color="violet"
>
{fullscreen ? (
<IconMinimize />
Expand Down
1 change: 0 additions & 1 deletion src/components/player/controls/PlayPauseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const PlayPauseButton = () => {
<ActionIcon
onClick={() => togglePlay()}
variant="light"
color="violet"
>
{playing ? (
<IconPlayerPause />
Expand Down
Loading

0 comments on commit 7acb4e4

Please sign in to comment.