+
);
diff --git a/src/components/Nav.tsx b/src/components/Nav.tsx
index c2f7acf..2c915a6 100644
--- a/src/components/Nav.tsx
+++ b/src/components/Nav.tsx
@@ -12,7 +12,9 @@ import { Button } from "@nextui-org/button";
import NextLink from "next/link";
import { usePathname } from "next/navigation";
-import { Search } from "./Search";
+// import { Search } from "./Search";
+
+export const navHeight = 64;
export const Nav: Component = () => {
const navItems = [
diff --git a/src/components/Search.tsx b/src/components/Search.tsx
index 212713b..ed7e2b2 100644
--- a/src/components/Search.tsx
+++ b/src/components/Search.tsx
@@ -4,17 +4,22 @@ import { useClient } from "@/hooks/useClient";
import { Component } from "@/typings/component";
import { Autocomplete, AutocompleteItem } from "@nextui-org/autocomplete";
import { useQuery } from "@tanstack/react-query";
-import { FormEventHandler, useState } from "react";
+import { FormEventHandler, useCallback, useMemo, useState } from "react";
import { useDebounce } from "use-debounce";
+import { FiSearch as SearchIcon } from "react-icons/fi";
+import { useRouter } from "next/navigation";
+
export const Search: Component<{ initialQueryValue?: string }> = ({
initialQueryValue
}) => {
const client = useClient();
- const [searchQuery, setSearchQuery] = useState("");
+ const [searchQuery, setSearchQuery] = useState(initialQueryValue ?? "");
+
+ const router = useRouter();
- const [searchQueryDebounced] = useDebounce(searchQuery, 500);
+ const [searchQueryDebounced] = useDebounce(searchQuery, 250);
const { isLoading, error, data } = useQuery({
queryKey: ["search", "suggestions", searchQueryDebounced],
@@ -22,29 +27,50 @@ export const Search: Component<{ initialQueryValue?: string }> = ({
enabled: searchQueryDebounced.length !== 0
});
- const handleSubmit: FormEventHandler = (e) => {
- console.log(searchQuery);
- };
+ const handleSubmit = useCallback(() => {
+ router.push(`/results?search_query=${searchQuery}`);
+ }, [searchQuery]);
- const suggestions = data ?? [];
+ const suggestions = useMemo(
+ () =>
+ data?.map((suggestion) => ({
+ label: suggestion,
+ value: suggestion
+ })) ?? [],
+ [data]
+ );
return (
-
- {suggestions.map((suggestion) => (
-
- {suggestion}
-
- ))}
-
+
);
};
diff --git a/src/components/Video.tsx b/src/components/Video.tsx
index b8d42b5..1d1ac40 100644
--- a/src/components/Video.tsx
+++ b/src/components/Video.tsx
@@ -11,9 +11,19 @@ import formatUploadedTime from "@/utils/formatUploadedTime";
import { Tooltip } from "@nextui-org/tooltip";
import { ContextMenuItem } from "@/typings/contextMenu";
-export const Video: Component<{ data: VideoProps }> = ({ data: video }) => {
- const url = `/watch?v=${video.id}`;
- const channelUrl = `/channel/${video.author.id}`;
+import NextImage from "next/image";
+import { useMemo } from "react";
+
+export const Video: Component<{ data: VideoProps }> = ({ data }) => {
+ const url = `/watch?v=${data.id}`;
+ const channelUrl = `/channel/${data.author.id}`;
+
+ const videoSize = 400;
+ const aspectRatio = 16 / 9;
+
+ const [width, height] = useMemo(() => {
+ return [videoSize * aspectRatio, videoSize];
+ }, [videoSize]);
const menuItems: ContextMenuItem[] = [
{ title: "Go to video", key: "gotoVideo", href: url },
@@ -21,20 +31,20 @@ export const Video: Component<{ data: VideoProps }> = ({ data: video }) => {
title: "Copy video id",
key: "videoId",
onClick: () => {
- navigator.clipboard.writeText(video.id);
+ navigator.clipboard.writeText(data.id);
},
showDivider: true
},
{
title: "Open thumbnail",
key: "thumbnail",
- href: video.thumbnail
+ href: data.thumbnail
},
{
title: "Copy thumnail url",
key: "thumbnailUrl",
onClick: () => {
- navigator.clipboard.writeText(video.thumbnail);
+ navigator.clipboard.writeText(data.thumbnail);
},
showDivider: true
},
@@ -43,7 +53,7 @@ export const Video: Component<{ data: VideoProps }> = ({ data: video }) => {
title: "Copy channel id",
key: "channelId",
onClick: () => {
- navigator.clipboard.writeText(video.author.id);
+ navigator.clipboard.writeText(data.author.id);
}
}
];
@@ -54,34 +64,37 @@ export const Video: Component<{ data: VideoProps }> = ({ data: video }) => {
+
- {formatDuration(video.duration)}
+ {formatDuration(data.duration)}
-
- {video.title}
+
+ {data.title}
- {video.author.name}
+ {data.author.name}
-
+
- {formatUploadedTime(video.uploaded)}
+ {formatUploadedTime(data.uploaded)}
- Views: {formatViewCount(video.views)}
+ Views: {formatViewCount(data.views)}