Skip to content
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

Added Searchbar in FAQ's and fixed the Navbar issue- Unexpected Navbar #182

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
115 changes: 71 additions & 44 deletions app/faq/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import Link from "next/link";
import { useTheme } from "next-themes";
import Link from "next/link";
import { useEffect, useState } from "react";
import NavbarComponent from "../front-navbar";

const faqs = [
Expand Down Expand Up @@ -57,6 +57,7 @@ const FAQ = () => {
const { systemTheme, theme } = useTheme();
const currentTheme = theme === "dark" ? systemTheme : theme;
const [darkMode, setDarkMode] = useState(false);
const [searchTerm, setSearchTerm] = useState("");

useEffect(() => {
setDarkMode(currentTheme === 'dark');
Expand All @@ -66,6 +67,12 @@ const FAQ = () => {
setActiveIndex(index === activeIndex ? null : index);
};

// Filter FAQs based on search term
const filteredFaqs = faqs.filter((faq) =>
faq.question.toLowerCase().includes(searchTerm.toLowerCase()) ||
faq.answer.toLowerCase().includes(searchTerm.toLowerCase())
);

return (
<div
className={`min-h-screen ${
Expand Down Expand Up @@ -96,50 +103,70 @@ const FAQ = () => {
>
Frequently Asked Questions
</h1>

{/* Search Bar */}
<div className="mb-8 text-center">
<input
type="text"
placeholder="Search FAQs..."
className={`w-full max-w-lg p-3 rounded-md transition-colors duration-300 ${
darkMode ? "bg-gray-800 text-white" : "bg-gray-100 text-black"
}`}
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
</div>

<div className="space-y-6 max-w-3xl mx-auto">
{faqs.map((faq, index) => (
<div
key={index}
className={`p-4 rounded-lg transition duration-300 cursor-pointer shadow-md ${
darkMode
? "bg-gray-800 hover:bg-gray-700"
: "bg-gray-100 hover:bg-gray-200"
}`}
onClick={() => toggleFAQ(index)}
>
<div className="flex justify-between items-center">
<h2
className={`font-semibold text-lg transition-colors duration-300 ${
activeIndex === index
? darkMode
? "text-white"
: "text-gray-800"
: darkMode
? "text-gray-400"
: "text-gray-600"
}`}
>
{faq.question}
</h2>
<span
className={`transition-transform duration-300 ${
darkMode ? "text-gray-400" : "text-gray-600"
} ${activeIndex === index ? "rotate-180" : "rotate-0"}`}
>
</span>
{filteredFaqs.length > 0 ? (
filteredFaqs.map((faq, index) => (
<div
key={index}
className={`p-4 rounded-lg transition duration-300 cursor-pointer shadow-md ${
darkMode
? "bg-gray-800 hover:bg-gray-700"
: "bg-gray-100 hover:bg-gray-200"
}`}
onClick={() => toggleFAQ(index)}
>
<div className="flex justify-between items-center">
<h2
className={`font-semibold text-lg transition-colors duration-300 ${
activeIndex === index
? darkMode
? "text-white"
: "text-gray-800"
: darkMode
? "text-gray-400"
: "text-gray-600"
}`}
>
{faq.question}
</h2>
<span
className={`transition-transform duration-300 ${
darkMode ? "text-gray-400" : "text-gray-600"
} ${activeIndex === index ? "rotate-180" : "rotate-0"}`}
>
</span>
</div>
{activeIndex === index && (
<p
className={`mt-4 transition-all duration-300 ${
darkMode ? "text-gray-300" : "text-gray-700"
}`}
>
{faq.answer}
</p>
)}
</div>
{activeIndex === index && (
<p
className={`mt-4 transition-all duration-300 ${
darkMode ? "text-gray-300" : "text-gray-700"
}`}
>
{faq.answer}
</p>
)}
</div>
))}
))
) : (
<p className={`text-center ${darkMode ? "text-white" : "text-black"}`}>
No FAQs match your search.
</p>
)}
</div>
</div>
</div>
Expand Down