Skip to content

Commit

Permalink
Removed rendering problem in home page
Browse files Browse the repository at this point in the history
  • Loading branch information
KaranSiddhu committed Aug 1, 2021
1 parent b6594d3 commit 8ea2ca1
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 49 deletions.
4 changes: 0 additions & 4 deletions .env

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

config.env

# dependencies
/node_modules
/.pnp
Expand Down
1 change: 1 addition & 0 deletions src/api/backendApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const API =process.env.REACT_APP_BACKEND;
// export const API_IMG =process.env.REACT_APP_BACKEND_IMG;

export const QuotesAPI = process.env.REACT_APP_QUOTES_API;
7 changes: 5 additions & 2 deletions src/components/header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ const Header = ({ history }) => {
<section className="header">
<section className="header-top">
<section className="header-top__logo">
<NavLink to="/" exact activeClassName="active-class">
{/* <NavLink to="/" exact activeClassName="active-class"> */}
<a href="/">
<img src={logo} alt="LOGO" />
</NavLink>
</a>

{/* </NavLink> */}
</section>

<section
Expand Down
5 changes: 3 additions & 2 deletions src/components/posts/Posts.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from "react";
import { Link } from "react-router-dom";
import { API } from "../../api/backendApi";
import { API_IMG } from "../../api/backendApi";

import "./posts.css";

const Posts = ({ posts }) => {
return (
<div className="posts">
{posts.map((post, index) => {

let imageUrl = post.photo
? `${API}/blog/photo/${post._id}`
? post.photo
: "https://redzonekickboxing.com/wp-content/uploads/2017/04/default-image.jpg";

{/* console.log(post); */}
Expand Down
2 changes: 2 additions & 0 deletions src/components/posts/posts.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}

.postCat {
Expand All @@ -58,6 +59,7 @@
margin-top: 15px;
cursor: pointer;
color: black;

}
.postTitle:hover{
color: #2ecc72;
Expand Down
18 changes: 11 additions & 7 deletions src/pages/Home/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ const HomeScreen = ({ history }) => {
const [loading, setLoading] = useState(false);
const [blogs, setBlogs] = useState([]);
const { search } = useLocation();



// const { } = useContext(AuthContext);

const getQuotes = async () => {
try {
setLoading(true);
// setLoading(true);

const { data } = await axios.get(QuotesAPI, { withCredentials: false });

Expand All @@ -36,11 +37,11 @@ const HomeScreen = ({ history }) => {

useEffect(() => {
const fetchBlogs = async () => {
console.log("LOCATION - ",search);
// console.log("LOCATION - ",search);
try {
setLoading(true);
const { data } = await axios.get(`${API}/blogs/${search}`);
console.log("BLOG DATA ", data);
// console.log("BLOG DATA ", data);
setLoading(false);

setBlogs(data);
Expand All @@ -65,16 +66,19 @@ const HomeScreen = ({ history }) => {

const showBlogs = () => {
console.log("USE STATE", blogs);
return <div className="blogs__container">
{ (blogs.length === 0) ? "" : <Posts posts={blogs.blogs}/> }
</div>;
return (
<div className="blogs__container">
{blogs.length === 0 ? "" : <Posts posts={blogs.blogs} />}
</div>
);
};

const homePageContent = () => {
return (
<>
{quote(quotes.text, quotes.author)}
{showBlogs()}

</>
);
};
Expand Down
22 changes: 14 additions & 8 deletions src/pages/Single Post/DisplayPost.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import React, { useState, useEffect, useContext } from "react";
import { Link } from "react-router-dom";
import { API } from "../../api/backendApi";
import { API, API_IMG } from "../../api/backendApi";
import AuthContext from "../../context/AuthContext";

import { FaEdit } from "react-icons/fa";
Expand All @@ -16,7 +16,7 @@ const DisplayPost = ({ match, history }) => {
const [loading, setLoading] = useState(false);

const { userData } = useContext(AuthContext);

console.log("SINGLE POST - ", post);
useEffect(() => {
const getPost = async () => {
setLoading(true);
Expand Down Expand Up @@ -58,7 +58,7 @@ const DisplayPost = ({ match, history }) => {
await axios.put(
`${API}/blog/update/${post._id}`,
{
userEmail: userData.email,
user: userData._id,
title,
desc
},
Expand All @@ -72,7 +72,7 @@ const DisplayPost = ({ match, history }) => {
};

let imageUrl = post.photo
? `${API}/blog/photo/${post._id}`
? post.photo
: "https://redzonekickboxing.com/wp-content/uploads/2017/04/default-image.jpg";

const displayPostContent = () => {
Expand All @@ -92,8 +92,11 @@ const DisplayPost = ({ match, history }) => {
) : (
<h1 className="singlePostTitle">
{title}
{console.log("CHEKC🔥 - ", post.userEmail === userData.email)}
{post.userEmail === userData.email && (

{
(post.user === undefined
? ""
: post.user.email) === userData.email && (
<div className="singlePostEdit">
<FaEdit
className="singlePostIcon far fa-edit"
Expand All @@ -107,8 +110,11 @@ const DisplayPost = ({ match, history }) => {
<div className="singlePostInfo">
<span className="singlePostAuthor">
Author:
<Link to={`/?user=${post.userEmail}`} className="link_query">
<b> {post.userEmail}</b>
<Link
to={`/?user=${post.user === undefined ? "" : post.user._id}`}
className="link_query"
>
<b>{post.user === undefined ? "" : post.user.email}</b>
</Link>
</span>
<span className="singlePostDate">{new Date(post.createdAt).toDateString()}</span>
Expand Down
49 changes: 26 additions & 23 deletions src/pages/create post/Createpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@ const Createpost = () => {

const handleSubmit = async (e) => {
e.preventDefault();
const newPost = {
userEmail: userData.email,
title,
desc
};

if (file) {
const data = new FormData();
const filename = Date.now() + file.name;
data.append("name", filename);
data.append("file", file);
newPost.photo = filename;
try {
await axios.post("/upload", data);
} catch (err) {
console.log("ERROR - ", err);
}
}

try {
const res = await axios.post("/posts", newPost);
window.location.replace("/post/" + res.data._id);
} catch (err) {
console.log("ERROR - ", err);
}

// const newPost = {
// userEmail: userData.email,
// title,
// desc
// };

// if (file) {
// const data = new FormData();
// const filename = Date.now() + file.name;
// data.append("name", filename);
// data.append("file", file);
// newPost.photo = filename;
// try {
// await axios.post("/upload", data);
// } catch (err) {
// console.log("ERROR - ", err);
// }
// }

// try {
// const res = await axios.post("/posts", newPost);
// window.location.replace("/post/" + res.data._id);
// } catch (err) {
// console.log("ERROR - ", err);
// }
};

return (
Expand Down
6 changes: 3 additions & 3 deletions src/pages/profile/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const ProfilePage = ({ history }) => {
<TiTick />
<button
className="btn btn-primary"
onClick={() => history.push(`/?user=${userData.email}`)}
onClick={() => history.push(`/?user=${userData._id}`)}
>
Manage your blogs
</button>
Expand Down Expand Up @@ -368,7 +368,7 @@ const ProfilePage = ({ history }) => {

const handleBlogSubmit = async (e) => {
e.preventDefault();
file.set("userEmail", userData.email);
file.set("user", userData._id);

try{

Expand Down Expand Up @@ -482,7 +482,7 @@ const ProfilePage = ({ history }) => {
</div>
</Modal>

{/* NOTE edit progile modal */}
{/* NOTE edit profile modal */}
<Modal
isOpen={isProfileModalOpen}
onRequestClose={() => setIsProfileModalOpen(false)}
Expand Down

0 comments on commit 8ea2ca1

Please sign in to comment.