From e70b5bf4dac8bc29d77b44151f620ddcfc7b6c0f Mon Sep 17 00:00:00 2001 From: hoseacodes Date: Sun, 19 Mar 2023 23:13:23 -0500 Subject: [PATCH] working code --- config/db.js | 12 ++++----- controllers/article.js | 2 +- models/article.js | 8 +++++- models/payment.js | 2 +- models/product.js | 2 +- src/Components/NavBar/SideBar.jsx | 2 +- .../PersonalBrand/PersonalBrand.jsx | 8 +++--- src/Layout/Hero/styledHero.jsx | 2 +- src/Pages/Articles/Articles.jsx | 26 ++++++++++++------- src/Pages/Auth/login.jsx | 2 +- src/Pages/Auth/register.jsx | 2 +- utils/authAdmin.js | 2 +- 12 files changed, 42 insertions(+), 28 deletions(-) diff --git a/config/db.js b/config/db.js index 7ff4bf34..eefe1f67 100644 --- a/config/db.js +++ b/config/db.js @@ -1,16 +1,16 @@ import mongoose from 'mongoose'; const connectDB = async () => { - const URI = process.env.MONGODB_URL + const URI = process.env.MONGODB_URL || "mongodb://localhost:27017/" mongoose.connect(URI, { - useCreateIndex: true, - useFindAndModify: false, useNewUrlParser: true, useUnifiedTopology: true }, err => { - if (err) throw err; - console.log('Connected to MongoDB') - }); + if (err) { + throw err; + } + console.log('Connected to MongoDB') + }); } export default connectDB; diff --git a/controllers/article.js b/controllers/article.js index ddd3822f..96630730 100755 --- a/controllers/article.js +++ b/controllers/article.js @@ -34,7 +34,7 @@ async function createArticle(req, res) { return res.status(400).json({ msg: "No image upload" }); } - const article = await Articles.findOne({ article_id }); + const article = await Articles.find({ article_id }); if (article) { diff --git a/models/article.js b/models/article.js index bdff9fb5..04e88c30 100755 --- a/models/article.js +++ b/models/article.js @@ -79,6 +79,12 @@ articleSchema.pre('validate', function (next) { const Articles = mongoose.model('Articles', articleSchema); -Articles.createIndexes(); +// When your application starts up, Mongoose automatically calls createIndex for each defined index +// in your schema. Mongoose will call createIndex for each index sequentially, and emit an 'index' +// event on the model when all the createIndex calls succeeded or when there was an error. While +// nice for development, it is recommended this behavior be disabled in production since index creation +// can cause a significant performance impact. Disable the behavior by setting the autoIndex option of +// your schema to false, or globally on the connection by setting the option autoIndex to false. +// Articles.createIndexes(); export default Articles; diff --git a/models/payment.js b/models/payment.js index 1e8109b2..9be57186 100644 --- a/models/payment.js +++ b/models/payment.js @@ -39,6 +39,6 @@ const paymentSchema = new mongoose.Schema({ const Payments = mongoose.model("Payments", paymentSchema); -Payments.createIndexes(); +// Payments.createIndexes(); export default Payments; diff --git a/models/product.js b/models/product.js index 10fa7a2b..5113cae2 100644 --- a/models/product.js +++ b/models/product.js @@ -49,6 +49,6 @@ const productSchema = new mongoose.Schema({ const Products = mongoose.model("Products", productSchema); -Products.createIndexes(); +// Products.createIndexes(); export default Products; diff --git a/src/Components/NavBar/SideBar.jsx b/src/Components/NavBar/SideBar.jsx index 6bc15221..cbc52b65 100644 --- a/src/Components/NavBar/SideBar.jsx +++ b/src/Components/NavBar/SideBar.jsx @@ -6,7 +6,7 @@ import {ArticleHr} from '../../Layout/Hr/styledHr'; import {HiOutlinePencilAlt} from 'react-icons/hi'; import {BsHouseDoor, BsBell} from 'react-icons/bs'; import {MdBookmarkBorder} from 'react-icons/md'; -import logo from '../../Assets/Images/newLogo.png'; +import logo from '../../Assets/Images/logo-min.png'; const SideBar = () => { diff --git a/src/Components/PersonalBrand/PersonalBrand.jsx b/src/Components/PersonalBrand/PersonalBrand.jsx index 1adf13c8..e5f09e4f 100755 --- a/src/Components/PersonalBrand/PersonalBrand.jsx +++ b/src/Components/PersonalBrand/PersonalBrand.jsx @@ -1,8 +1,8 @@ import React from 'react'; -import './PersonalBrand.css'; -import nique from '../../icons/nique.jpg' -import dom from '../../icons/hosea3.png' -import Resume2020 from '../../icons/Resume2020.pdf' +import './PersonalBrand.css' +import nique from '../../Assets/Icons/nique.jpg' +import dom from '../../Assets/Icons/hosea3.png' +import Resume2020 from '../../Assets/Files/Resume2020.pdf' import Modal from 'react-bootstrap/Modal' import Col from 'react-bootstrap/Col' import Row from 'react-bootstrap/Row' diff --git a/src/Layout/Hero/styledHero.jsx b/src/Layout/Hero/styledHero.jsx index c6ea31cd..9c3f1353 100644 --- a/src/Layout/Hero/styledHero.jsx +++ b/src/Layout/Hero/styledHero.jsx @@ -1,5 +1,5 @@ import styled, {css} from 'styled-components'; -import breakpoint from '../../Utils/breakpoints.js'; +import breakpoint from '../../utils/breakpoints'; import wireframe from '../../Assets/Images/wireframe-min.jpg'; import houston from '../../Assets/Images/besomeone-min.jpg'; diff --git a/src/Pages/Articles/Articles.jsx b/src/Pages/Articles/Articles.jsx index 7e80d9aa..700af0ca 100755 --- a/src/Pages/Articles/Articles.jsx +++ b/src/Pages/Articles/Articles.jsx @@ -26,17 +26,23 @@ const Articles = () => { const indexOfLastPost = currentPage * postsPerPage; const indexOfFirstPost = indexOfLastPost - postsPerPage; - const mainPosts = articles + const mainPosts = articles.sort((a,b) => new Date(b.createdAt) - new Date(a.createdAt)); + const archivedPosts = []; - + mainPosts.map((article) => { - if (article.archived) { - archivedPosts.push(article); - mainPosts.pop(article) - } + if (article.archived) { + archivedPosts.push(article); + mainPosts.pop(article) + } }); - + const currentPosts = mainPosts.slice(indexOfFirstPost, indexOfLastPost) + const shuffleArray = (arr) => arr.sort(() => 0.5 - Math.random()); + + const popularPosts = shuffleArray(mainPosts) + .filter((article) => article != currentPosts) + .slice(0, 5); const paginate = pageNum => setCurrentPage(pageNum); const nextPage = () => { @@ -115,6 +121,8 @@ const Articles = () => { else if (tagsShow === "Software Engineer") { taggedArticles = currentPosts.filter(item => item.category.includes("Software Engineer")) } + console.log(popularPosts) + // Load this effect on mount useEffect(() => { @@ -209,9 +217,9 @@ const Articles = () => {

Popular Post

- {mainPosts.map(article => { + {popularPosts.map(article => { return ( - +
{article.title}

) })} diff --git a/src/Pages/Auth/login.jsx b/src/Pages/Auth/login.jsx index c10d0414..aeac584a 100644 --- a/src/Pages/Auth/login.jsx +++ b/src/Pages/Auth/login.jsx @@ -5,7 +5,7 @@ import { Link } from "react-router-dom"; import { GlobalState } from '../../GlobalState'; import "./login.css"; -import Logo from "../../Assets/Images/newLogo.png"; +import Logo from "../../Assets/Images/logo-min.png"; const Login = () => { const state = useContext(GlobalState) diff --git a/src/Pages/Auth/register.jsx b/src/Pages/Auth/register.jsx index 2ee4990d..88d2772c 100644 --- a/src/Pages/Auth/register.jsx +++ b/src/Pages/Auth/register.jsx @@ -4,7 +4,7 @@ import axios from "axios"; import { Link } from "react-router-dom"; import "./login.css"; -import Logo from "../../Assets/Images/newLogo.png"; +import Logo from "../../Assets/Images/logo-min.png"; const Register = () => { const [showRole, setShowRole] = useState(false); diff --git a/utils/authAdmin.js b/utils/authAdmin.js index f49307ab..5b7620bd 100644 --- a/utils/authAdmin.js +++ b/utils/authAdmin.js @@ -2,7 +2,7 @@ import Users from "../models/user.js"; const authAdmin = async (req, res, next) => { try { - const user = await Users.findOne({ + const user = await Users.find({ _id: req.params.id }) console.log(user)