Skip to content

Commit

Permalink
Server connected with frontend!
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoveetSingh committed May 27, 2024
1 parent 359edae commit 7874a53
Show file tree
Hide file tree
Showing 18 changed files with 538 additions and 55 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Sample workflow for building and deploying a Next.js site to GitHub Pages
#
# To get started with Next.js see: https://nextjs.org/docs/getting-started
#
name: Deploy Next.js site to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["test"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine packager manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Setup Pages
uses: actions/configure-pages@v2
with:
# Automatically inject basePath in your Next.js configuration file and disable
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
#
# You may remove this line if you want to manage the configuration yourself.
static_site_generator: next
- name: Restore cache
uses: actions/cache@v3
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
- name: Static HTML export with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next export
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./out

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
11 changes: 11 additions & 0 deletions components/Blogs/BlogCard.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import styles from "@styles/scss/blogcard.module.scss";
import Image from "next/image";
<<<<<<< HEAD:components/Blogs/BlogCard.js
import dataScienceImg from "@images/blog/dataScience.webp";
=======
>>>>>>> 2e3ced3f1a6c1a70341b50aee0bde119b118a150:components/BlogCard.js
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faThumbsUp, faComment } from "@fortawesome/free-solid-svg-icons";
import Link from "next/link";
const BlogCard = (props) => {
<<<<<<< HEAD:components/Blogs/BlogCard.js
const { id, image, comments, likes ,title,author} = props;
=======
const { id, title, image, comments, likes } = props;
>>>>>>> 2e3ced3f1a6c1a70341b50aee0bde119b118a150:components/BlogCard.js
return (
<>
<Link
Expand All @@ -14,10 +21,14 @@ const BlogCard = (props) => {
>
<div className={styles.cover}>
<div className={styles.image}>
<<<<<<< HEAD:components/Blogs/BlogCard.js
<Image loading="lazy" src={image} alt="data-science-amupedia-blogs"
layout="responsive"
width="1500"
height="1000"/>
=======
<Image src={`/images/blog/${image}`} width={500} height={500} alt="data-science-amupedia-blogs" />
>>>>>>> 2e3ced3f1a6c1a70341b50aee0bde119b118a150:components/BlogCard.js
</div>
<h3 className={styles.title}>
{title}
Expand Down
11 changes: 6 additions & 5 deletions components/Opportunities/oppCard.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/* eslint-disable jsx-a11y/alt-text */
import styles from "@styles/oppCard.module.css";
import Link from "node_modules/next/link";

const OppCard = (props) => {
const { title, date, image } = props;
const OppCard = (data) => {
const { title, date, image } = data.data;
return (
<div className={styles.main}>
<div className={styles.picture}>
<h2>Image</h2>
<image src={`/images/oppCard/${image}`} />
</div>
<div className={styles.cardInfo}>
<div className={styles.title}>
<h3>Title</h3>
<span>Date Added -</span>
<h3>{title}</h3>
<span>{date}</span>
</div>
<Link href="#">
<a className={styles.link}>Apply Now</a>
Expand Down
8 changes: 8 additions & 0 deletions db/models/Blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const blogSchema = new mongoose.Schema({
type: String,
required: true,
},
like: {
type: Number,
required: true,
},
numberOfComments: {
type: Number,
required: true,
}
});

const Blog = mongoose.models.Blog || mongoose.model("Blog", blogSchema);
Expand Down
22 changes: 22 additions & 0 deletions db/models/BlogComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import mongoose from "mongoose";

const blogCommentSchema = new mongoose.Schema({
userName: {
type: String,
},
blogId: {
type: String,
required: true,
},
message: {
type: String,
required: true,
},
date: {
type: String,
required: true,
}
});

const BlogComment = mongoose.models.BlogComment || mongoose.model("BlogComment", blogCommentSchema);
export default BlogComment;
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
<<<<<<< HEAD
"@fortawesome/react-fontawesome": "^0.2.0",
"aos": "^2.3.4",
=======
"@fortawesome/react-fontawesome": "^0.1.16",
"@types/webidl-conversions": "^7.0.0",
>>>>>>> 2e3ced3f1a6c1a70341b50aee0bde119b118a150
"axios": "^0.27.2",
"bcryptjs": "^2.4.3",
"framer-motion": "^5.5.5",
Expand Down
90 changes: 70 additions & 20 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<<<<<<< HEAD
import Navbar from "@comp/common/Navbar";
import jwt from "jsonwebtoken";
=======
import Navbar from "@comp/Navbar";
// import jwt from "jsonwebtoken";
>>>>>>> 2e3ced3f1a6c1a70341b50aee0bde119b118a150
import "@styles/globals.css";
import Head from "node_modules/next/head";
// import { useEffect } from 'react';
Expand Down Expand Up @@ -71,30 +76,31 @@ function MyApp({ Component, pageProps, router }) {
// }
// }, []);

return (
<StoreProvider>
{/* <div id="signInDiv"></div> */}
<Alert />
{/* <Login /> */}
<motion.div
key={router.route}
initial="pageInitial"
animate="pageAnimate"
variants={{
pageInitial: {
opacity: 0,
},
pageAnimate: {
opacity: 1,
},
}}
>
<Head>
{/* <script
return (
<StoreProvider>
{/* <div id="signInDiv"></div> */}
<Alert />
{/* <Login /> */}
<motion.div
key={router.route}
initial="pageInitial"
animate="pageAnimate"
variants={{
pageInitial: {
opacity: 0,
},
pageAnimate: {
opacity: 1,
},
}}
>
<Head>
{/* <script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6172950963478417"
crossOrigin="anonymous"
></script> */}
<<<<<<< HEAD

<title>Amupedia</title>
{/* Primary meta tags */}
Expand Down Expand Up @@ -151,6 +157,50 @@ function MyApp({ Component, pageProps, router }) {
</motion.div>
</StoreProvider>
);
=======
<script
src="https://accounts.google.com/gsi/client"
async
defer
></script>
<title>Amupedia</title>
<meta
name="description"
content="Amupedia is an initiative to help college students pursuing B.Tech, B.E or B.Com, especially from AMU."
/>
<meta name="keywords" content="B.Tech, B.Com, B.E" />
<meta
property="og:image"
content="https://www.amupedia.com/og-image.jpg"
/>
<meta property="og:image:width" content="150" />
<meta property="og:image:height" content="150" />
<meta property="og:title" content="Amupedia" />
<meta
property="og:description"
content="Amupedia is an initiative to help college students pursuing B.Tech, B.E or B.Com, especially from AMU."
/>
<meta name="twitter:card" content="summary" />
<meta property="og:url" content="https://www.amupedia.com" />
<script
type="application/ld+json"
dangerouslySetInnerHTML={addProductJsonLd()}
key="product-jsonld"
/>
</Head>
<section styles={{ position: "relative" }}>
<Navbar />
<Component {...pageProps}></Component>
<Script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6172950963478417"
crossOrigin="anonymous"
></Script>
</section>
</motion.div>
</StoreProvider>
);
>>>>>>> 2e3ced3f1a6c1a70341b50aee0bde119b118a150
}

export default MyApp;
12 changes: 12 additions & 0 deletions pages/adFix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const body = document.querySelector('body');
const googleAd = document.querySelector('ins[data-anchor-status]');

setInterval(() => {
if (googleAd.getAttribute("data-anchor-status") === "displayed") {
body.style.paddingTop = "100px";
} else if (googleAd.getAttribute("data-anchor-status") === "dismissed") {
body.style.paddingTop = "0";
}
}, 0);

console.log("Testing");
20 changes: 20 additions & 0 deletions pages/api/blogs/comments/fetchComments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import db from "db/db";
import BlogComment from "db/models/BlogComment";
import nextConnect from "next-connect";
const handler = nextConnect();

handler.get(async (req, res) => {
try {
await db.connect();
const data = req.body;
console.log(data);
const result = await BlogComment.find();
console.log(result)
await db.disconnect();
res.status(200).json({ success: true, result: result });
} catch (error) {
res.status(500).json({ success: false, error });
}
});

export default handler;
28 changes: 28 additions & 0 deletions pages/api/blogs/comments/publishComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import db from "db/db";
import BlogComment from "db/models/BlogComment";
import nextConnect from "next-connect";
const handler = nextConnect();

handler.post(async (req, res) => {
try {
await db.connect();
const data = req.body;
const today = new Date();
const dd = String(today.getDate()).padStart(2, '0');
const mm = String(today.getMonth() + 1).padStart(2, '0');
const yyyy = today.getFullYear();
console.log(data);
const result = await BlogComment.create({
userName: req.body.userName,
blogId: req.body.blogId,
message: req.body.message,
date: mm + '/' + dd + '/' + yyyy,
});
await db.disconnect();
res.status(200).json({ success: true, result: result });
} catch (error) {
res.status(500).json({ success: false, error });
}
});

export default handler;
Loading

0 comments on commit 7874a53

Please sign in to comment.