-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae32eca
commit c59234c
Showing
4 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
import type { Metadata } from "next"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
import Navbar from "@/components/Navbar"; | ||
import Providers from "@/components/ThemeProvider"; | ||
import { StoreProvider } from "@/store/StoreProvider"; | ||
import { Toaster } from "@/components/ui/toaster"; | ||
|
||
import { GeistSans } from 'geist/font/sans'; | ||
import { db } from "@/utils/firebase"; | ||
import { collection , getDocs, query, where } from "firebase/firestore"; | ||
|
||
type Props = { | ||
params: { | ||
postTitle: string; | ||
} | ||
} | ||
|
||
type Post = { | ||
id: string; | ||
title: string; | ||
// content: string; | ||
} | ||
|
||
const fetchPost = async (postTitle: string) => { | ||
|
||
//how to fetch the question from the firestore using postTitle | ||
const queRef = collection(db, "questions"); | ||
const q = query (queRef, where("title", "==", postTitle)); | ||
|
||
const querySnapshot = await getDocs(q); | ||
const post = querySnapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() } as Post )); | ||
console.log(post); | ||
return { post }; | ||
|
||
} | ||
|
||
export const generateMetaData = async({ params }: Props) : Promise<Metadata> => { | ||
|
||
const postTitleWithSpaces = decodeURIComponent(params.postTitle as string).split("-").join(" "); | ||
const { post }= await fetchPost(postTitleWithSpaces); | ||
|
||
|
||
const metadata: Metadata = { | ||
title: post[0].title, | ||
description: "Discover answers to your questions.", | ||
}; | ||
return metadata; | ||
} | ||
|
||
|
||
// export const metadata: Metadata = { | ||
// title: "Your Questions Answered", | ||
// description: "Get all your answers here.", | ||
// }; | ||
|
||
export default function PostPage({ | ||
children, | ||
}:{ | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
|
||
<div> | ||
<Navbar /> | ||
<div className=" "> | ||
{children} | ||
</div> | ||
</div> | ||
|
||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters