Skip to content

dangerouslySetInnerHtml error fixed #22

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

Open
wants to merge 1 commit into
base: starter
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {
images:{
domains:["lh3.googleusercontent.com","firebasestorage.googleapis.com"]
}
}

module.exports = nextConfig
1,220 changes: 1,219 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
"lint": "next lint"
},
"dependencies": {
"@auth/prisma-adapter": "^1.0.1",
"@prisma/client": "^5.2.0",
"eslint": "8.48.0",
"eslint-config-next": "13.4.19",
"firebase": "^10.3.0",
"next": "13.4.19",
"next-auth": "^4.23.1",
"prisma": "^5.2.0",
"react": "18.2.0",
"react-dom": "18.2.0"
"react-dom": "18.2.0",
"react-quill": "^2.0.0",
"swr": "^2.2.2"
}
}
91 changes: 91 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model Account {
id String @id @default(cuid()) @map("_id")
userId String
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String?
session_state String?

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([provider, providerAccountId])
}

model Session {
id String @id @default(cuid()) @map("_id")
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid()) @map("_id")
name String?
email String @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
Post Post[]
Comment Comment[]
}

model VerificationToken {
identifier String @id @map("_id")
token String @unique
expires DateTime

@@unique([identifier, token])
}

model Category {
id String @id @default(cuid()) @map("_id")
slug String @unique
title String
img String?
Posts Post[]
}

model Post {
id String @id @default(cuid()) @map("_id")
createdAt DateTime @default(now())
slug String @unique
title String
desc String
img String?
views Int @default(0)
catSlug String
cat Category @relation(fields: [catSlug], references: [slug])
userEmail String
user User @relation(fields: [userEmail], references: [email])
comments Comment[]
}

model Comment {
id String @id @default(cuid()) @map("_id")
createdAt DateTime @default(now())
desc String
userEmail String
user User @relation(fields: [userEmail], references: [email])
postSlug String
post Post @relation(fields: [postSlug], references: [slug])
}
Binary file added public/external.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/app/api/auth/[...nextauth]/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { authOptions } from "@/utils/auth";
import NextAuth from "next-auth";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
15 changes: 15 additions & 0 deletions src/app/api/categories/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import prisma from "@/utils/connect";
import { NextResponse } from "next/server";

export const GET = async () => {
try {
const categories = await prisma.category.findMany();

return new NextResponse(JSON.stringify(categories, { status: 200 }));
} catch (err) {
console.log(err);
return new NextResponse(
JSON.stringify({ message: "Something went wrong!" }, { status: 500 })
);
}
};
51 changes: 51 additions & 0 deletions src/app/api/comments/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { getAuthSession } from "@/utils/auth";
import prisma from "@/utils/connect";
import { NextResponse } from "next/server";

// GET ALL COMMENTS OF A POST
export const GET = async (req) => {
const { searchParams } = new URL(req.url);

const postSlug = searchParams.get("postSlug");

try {
const comments = await prisma.comment.findMany({
where: {
...(postSlug && { postSlug }),
},
include: { user: true },
});

return new NextResponse(JSON.stringify(comments, { status: 200 }));
} catch (err) {
// console.log(err);
return new NextResponse(
JSON.stringify({ message: "Something went wrong!" }, { status: 500 })
);
}
};

// CREATE A COMMENT
export const POST = async (req) => {
const session = await getAuthSession();

if (!session) {
return new NextResponse(
JSON.stringify({ message: "Not Authenticated!" }, { status: 401 })
);
}

try {
const body = await req.json();
const comment = await prisma.comment.create({
data: { ...body, userEmail: session.user.email },
});

return new NextResponse(JSON.stringify(comment, { status: 200 }));
} catch (err) {
console.log(err);
return new NextResponse(
JSON.stringify({ message: "Something went wrong!" }, { status: 500 })
);
}
};
22 changes: 22 additions & 0 deletions src/app/api/posts/[slug]/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import prisma from "@/utils/connect";
import { NextResponse } from "next/server";

// GET SINGLE POST
export const GET = async (req, { params }) => {
const { slug } = params;

try {
const post = await prisma.post.update({
where: { slug },
data: { views: { increment: 1 } },
include: { user: true },
});

return new NextResponse(JSON.stringify(post, { status: 200 }));
} catch (err) {
console.log(err);
return new NextResponse(
JSON.stringify({ message: "Something went wrong!" }, { status: 500 })
);
}
};
74 changes: 74 additions & 0 deletions src/app/api/posts/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { getAuthSession } from "@/utils/auth";
import prisma from "@/utils/connect";
import { NextResponse } from "next/server";

export const GET = async (req) => {
const { searchParams } = new URL(req.url);

const page = searchParams.get("page");
const cat = searchParams.get("cat");

const POST_PER_PAGE = 2;

const query = {
take: POST_PER_PAGE,
skip: POST_PER_PAGE * (page - 1),
where: {
...(cat && { catSlug: cat }),
},
};








try {
const [posts, count] = await prisma.$transaction([
prisma.post.findMany(query),
prisma.post.count({ where: query.where }),
]);
return new NextResponse(JSON.stringify({ posts, count }, { status: 200 }));
} catch (err) {
console.log(err);
return new NextResponse(
JSON.stringify({ message: "Something went wrong!" }, { status: 500 })
);
}
};










// CREATE A POST
export const POST = async (req) => {
const session = await getAuthSession();

if (!session) {
return new NextResponse(
JSON.stringify({ message: "Not Authenticated!" }, { status: 401 })
);
}

try {
const body = await req.json();
const post = await prisma.post.create({
data: { ...body, userEmail: session.user.email },
});

return new NextResponse(JSON.stringify(post, { status: 200 }));
} catch (err) {
console.log(err);
return new NextResponse(
JSON.stringify({ message: "Something went wrong!" }, { status: 500 })
);
}
};
13 changes: 13 additions & 0 deletions src/app/blog/blogPage.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.title{
background-color: coral;
color: white;
padding: 5px 10px;
text-align: center;
text-transform: capitalize;
}

.content{
display: flex;
gap: 50px;
}

20 changes: 20 additions & 0 deletions src/app/blog/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import CardList from "@/components/cardList/CardList";
import styles from "./blogPage.module.css";
import Menu from "@/components/Menu/Menu";

const BlogPage = ({ searchParams }) => {
const page = parseInt(searchParams.page) || 1;
const { cat } = searchParams;

return (
<div className={styles.container}>
<h1 className={styles.title}>{cat} Blog</h1>
<div className={styles.content}>
<CardList page={page} cat={cat}/>
<Menu />
</div>
</div>
);
};

export default BlogPage;
Loading