Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
auraticabhi committed Mar 26, 2024
1 parent 4f233c4 commit 7a6f2f8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
15 changes: 13 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export default function Home() {

async function createQuestionPost(data: Input) {

console.log("creating");
//console.log("creating");

const docRef = await addDoc(collection(db, "questions"), {
title: data.title,
Expand Down Expand Up @@ -384,6 +384,13 @@ export default function Home() {

}

const guestHandler = ()=>{
if(user?.isAnonymous){
auth.signOut();
router.push("/auth");
}
}

const [searchTerm , setSearchTerm] = useState("");

function transformHitToPost(hit: any) {
Expand Down Expand Up @@ -488,9 +495,13 @@ export default function Home() {

<div>
<Dialog>
{
isGuest === 'true'||user?.isAnonymous==true?
<Button variant="default" className=" w-full" onClick={guestHandler}>Ask Question</Button>:
<DialogTrigger asChild>
<Button variant="default" className=" w-full" disabled={isGuest === 'true'||user?.isAnonymous==true}>Ask Question</Button>
<Button variant="default" className=" w-full" >Ask Question</Button>
</DialogTrigger>
}
<DialogContent className="sm:max-w-[925px] max-h-[40rem] overflow-y-scroll ">
<DialogHeader>
<DialogTitle>Post Question</DialogTitle>
Expand Down
61 changes: 60 additions & 1 deletion components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ import MobileSidebar from "./MobileSidebar";

import { useToast } from "./ui/use-toast";
import { Separator } from "./ui/separator";
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "./ui/select";
import { LuXCircle } from "react-icons/lu";

type Input = z.infer<typeof QuestionType>;

Expand All @@ -112,8 +114,10 @@ const Navbar = ({}: Props) => {
//const [user, loading] = useAuthState(auth);
const [imageUpload , setImageUpload] = useState<File | null>(null);
const [imageUrl, setImageUrl] = useState<string | null>(null);
const [selectC, setSelectC] = useState<any>([]);
const [progress , setProgress] = useState<number | null>(0);
const [previewImg, setPreviewImg] = useState<any>(null);
const [selectedCategory, setSelectedCategory] = useState<string | undefined>('');

//for real-time notifications
const [notifications , setNotifications] = useState<any[]>([]);
Expand All @@ -134,6 +138,24 @@ const Navbar = ({}: Props) => {
},
});

const handleSelectChange = (newValue: string | undefined) => {
// setSelectedCategory(newValue);
if(!selectC.includes(newValue)){
setSelectC((prev:any)=>{
return [...prev, newValue]
})
}
//console.log(selectC);
};

const delCategories = (category:string)=>{
let newCategory=selectC.filter((cat:any)=>{
console.log(cat, " ", category);
return cat!=category;
})
setSelectC(newCategory);
}

const uploadImage = async(file: any) => {
if(file == null) return;

Expand Down Expand Up @@ -208,6 +230,7 @@ const Navbar = ({}: Props) => {
name: user?.displayName,
createdAt: serverTimestamp(),
questionImageURL: imageUrl,
category: selectC,
anonymity: data.anonymity,
// ansNumbers: 0,
});
Expand Down Expand Up @@ -284,6 +307,13 @@ const Navbar = ({}: Props) => {
}
}

const guestHandler = ()=>{
if(user?.isAnonymous){
auth.signOut();
router.push("/auth");
}
}

//fetching real-time notifications
useEffect(() => {
if (user) {
Expand Down Expand Up @@ -439,9 +469,13 @@ useEffect(() => {

<div>
<Dialog>
{
isGuest === 'true'||user?.isAnonymous==true?
<Button variant="outline" className=" rounded-3xl w-full" onClick={guestHandler}>Ask Question</Button>:
<DialogTrigger asChild>
<Button variant="outline" className=" rounded-3xl w-full" disabled={isGuest === 'true'}>Ask Question</Button>
<Button variant="outline" className=" rounded-3xl w-full">Ask Question</Button>
</DialogTrigger>
}
<DialogContent className="sm:max-w-[925px] max-h-[55rem] overflow-y-scroll ">
<DialogHeader>
<DialogTitle>Post Question</DialogTitle>
Expand Down Expand Up @@ -505,6 +539,31 @@ useEffect(() => {
</div>
}
</div>
<div>
<Select value={selectedCategory} onValueChange={handleSelectChange} >
<SelectTrigger className="w-full">
<SelectValue placeholder="Select a Category" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Categories</SelectLabel>
<SelectItem value="How To">How To</SelectItem>
<SelectItem value="Help">Help</SelectItem>
<SelectItem value="Mystery/Haunted/Ghost">Mystery/Haunted/Ghost</SelectItem>
<SelectItem value="Astrology/Remedies/Occult">Astrology/Remedies/Occult</SelectItem>
<SelectItem value="GemStones/Rudraksha">GemStones/Rudraksha</SelectItem>
<SelectItem value="Others">Others</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<div className="flex">
{
selectC.map((category:string, index:number)=>{
return <span className='bg-slate-300 text-slate-800 rounded-xl p-1 text-sm flex mr-1 mt-3' key={index}>{category} <span onClick={()=>{delCategories(category)}} className="mt-[0.27rem] ml-1 cursor-pointer text-slate-800 hover:text-slate-900"><LuXCircle /></span></span>
})
}
</div>
</div>
<FormField
control={form.control}
name="anonymity"
Expand Down
2 changes: 1 addition & 1 deletion components/RightHandFeed/RightHandFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const RightHandFeed = (props: Props) => {
{posts.map((post, index) => (
<TableRow key={index}>
<Link href={`/${encodeURIComponent(post?.title?.split(" ").join("-"))}`}>
<TableCell className="text-[#195FAA] text-base">{post.title}</TableCell>
<TableCell className="text-[#195FAA] text-base">{post.title.length>70?post.title.substring(0, 69)+"...":post.title}</TableCell>
</Link>
</TableRow>
))}
Expand Down

0 comments on commit 7a6f2f8

Please sign in to comment.