Skip to content

Commit 93dd099

Browse files
committed
Some errors are resolved
1 parent f64e2cf commit 93dd099

File tree

11 files changed

+666
-589
lines changed

11 files changed

+666
-589
lines changed

Diff for: app/(profile)/create-post/[[...blogid]]/page.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ const placeholderValues: placeholderValuesType = {
3030
blogTags: []
3131
}
3232

33-
const CreateBlog = ({params}:{params:{blogid:string}}) => {
33+
type CreateBlogProps = {
34+
params: Promise<{
35+
blogid?: string | string[] | undefined;
36+
}>;
37+
};
38+
39+
const CreateBlog = ({ params }: CreateBlogProps) => {
3440
const [loading, setLoading] = useState<boolean>(false);
3541
const [selectedTags, setSelectedTags] = useState<string[]>([]);
3642
const [action, setAction] = useState<string>('');
@@ -41,17 +47,17 @@ const CreateBlog = ({params}:{params:{blogid:string}}) => {
4147
const [blogid, setBlogid] = useState<string | null>(null);
4248

4349
useEffect(() => {
44-
const fetchBlogId = async () => {
45-
46-
const resolvedBlogId = await params.blogid[0] ;
47-
console.log(resolvedBlogId);
48-
49-
setBlogid(resolvedBlogId);
50+
const resolveParams = async () => {
51+
const resolvedParams = await params;
52+
const resolvedBlogId = Array.isArray(resolvedParams.blogid)
53+
? resolvedParams.blogid[0]
54+
: resolvedParams.blogid;
55+
setBlogid(resolvedBlogId || null);
5056
};
5157

52-
fetchBlogId();
53-
}, [params]);
54-
// const blogid = params.blogid?.[0];
58+
resolveParams();
59+
}, [params]);
60+
5561
const [state, formAction] = useActionState(blogid ? UpdatePost : CreatePost, initialState);
5662

5763
useEffect(() => {

Diff for: app/(profile)/dashboard/page.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Image from 'next/image';
21
import { FetchBlog } from '@/utils/profileActions';
32
import { format } from 'date-fns';
43
import DeleteBlogBtn from '@/components/DeleteBlogBtn';
@@ -57,7 +56,7 @@ const Dashboard = async() => {
5756
<td className="tableBorder px-4 py-2">
5857
<div className="flex gap-4 items-center text-sm">
5958
<div className="w-8 h-8">
60-
<Image
59+
<img
6160
src={blog.blogCover}
6261
alt="Blog Image"
6362
width={40}

Diff for: app/blog/[id]/page.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { getBlog } from '@/utils/getBlog';
22
import Image from 'next/image';
33
import { notFound } from 'next/navigation';
44

5-
const ReadBlog = async ({params}:{params:{id:string}}) => {
5+
interface ReadBlogProps {
6+
params: Promise<{
7+
id: string;
8+
}>
9+
}
10+
11+
const ReadBlog = async ({ params }: ReadBlogProps) => {
612
const {id} = await params;
713
const blog = await getBlog(id);
814

Diff for: components/AllBlogs.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Blog } from "@/utils/types";
44

55
const AllBlogs = ({allBlogs}:{allBlogs:Blog[]}) => {
66
return (
7-
<div className="w-11/12 mx-auto max-w-7xl mt-16 mb-20 sm:mt-8">
7+
<div className="w-11/12 mx-auto max-w-7xl mt-8 sm:mt-0 mb-20">
88
<h1 className="text-xl mb-4">All blog posts</h1>
99
<div className="grid gap-5 sm:grid-cols-2 md:grid-cols-3">
1010
{

Diff for: components/SingleCard.tsx

+2-65
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,3 @@
1-
// import Image from "next/image"
2-
// import Link from "next/link"
3-
// import Tags from "@/components/Tags"
4-
// import { format } from 'date-fns';
5-
// import { MdOutlineArrowOutward } from "react-icons/md";
6-
7-
// interface User {
8-
// firstName: string;
9-
// lastName: string;
10-
// }
11-
12-
// interface Tag {
13-
// id: string;
14-
// name: string;
15-
// }
16-
17-
// interface BlogTag {
18-
// id: string;
19-
// tagId: string;
20-
// blogId: string;
21-
// tag: Tag; // Add the nested tag structure
22-
// }
23-
24-
// interface Blog {
25-
// id: string;
26-
// blogName: string;
27-
// hook: string;
28-
// blogCover: string;
29-
// blogCoverPublicId?: string | null;
30-
// desc: string;
31-
// status: boolean;
32-
// createdAt: Date;
33-
// updatedAt?: Date;
34-
// userId: string;
35-
// user: User;
36-
// blogTags: BlogTag[];
37-
// }
38-
39-
// const SingleCard = ({blog}:{blog:Blog}) => {
40-
41-
// return (
42-
// <Link href={`/blog/${20}`}>
43-
// <div className="w-full mb-4">
44-
// <Image src={`${blog?.blogCover}`} className="w-full h-full object-cover" width={800} height={300} alt="blog 1"/>
45-
// </div>
46-
// <div>
47-
// <p className="para text-xs">{blog?.user?.firstName}&nbsp;{blog?.user?.lastName}+{format(new Date(blog?.createdAt), 'dd MMM yyyy')}</p>
48-
// <div className="flex justify-between my-2">
49-
// <h1 className="truncate text-xl font-bold w-4/5" title={`${blog?.blogName}`}>{blog?.blogName}</h1>
50-
// <span className="text-2xl font-extrabold"><MdOutlineArrowOutward /></span>
51-
// </div>
52-
// <p className="text-xs cardPara mb-4">{blog?.hook}</p>
53-
// <Tags tags={blog.blogTags} />
54-
55-
// </div>
56-
// </Link>
57-
// )
58-
// }
59-
60-
// export default SingleCard
61-
62-
63-
import Image from "next/image";
641
import Link from "next/link";
652
import Tags from "@/components/Tags";
663
import { format, isValid } from "date-fns";
@@ -89,9 +26,9 @@ const SingleCard = ({ blog }: { blog: Blog }) => {
8926
return (
9027
<Link href={`/blog/${blog?.id}`} className="w-full grid grid-cols-6 gap-2 h-auto max-w-full">
9128
<div className="w-full overflow-hidden col-span-6">
92-
<Image
29+
<img
9330
src={imageSrc}
94-
className="w-full h-full object-cover"
31+
className="w-full h-full object-cover max-h-96"
9532
width={800}
9633
height={300}
9734
alt={`${blog?.blogName}`}

Diff for: components/verticalCard.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Image from "next/image"
21
import Link from "next/link"
32
import Tags from "@/components/Tags"
43
import { format, isValid } from "date-fns";
@@ -25,13 +24,12 @@ const VerticalCard = ({blog}:{blog:Blog}) => {
2524
<div className="w-full">
2625
<Link href={`/blog/${blog?.id}`} className="w-full grid grid-cols-6 gap-2 h-40">
2726
<div className="w-full overflow-y-hidden mb-4 col-span-2">
28-
<Image
27+
<img
2928
src={imageSrc}
3029
className="w-full h-full object-cover"
3130
width={800}
3231
height={300}
3332
alt={`${blog?.blogName}`}
34-
priority
3533
/>
3634
</div>
3735
<div className="col-span-4">

Diff for: next.config.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NextConfig } from "next";
33
const nextConfig: NextConfig = {
44
experimental: {
55
serverActions: {
6-
bodySizeLimit: "1000mb",
6+
bodySizeLimit: "1000mb", // Set body size limit for server actions
77
},
88
},
99
images: {
@@ -17,8 +17,21 @@ const nextConfig: NextConfig = {
1717
hostname: "images.unsplash.com",
1818
},
1919
],
20+
minimumCacheTTL: 60, // Cache images for at least 60 seconds
21+
},
22+
async headers() {
23+
return [
24+
{
25+
source: "/_next/image",
26+
headers: [
27+
{
28+
key: "Cache-Control",
29+
value: "public, max-age=31536000, immutable", // Cache image optimizations
30+
},
31+
],
32+
},
33+
];
2034
},
21-
/* other config options here */
2235
};
2336

2437
export default nextConfig;

0 commit comments

Comments
 (0)