Skip to content
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

create mogo branch #1

Open
wants to merge 2 commits into
base: main
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
4 changes: 2 additions & 2 deletions components/common/GoTopButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const GoTopButton = () => {
background: #daa520;
color: #171717;

width: 30px;
height: 30px;
width: 36px;
height: 36px;
border-radius: 25px;

outline: none;
Expand Down
2 changes: 1 addition & 1 deletion components/common/NotFoundPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from "next/link";

const NotFoundPage = () => {
return (
<div>
<div className="w-full">
<div className="fon">
<div className="horizon">
<div></div>
Expand Down
25 changes: 13 additions & 12 deletions models/Work.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// import { Schema, model, models } from "mongoose";
import { Schema, model, models } from "mongoose";

// const workSchema = new Schema({
// id: Number,
// title: String,
// description: String,
// imgUrl: String,
// gitLink: String,
// netlifyLink: String,
// like: Number,
// });

// const Work = models.Work || model("Work", workSchema);
// export default Work;
const workSchema = new Schema({
id: Number,
title: String,
description: String,
imgUrl: String,
gitLink: String,
netlifyLink: String,
like: Number,
});

const Work = models.Work || model("Work", workSchema);
export default Work;
100 changes: 50 additions & 50 deletions pages/api/data/[workId].js
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
// import Work from "@/models/Work";
// import connectDB from "@/utils/connectDB";
import Work from "@/models/Work";
import connectDB from "@/utils/connectDB";

// export default async function handler(req, res) {
// try {
// await connectDB();
// } catch (err) {
// console.log(err);
// res
// .status(500)
// .json({ status: "failed", message: "error in connecting to database" });
export default async function handler(req, res) {
try {
await connectDB();
} catch (err) {
console.log(err);
res
.status(500)
.json({ status: "failed", message: "error in connecting to database" });

// return;
// }
return;
}

// console.log(req.query);
// const id = req.query.workId;
// const data = req.body.data;
// console.log("workId",id);
console.log(req.query);
const id = req.query.workId;
const data = req.body.data;
console.log("workId",id);

// // if (req.method === "GET") {
// // try {
// // const workData = await Work.findOne({ _id: id });
// // res.status(200).json({ status: "ok", data: workData });
// // } catch (err) {
// // console.log(err);
// // res.status(500).json({
// // status: "failed",
// // message: "error in retrieving data from database",
// // });
// // }
// // } else
// if (req.method === "PATCH") {
// try {
// const workData = await Work.findOne({ _id: id });
// workData.id = data.id;
// workData.title = data.title;
// workData.description = data.description;
// workData.imgUrl = data.imgUrl;
// workData.gitLink = data.gitLink;
// workData.netlifyLink = data.netlifyLink;
// workData.like = data.like;
// if (req.method === "GET") {
// try {
// const workData = await Work.findOne({ _id: id });
// res.status(200).json({ status: "ok", data: workData });
// } catch (err) {
// console.log(err);
// res.status(500).json({
// status: "failed",
// message: "error in retrieving data from database",
// });
// }
// } else
if (req.method === "PATCH") {
try {
const workData = await Work.updateOne({ _id: id });
// workData.id = data.id;
// workData.title = data.title;
// workData.description = data.description;
// workData.imgUrl = data.imgUrl;
// workData.gitLink = data.gitLink;
// workData.netlifyLink = data.netlifyLink;
workData.like = data.like;

// await workData.save();
// res.status(200).json({ status: "ok", data: workData });
// } catch (err) {
// console.log(err.message);
// res.status(500).json({
// status: "failed",
// message: "error in updating data from database",
// });
// return;
// }
// }
// }
await workData.save();
res.status(200).json({ status: "ok", data: workData });
} catch (err) {
console.log(err.message);
res.status(500).json({
status: "failed",
message: "error in updating data from database",
});
return;
}
}
}
48 changes: 24 additions & 24 deletions pages/api/data/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// import Work from "@/models/Work";
// import connectDB from "@/utils/connectDB";
import Work from "@/models/Work";
import connectDB from "@/utils/connectDB";

// export default async function handler(req, res) {
// try {
// await connectDB();
// } catch (err) {
// console.log(err);
// res
// .status(500)
// .json({ status: "failed", message: "error in connecting to database" });
// return;
// }
export default async function handler(req, res) {
try {
await connectDB();
} catch (err) {
console.log(err);
res
.status(500)
.json({ status: "failed", message: "error in connecting to database" });
return;
}

// // if (req.method === "POST") {
// // const likeItem = req.body.like;
Expand Down Expand Up @@ -41,15 +41,15 @@
// // }
// // } else

// if (req.method === "GET") {
// try {
// const works = await Work.find();
// res.status(200).json({ status: "ok", data: works });
// } catch (err) {
// res.status(500).json({
// status: "failed",
// message: "error in retrieving data from database",
// });
// }
// }
// }
if (req.method === "GET") {
try {
const works = await Work.find();
res.status(200).json({ status: "ok", data: works });
} catch (err) {
res.status(500).json({
status: "failed",
message: "error in retrieving data from database",
});
}
}
}
54 changes: 27 additions & 27 deletions pages/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import connectDB from "@/utils/connectDB";

const Portfolio = ({ works }) => {
if (!works || works.length === 0) {
return <h2>Loading....</h2>;
return <h2 className="w-full h-full text-center flex justify-center items-center">Loading....</h2>;
}

return <PortfolioPage works={works} />;
Expand All @@ -17,30 +17,30 @@ const Portfolio = ({ works }) => {
export default Portfolio;

export async function getStaticProps({ locale }) {
// try {
// await connectDB();
// const works = await Work.find();
// return {
// props: {
// works: JSON.parse(JSON.stringify(works)),
// ...(await serverSideTranslations(locale, ["portfolio"])),
// },
// // revalidate: 24 * 60 * 60,
// };
// } catch (err) {
// return {
// notFound: true,
// };
// }

const res = await fetch("https://fatemeweb-api.vercel.app/PortfoliosData");
const data = await res.json();

return {
props: {
works: data,
...(await serverSideTranslations(locale, ["portfolio"])),
},
// revalidate: 24 * 60 * 60,
};
try {
await connectDB();
const works = await Work.find();
return {
props: {
works: JSON.parse(JSON.stringify(works)),
...(await serverSideTranslations(locale, ["portfolio"])),
},
// revalidate: 24 * 60 * 60,
};
} catch (err) {
return {
notFound: true,
};
}

// const res = await fetch("https://fatemeweb-api.vercel.app/PortfoliosData");
// const data = await res.json();

// return {
// props: {
// works: data,
// ...(await serverSideTranslations(locale, ["portfolio"])),
// },
// // revalidate: 24 * 60 * 60,
// };
}
2 changes: 1 addition & 1 deletion styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
}

.portfolio-hover{
@apply absolute bg-yellowPrimary top-0 left-0 w-full h-full flex justify-center items-center flex-wrap opacity-0 duration-300
@apply absolute p-4 bg-yellowPrimary top-0 left-0 w-full h-full flex justify-center items-center flex-wrap opacity-0 duration-300
}
.portfolio-item:hover .portfolio-hover{
@apply opacity-100
Expand Down
13 changes: 9 additions & 4 deletions utils/connectDB.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import mongoose from "mongoose";

async function connectDB() {
if (mongoose.connections[0].readyState) return;
await mongoose.connect(process.env.MONGO_URL);
console.log("connected to DB");
try {
if (mongoose.connections[0].readyState) return;
mongoose.set("strictQuery", false);
await mongoose.connect(process.env.MONGO_URI);
console.log("Connected to DB");
} catch (error) {
console.log("Error connecting to DB:", error.message);
}
}

export default connectDB;
export default connectDB;