diff --git a/src/Config.js b/src/Config.js
new file mode 100644
index 0000000..cd74e7c
--- /dev/null
+++ b/src/Config.js
@@ -0,0 +1,4 @@
+export const baseUrl = process.env.REACT_APP_API_BASE_URL;
+export const apiWeb = process.env.REACT_APP_API_CONTACT;
+export const apiEmail = process.env.REACT_APP_EMAIL_KEY;
+
diff --git a/src/api/posts.js b/src/api/posts.js
index d5dc2a9..d6be352 100644
--- a/src/api/posts.js
+++ b/src/api/posts.js
@@ -1,11 +1,11 @@
import axios from "axios";
-import Cookies from "js-cookie";
+import Cookies from "js-cookie";
+import { baseUrl } from "../Config";
-const PostUrl = process.env.REACT_APP_POST_URL;
-const UpdatePost = process.env.REACT_APP_UPDATE_POST;
-const DeletePost = process.env.REACT_APP_POST_DELETE;
-const PostId = process.env.REACT_APP_POST_ID;
+export const getTokenFromCookie = () => {
+ return Cookies.get("token") || "";
+};
export const getTokenFromCookie = () => {
@@ -14,7 +14,7 @@ export const getTokenFromCookie = () => {
export const getPostsRequest = async () =>
- await axios.get(PostUrl, {});
+ await axios.get(`${baseUrl}/posts`, {});
export const createPostRequest = async (post) => {
const form = new FormData();
@@ -23,36 +23,40 @@ export const createPostRequest = async (post) => {
form.append(key, post[key]);
}
- return await axios.post(PostUrl, form, {
+ return await axios.post(`${baseUrl}/posts`, form, {
headers: {
"Content-Type": "multipart/form-data",
- Authorization: `Bearer ${getTokenFromCookie()}`,
+ Authorization: `Bearer ${getTokenFromCookie()}`,
+
},
});
};
export const deletePostRequest = async (id) =>
- await axios.delete(DeletePost + id, {
+
+ await axios.delete(`${baseUrl}/posts/${id}`, {
headers: {
- Authorization: `Bearer ${getTokenFromCookie()}`,
+ Authorization: `Bearer ${getTokenFromCookie()}`,
+
},
});
export const getPostRequest = async (id) =>
- await axios.get(PostId + id);
-
- export const updatePostRequest = async (id, formData) => {
- try {
- const response = await axios.put(`${UpdatePost}/${id}`, formData, {
- headers: {
- Authorization: `Bearer ${getTokenFromCookie()}`,
- 'Content-Type': 'multipart/form-data',
- },
- });
-
- return response.data;
- } catch (error) {
-
- throw error;
- }
- };
\ No newline at end of file
+
+ await axios.get(`${baseUrl}/posts/` + id);
+
+export const updatePostRequest = async (id, formData) => {
+ try {
+ const response = await axios.put(`${baseUrl}/posts/${id}`, formData, {
+ headers: {
+ Authorization: `Bearer ${getTokenFromCookie()}`,
+ "Content-Type": "multipart/form-data",
+ },
+ });
+
+ return response.data;
+ } catch (error) {
+ throw error;
+ }
+};
+
diff --git a/src/components/Comments.jsx b/src/components/Comments.jsx
index 476b272..c1d1b54 100644
--- a/src/components/Comments.jsx
+++ b/src/components/Comments.jsx
@@ -4,18 +4,26 @@ import axios from "axios";
import toast from "react-hot-toast";
import Cookies from "js-cookie";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import {
+ faTrash,
+ faPenToSquare,
+ faXmark,
+ faCheck,
+} from "@fortawesome/free-solid-svg-icons";
+import { baseUrl } from "../Config";
+
export const Comment = ({ comment, onDelete, onEdit }) => {
const [isEditing, setIsEditing] = useState(false);
const [editedText, setEditedText] = useState(comment.text);
const handleDeleteComment = async () => {
try {
- await axios.delete(
- `http://localhost:4000/api/posts/${comment._id}/comments/`,
- {
- withCredentials: true,
- }
- );
+
+ await axios.delete(`${baseUrl}/posts/${comment._id}/comments/`, {
+ withCredentials: true,
+ });
+
onDelete(comment._id);
@@ -28,7 +36,9 @@ export const Comment = ({ comment, onDelete, onEdit }) => {
const handleEditComment = async () => {
try {
const response = await axios.put(
- `http://localhost:4000/api/posts/${comment._id}/comments/`,
+
+ `${baseUrl}/posts/${comment._id}/comments/`,
+
{ text: editedText },
{
withCredentials: true,
@@ -47,7 +57,9 @@ export const Comment = ({ comment, onDelete, onEdit }) => {
};
const canEditAndDelete =
- comment?.commentator?.trim() === Cookies.get("username")?.trim()
+
+ comment?.commentator?.trim() === Cookies.get("username")?.trim();
+
return (
@@ -64,34 +76,42 @@ export const Comment = ({ comment, onDelete, onEdit }) => {
<>
>
) : (
<>
>
)}
@@ -104,7 +124,13 @@ export const Comment = ({ comment, onDelete, onEdit }) => {
-
-
-
-
+
@@ -132,12 +65,24 @@ export function PostCard({ post }) {
{post.title}
+
- {post.description
- ? `${post.description.substr(0, 330)}...Read More`
- : "not description"}
+ {showFullDescription
+ ? post.description
+ : post.description
+ ? `${post.description.substr(0, 330)}...`
+ : "No description"}
+ {post.description && (
+
+ )}
+
{" "}
Source: {post.source}
diff --git a/src/components/PostCardUser.jsx b/src/components/PostCardUser.jsx
index 30ac45a..43d5e5b 100644
--- a/src/components/PostCardUser.jsx
+++ b/src/components/PostCardUser.jsx
@@ -1,11 +1,12 @@
import moment from "moment";
-import React, { useEffect } from "react";
+import React, { useEffect} from "react";
import ReactMarkdown from "react-markdown";
import { insertMedia } from "./PostCard";
import logoImg from "../Images/postimg.jpg";
import { Link, useNavigate } from "react-router-dom";
import Cookies from "js-cookie";
-
+import { faComment } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
export function PostCardUser({ post }) {
const relativeDate = moment(post.createdAt).fromNow();
const navigate = useNavigate();
@@ -49,6 +50,10 @@ export function PostCardUser({ post }) {
{" "}
Source: {post.source}
+
+
+ {post.comments.length} Comment(s)
+
diff --git a/src/components/PostDetailsCard.jsx b/src/components/PostDetailsCard.jsx
index a08dd4f..b2e05d1 100644
--- a/src/components/PostDetailsCard.jsx
+++ b/src/components/PostDetailsCard.jsx
@@ -10,8 +10,9 @@ import toast from "react-hot-toast";
import { SocialShare } from "./SocialShare";
import { usePosts } from "../context/postContext";
import { getTokenFromCookie } from "../api/posts";
-import { faArrowLeft } from "@fortawesome/free-solid-svg-icons";
+import { faArrowLeft,faComment } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { baseUrl } from "../Config";
export function PostDetailsCard() {
const { state } = useLocation();
const relativeDate = state?.post
@@ -28,7 +29,9 @@ export function PostDetailsCard() {
try {
const response = await axios.post(
- `http://localhost:4000/api/posts/${postId}/comments`,
+
+ `${baseUrl}/posts/${postId}/comments`,
+
{ text: commentText },
{
headers: {
@@ -156,7 +159,8 @@ export function PostDetailsCard() {
- {postData.comments.length} Comment(s)
+ {postData.comments.length} Comment(s)
+
{
const initialState = {
username: "",
@@ -17,7 +19,7 @@ const SignupForm = ({ onSuccess }) => {
const handleSubmit = async (e) => {
e.preventDefault();
try {
- const url = "http://localhost:4000/api/auth/signup";
+ const url = `${baseUrl}/auth/signup`;
const { data: res } = await axios.post(url, data);
const roles = res?.roles;
const token = res?.token;
diff --git a/src/hooks/useAuthentication.js b/src/hooks/useAuthentication.js
index 74559d7..e603d32 100644
--- a/src/hooks/useAuthentication.js
+++ b/src/hooks/useAuthentication.js
@@ -2,10 +2,11 @@ import axios from "axios";
import { useNavigate } from "react-router-dom";
import Cookies from "js-cookie";
import toast from "react-hot-toast";
-
+import { baseUrl } from "../Config";
const useAuthentication = () => {
const navigate = useNavigate();
- const LoginUrl = process.env.REACT_APP_API_LOGIN;
+ const LoginUrl = `${baseUrl}/auth/signin`;
+
const authenticate = async (data) => {
try {
diff --git a/src/hooks/useSignupLogic.js b/src/hooks/useSignupLogic.js
index aaeb1f8..d5f21db 100644
--- a/src/hooks/useSignupLogic.js
+++ b/src/hooks/useSignupLogic.js
@@ -3,7 +3,7 @@ import { useNavigate, useLocation } from "react-router-dom";
import useAuth from "./useAuth";
import axios from "axios";
import { toast } from "react-hot-toast";
-
+import { baseUrl } from "../Config";
const useSignupLogic = () => {
const [data, setData] = useState({
username: "",
@@ -16,7 +16,7 @@ const useSignupLogic = () => {
const location = useLocation();
const navigate = useNavigate();
- const SignupUrl = process.env.REACT_APP_API_SIGNUP;
+ const SignupUrl = `${baseUrl}/auth/signup`;
const from = location.state?.from?.pathname || "/login";
const handleChange = ({ currentTarget: input }) => {
diff --git a/src/pages/Contact.js b/src/pages/Contact.js
index 2806fb5..159432e 100644
--- a/src/pages/Contact.js
+++ b/src/pages/Contact.js
@@ -3,8 +3,7 @@ import { toast } from "react-hot-toast";
import { faHeadset } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import Cookies from "js-cookie";
-const apiWeb = process.env.REACT_APP_API_CONTACT;
-const apiEmail =process.env.REACT_APP_EMAIL_KEY
+import { apiEmail,apiWeb } from "../Config";
const ContactForm = () => {
const savedEmail = Cookies.get("email");
@@ -68,11 +67,10 @@ const ContactForm = () => {