-
Notifications
You must be signed in to change notification settings - Fork 2
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
15c6139
commit bab329e
Showing
45 changed files
with
2,179 additions
and
375 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react' | ||
import { redirect } from "next/navigation"; | ||
import { currentUser } from "@clerk/nextjs"; | ||
|
||
import { fetchUser } from "@/lib/actions/user.actions"; | ||
import { fetchPostById } from "@/lib/actions/post.actions"; | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import EditPost from '@/components/cards/EditPost'; | ||
|
||
const page = async ({ params }: { params: { id: string } }) => { | ||
|
||
if (!params.id) return null; | ||
|
||
const user = await currentUser(); | ||
if (!user) return null; | ||
|
||
const userInfo = await fetchUser(user.id); | ||
if (!userInfo?.onboarded) redirect("/onboarding"); | ||
|
||
const post = await fetchPostById(params.id); | ||
|
||
if(user.id !== post.author_id) | ||
{ | ||
redirect("/") | ||
} | ||
|
||
if(!post) | ||
{ | ||
return( | ||
<section className="pt-16 flex flex-col justify-center items-center"> | ||
<div className="mb-8"> | ||
<Image src={"/assets/error.jpg"} alt="Error" width={300} height={300} className="rounded-xl"/> | ||
</div> | ||
<h1 className="text-heading3-bold mb-4">Post Not Found</h1> | ||
<p className="text-body-bold text-gray-600 mb-8">The post you are looking for does not exist or was deleted.</p> | ||
<Link href={"/"} className="bg-primary-500 text-white px-4 py-2.5 rounded-xl hover:bg-cyan-400 hover:underline hover:text-blue"> | ||
Home | ||
</Link> | ||
</section> | ||
|
||
) | ||
} | ||
|
||
return ( | ||
<section className='relative'> | ||
<h1 className='text-center text-heading3-bold mb-4'>Edit Post</h1> | ||
|
||
<EditPost | ||
key={post.idpost} | ||
id={post.idpost} | ||
currentUserId={user.id} | ||
parentId={post.parent_id} | ||
content={post.content} | ||
createdAt={post.created_at} | ||
|
||
image={post.author.image} | ||
username={post.author.username} | ||
authorId={post.author_id} | ||
contentImage={post.image} | ||
title={post.title} | ||
prompt={post.prompt} | ||
userId={user.id} | ||
/> | ||
|
||
|
||
|
||
</section> | ||
) | ||
} | ||
|
||
export default page |
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,68 @@ | ||
import Post from '@/components/cards/Post'; | ||
import Pagination from '@/components/shared/Pagination'; | ||
import Searchbar from '@/components/shared/Searchbar'; | ||
import { searchPosts } from '@/lib/actions/post.actions'; | ||
import { fetchUser } from '@/lib/actions/user.actions'; | ||
import { currentUser } from '@clerk/nextjs'; | ||
import { redirect } from 'next/navigation'; | ||
import React from 'react' | ||
|
||
const page = async ( | ||
{ | ||
searchParams, | ||
}: { | ||
searchParams: { [key: string]: string | undefined }; | ||
} | ||
) => { | ||
|
||
const user = await currentUser(); | ||
if (!user) return null; | ||
|
||
|
||
const userInfo = await fetchUser(user.id); | ||
if (!userInfo?.onboarded) redirect("/onboarding"); | ||
|
||
const searchQuery = searchParams.q; | ||
const pageNumber = searchParams?.page ? +searchParams.page : 1; | ||
const pageSize = 6; | ||
|
||
const result = await searchPosts({ searchQuery, pageNumber, pageSize }); | ||
|
||
return ( | ||
<> | ||
<h1 className='head-text text-left text-black mb-4'>Search for Posts...</h1> | ||
<Searchbar routeType='search-post' /> | ||
<section className='mt-9 flex flex-col gap-10'> | ||
{result.results?.length === 0 ? ( | ||
<p className='no-result'>No posts found</p> | ||
) : ( | ||
<> | ||
|
||
{result.results.map((post: any) => ( | ||
<Post | ||
key={post.idpost} | ||
id={post.idpost} | ||
currentUserId={user.id} | ||
parentId={post.parent_Id} | ||
content={post.content} | ||
createdAt={post.created_at} | ||
comments={post.children} | ||
image={post.author_image} | ||
contentImage={post.image} | ||
username={post.author_username} | ||
likes = {post.likes? post.likes: ''} | ||
authorId = {post.author_id} | ||
title={post.title} | ||
prompt={post.prompt} | ||
/> | ||
))} | ||
|
||
</> | ||
)} | ||
</section> | ||
|
||
</> | ||
) | ||
} | ||
|
||
export default page |
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
Oops, something went wrong.