Skip to content

fixed bug: search feature is not working as expected #1811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/VideoPlayer2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ export const VideoPlayer: FunctionComponent<VideoPlayerProps> = ({
};
const handleKeyUp = (event: any) => {
if (event.code === 'KeyT') {
player.playbackRate(1);
player?.playbackRate(1);
}
};
document.addEventListener('keydown', handleKeyPress, { capture: true });
Expand Down
35 changes: 21 additions & 14 deletions src/components/search/CommandMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,25 @@ export function CommandMenu({
},
[open, handleShortcut],
);
useEffect(() => {
console.log('Searched Videos Updated:', searchedVideos);
}, [searchedVideos]);

useEffect(() => {
document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener('keydown', handleKeyDown);
}, [handleKeyDown]);

// Function to handle video selection
const handleVideoSelect = (video: TSearchedVideos) => {
if (video.parentId && video.parent?.courses.length) {
const courseId = video.parent.courses[0].courseId
const videoUrl = `/courses/${courseId}/${video.parentId}/${video.id}`
onCardClick(videoUrl)
onClose()
}
}

return (
<CommandDialog open={open} onOpenChange={onOpenChange}>
<CommandInput
Expand All @@ -102,27 +115,21 @@ export function CommandMenu({
<CommandEmpty>No results found.</CommandEmpty>

<CommandGroup heading="Videos">
{!loading &&
searchedVideos &&
searchedVideos.length > 0 &&
{loading ? (
<CommandItem disabled>Loading videos...</CommandItem>
) : searchedVideos && searchedVideos.length > 0 ? (
searchedVideos.map((video) => (
<CommandItem
key={video.id}
onSelect={() => {
if (video.parentId && video.parent?.courses.length) {
const courseId = video.parent.courses[0].courseId;
const videoUrl = `/courses/${courseId}/${video.parentId}/${video.id}`;
onCardClick(videoUrl);
onClose();
}
}}
onSelect={() => handleVideoSelect(video)}
value={`video-${video.id}-${video.title}`}
>
<Play className="mr-2 h-4 w-4" />
<span className="truncate">{video.title}</span>
</CommandItem>
))}
{!loading && (!searchedVideos || searchedVideos.length === 0) && (
<CommandItem>No videos found</CommandItem>
))
) : (
<CommandItem disabled>No videos found</CommandItem>
)}
</CommandGroup>

Expand Down