Skip to content

Commit

Permalink
feat/search: Added search bar and other minor ui fix (#1176)
Browse files Browse the repository at this point in the history
* feat/search: Added search bar and other minor ui fix

* feat/search: Fixed search api result

* feat/search: minor fix

* Update Sidebar.tsx

tried the GUI conflict resolver xD

* Update Sidebar.tsx
  • Loading branch information
ItsFlash10 authored Oct 4, 2024
1 parent caef998 commit 700e6b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/app/api/search/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import db from '@/db';
import { CourseContent } from '@prisma/client';
import Fuse from 'fuse.js';
import { NextRequest, NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';

export type TSearchedVideos = {
id: number;
Expand All @@ -24,6 +26,7 @@ const fuzzySearch = (videos: TSearchedVideos[], searchQuery: string) => {
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const searchQuery = searchParams.get('q');
const session = await getServerSession(authOptions);

if (searchQuery && searchQuery.length > 2) {
const value: TSearchedVideos[] = await cache.get(
Expand All @@ -39,6 +42,19 @@ export async function GET(request: NextRequest) {
where: {
type: 'video',
hidden: false,
parent: {
courses: {
some: {
course: {
purchasedBy: {
some: {
userId: session?.user?.id,
},
},
},
},
},
},
},
select: {
id: true,
Expand Down
6 changes: 5 additions & 1 deletion src/app/courses/[courseId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { QueryParams } from '@/actions/types';
import SearchBar from '@/components/search/SearchBar';
import { Sidebar } from '@/components/Sidebar';
import { getFullCourseContent } from '@/db/course';
import { authOptions } from '@/lib/auth';
Expand Down Expand Up @@ -49,7 +50,10 @@ const Layout = async ({

return (
<div className="relative flex min-h-screen flex-col py-24">
<Sidebar fullCourseContent={fullCourseContent} courseId={courseId} />
<div className="flex justify-between gap-8">
<SearchBar />
<Sidebar fullCourseContent={fullCourseContent} courseId={courseId} />
</div>
{children}
</div>
);
Expand Down

0 comments on commit 700e6b1

Please sign in to comment.