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

set backendURL from env #10

Merged
merged 2 commits into from Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
@@ -1,2 +1,4 @@

node_modules
*.env
node_modules/
.idea/
build/
1 change: 1 addition & 0 deletions sample.env
@@ -0,0 +1 @@
REACT_APP_BACKEND_URL=
14 changes: 7 additions & 7 deletions src/Components/Comments/Comments.jsx
Expand Up @@ -4,7 +4,7 @@ import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
import ToastMaker from "toastmaker";
import "toastmaker/dist/toastmaker.css";
import axios from "axios";
import axios from '../../utils/axios';
import {IoIosArrowBack,IoIosArrowForward} from "react-icons/io";
import { useGlobalContext} from '../../Context/StateContext';
import Box from '@mui/material/Box';
Expand Down Expand Up @@ -58,7 +58,7 @@ const ArticleCommentModal = ({setShowCommentModal, article, Comment, handleComme
};
const comment_Type = (article.isArticleModerator || article.isArticleReviewer || article.isAuthor)?"officialcomment":"publiccomment";
try {
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/comment/`,
const res = await axios.post(`/api/comment/`,
{Title: title,Comment: comment, article: article.id, Type: 'comment', comment_Type:comment_Type, tag: "public", parent_comment:Comment.id},
config);
setLoading(false);
Expand Down Expand Up @@ -185,7 +185,7 @@ const ArticleCommentEditModal = ({setShowEditModal, article, Comment, version, h
};
const comment_Type = (article.isArticleModerator || article.isArticleReviewer || article.isAuthor)?"officialcomment":"publiccomment";
try {
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/comment/`,
const res = await axios.post(`/api/comment/`,
{Title: title,Comment: comment, article: article.id, Type: 'comment', comment_Type:comment_Type, tag: "public",parent_comment:null, version:Comment.id},
config);
setLoading(false);
Expand Down Expand Up @@ -390,7 +390,7 @@ const Comments = ({ comment, article, colour }) => {
}
};
try {
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/comment/like/`,
const res = await axios.post(`/api/comment/like/`,
{post:comment.id, value:event.target.value},
config);
ToastMaker("Comment Rated Successfully!!!", 3000, {
Expand Down Expand Up @@ -434,7 +434,7 @@ const Comments = ({ comment, article, colour }) => {
}
try {
const res = await axios.get(
`https://scicommons-backend-vkyc.onrender.com/api/comment/?limit=20&offset=${repliesData.length}`,
`/api/comment/?limit=20&offset=${repliesData.length}`,
config
);
await loadData(res.data.success.results);
Expand Down Expand Up @@ -666,7 +666,7 @@ const Dropdown = ({ article,comment,color}) => {
}
};
try{
const response = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/comment/${comment.id}/block_user/`,config);
const response = await axios.post(`/api/comment/${comment.id}/block_user/`,config);
setBlock(!block);
} catch(error){
console.log(error);
Expand All @@ -682,7 +682,7 @@ const Dropdown = ({ article,comment,color}) => {
}
};
try{
const response = await axios.delete(`https://scicommons-backend-vkyc.onrender.com/api/comment/${comment.id}/`,config);
const response = await axios.delete(`/api/comment/${comment.id}/`,config);
window.location.reload();
} catch(error){
console.log(error);
Expand Down
6 changes: 3 additions & 3 deletions src/Components/CommunityEditPage/CommunityEditPage.jsx
@@ -1,5 +1,5 @@
import React, {useState,useEffect} from 'react';
import axios from 'axios';
import axios from '../../utils/axios';
import ToastMaker from 'toastmaker';
import "toastmaker/dist/toastmaker.css";
import Loader from '../Loader/Loader';
Expand Down Expand Up @@ -47,7 +47,7 @@ const CommunityEditPage = () => {
Authorization: `Bearer ${token}`
}
}
const res = await axios.get('https://scicommons-backend-vkyc.onrender.com/api/community/mycommunity',config)
const res = await axios.get('/api/community/mycommunity',config)

await loadData(res.data.success)

Expand Down Expand Up @@ -133,7 +133,7 @@ const CommunityEditPage = () => {
}

try {
const response = await axios.put(`https://scicommons-backend-vkyc.onrender.com/api/community/${community.Community_name}/`, form_data, {
const response = await axios.put(`/api/community/${community.Community_name}/`, form_data, {
headers: {
"Content-type": "multipart/form-data",
Authorization: `Bearer ${token}`,
Expand Down
8 changes: 4 additions & 4 deletions src/Components/JoinRequests/JoinRequests.jsx
@@ -1,5 +1,5 @@
import React,{useState, useEffect} from 'react'
import axios from 'axios'
import axios from '../../utils/axios'
import Loader from '../Loader/Loader'
import { TECollapse } from "tw-elements-react"
import {SlUser} from "react-icons/sl";
Expand Down Expand Up @@ -39,7 +39,7 @@ const JoinRequests = ({community}) => {
Authorization: `Bearer ${token}`
}
}
const res = await axios.get(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/get_requests/`, config)
const res = await axios.get(`/api/community/${community}/get_requests/`, config)
await loadData(res.data.success)
setLoading(false)
} catch (error) {
Expand Down Expand Up @@ -204,7 +204,7 @@ const AcceptModal = ({setShow, request, community,index, onDelete, loading, setL
Authorization: `Bearer ${token}`
}
}
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/approve_request/`, {user: request.user_id, status: "approved"}, config)
const res = await axios.post(`/api/community/${community}/approve_request/`, {user: request.user_id, status: "approved"}, config)

await onDelete(index)
setLoading(false)
Expand Down Expand Up @@ -245,7 +245,7 @@ const RejectModal = ({setReject, request, community,index, onDelete, loading, se
Authorization: `Bearer ${token}`
}
}
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/approve_request/`, {user: request.user_id, status: "rejected"}, config)
const res = await axios.post(`/api/community/${community}/approve_request/`, {user: request.user_id, status: "rejected"}, config)

await onDelete(index)
setLoading(false)
Expand Down
10 changes: 5 additions & 5 deletions src/Components/MembersTable/MembersTable.jsx
@@ -1,5 +1,5 @@
import React,{useState, useEffect, useRef} from 'react'
import axios from 'axios'
import axios from '../../utils/axios'
import Loader from "../Loader/Loader"
import {AiOutlineEdit,AiOutlineDelete,AiOutlineUserAdd} from 'react-icons/ai'
import ToastMaker from 'toastmaker';
Expand Down Expand Up @@ -34,7 +34,7 @@ const MembersTable = ({community}) => {
Authorization: `Bearer ${token}`
}
}
const res = await axios.get(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/members/`,config)
const res = await axios.get(`/api/community/${community}/members/`,config)
await loadData(res.data.success)

} catch (error) {
Expand Down Expand Up @@ -208,7 +208,7 @@ const DeleteModal = ({username,community, onDelete, userId,index, setShowDeleteM
Authorization: `Bearer ${token}`
}
}
const res = await axios.delete(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/remove_member/${userId}`, config)
const res = await axios.delete(`/api/community/${community}/remove_member/${userId}`, config)
if(res.status === 200){
await onDelete(index)
ToastMaker(res.data.success, 3500,{
Expand Down Expand Up @@ -266,7 +266,7 @@ const EditModal = ({community, setShowEditModal, member, index, onEdit, handleRo
Authorization: `Bearer ${token}`
}
}
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/promote_member/`,{
const res = await axios.post(`/api/community/${community}/promote_member/`,{
username: member.username,
role: role.current.toLowerCase()

Expand Down Expand Up @@ -355,7 +355,7 @@ const AddModal = ({community, setShowAddModal, loading, setLoading, onAdd}) => {
Authorization: `Bearer ${token}`
}
}
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/promote_member/`,{
const res = await axios.post(`/api/community/${community}/promote_member/`,{
username: username.current,
role: "member",
}, config);
Expand Down
4 changes: 2 additions & 2 deletions src/Components/NavBar/NavBar.jsx
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'
import './NavBar.css'
import {SlUser} from 'react-icons/sl';
import axios from 'axios';
import axios from '../../utils/axios';
import Popper from "popper.js";
import {useNavigate} from 'react-router-dom';
import {CiMenuFries} from 'react-icons/ci';
Expand Down Expand Up @@ -41,7 +41,7 @@ const NavBar = () => {

const getCurrentUser = async () => {
try {
const response = await axios.get('https://scicommons-backend-vkyc.onrender.com/api/user/get_current_user/', {
const response = await axios.get('/api/user/get_current_user/', {
headers: {
Authorization: `Bearer ${token}`,
},
Expand Down
14 changes: 7 additions & 7 deletions src/Components/Post/Post.jsx
Expand Up @@ -6,7 +6,7 @@ import { Link, useNavigate } from 'react-router-dom';
import { SlUser } from 'react-icons/sl';
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';
import axios from 'axios';
import axios from '../../utils/axios';
import Popper from 'popper.js';
import ToastMaker from 'toastmaker';
import "toastmaker/dist/toastmaker.css";
Expand Down Expand Up @@ -39,7 +39,7 @@ const Post = ({ post, onDeletePost, handleEditChange }) => {
}
if(liked) {
try{
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/feed/unlike/`,{post: post.id}, config)
const res = await axios.post(`/api/feed/unlike/`,{post: post.id}, config)
setLiked((prevLiked) => !prevLiked)
setLikes((prevLikes) => prevLikes - 1)
} catch(err) {
Expand All @@ -49,7 +49,7 @@ const Post = ({ post, onDeletePost, handleEditChange }) => {
}
else {
try{
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/feed/like/`,{post: post.id}, config)
const res = await axios.post(`/api/feed/like/`,{post: post.id}, config)
setLiked((prevLiked) => !prevLiked)
setLikes((prevLikes) => prevLikes + 1)
} catch(err) {
Expand Down Expand Up @@ -80,7 +80,7 @@ const Post = ({ post, onDeletePost, handleEditChange }) => {
}
if(bookmark) {
try{
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/feed/unbookmark/`,{post: post.id}, config)
const res = await axios.post(`/api/feed/unbookmark/`,{post: post.id}, config)
setBookmark((prevBookmark) => !prevBookmark)
setBookmarks((prevBookmarks) => prevBookmarks - 1)
} catch(err) {
Expand All @@ -91,7 +91,7 @@ const Post = ({ post, onDeletePost, handleEditChange }) => {
}
else {
try{
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/feed/bookmark/`,{post: post.id}, config)
const res = await axios.post(`/api/feed/bookmark/`,{post: post.id}, config)
setBookmark((prevBookmark) => !prevBookmark)
setBookmarks((prevBookmarks) => prevBookmarks + 1)
} catch(err) {
Expand Down Expand Up @@ -290,7 +290,7 @@ const Dropdown = ({post, onDeletePost, handleEditChange}) => {
};
try{

const res = await axios.delete(`https://scicommons-backend-vkyc.onrender.com/api/feed/${post.id}/`, config);
const res = await axios.delete(`/api/feed/${post.id}/`, config);
await onDeletePost(post.id);
ToastMaker("Post Deleted Successfully", "success")
} catch(err) {
Expand Down Expand Up @@ -415,7 +415,7 @@ const PostEditModal = ({post, setShowEdit, handleEditChange}) => {
if(form_data.get('image') === null) {
form_data.delete('image');
}
const res = await axios.put(`https://scicommons-backend-vkyc.onrender.com/api/feed/${post.id}/`, form_data, config);
const res = await axios.put(`/api/feed/${post.id}/`, form_data, config);
ToastMaker('Post Edited Successfully', 3500,{
valign: 'top',
styles : {
Expand Down
12 changes: 6 additions & 6 deletions src/Components/SocialComment/SocialComment.jsx
Expand Up @@ -11,7 +11,7 @@ import ReactQuill from "react-quill";
import "react-quill/dist/quill.snow.css";
import ToastMaker from "toastmaker";
import "toastmaker/dist/toastmaker.css";
import axios from "axios";
import axios from '../../utils/axios';
import "./SocialComment.css";
import { useParams, useNavigate } from "react-router-dom";
import { SlUser } from "react-icons/sl";
Expand Down Expand Up @@ -49,7 +49,7 @@ const ReplyModal = ({ comment, setShowReply, handleReply, addReply }) => {
};
try {
const res = await axios.post(
`https://scicommons-backend-vkyc.onrender.com/api/feedcomment/`,
`/api/feedcomment/`,
{ post: postId, comment: body, parent_comment: comment.id },
config
);
Expand Down Expand Up @@ -157,7 +157,7 @@ const EditModal = ({ comment, setShowEdit, changeComment }) => {
}
try {
const res = await axios.put(
`https://scicommons-backend-vkyc.onrender.com/api/feedcomment/${comment.id}/`,
`/api/feedcomment/${comment.id}/`,
{ post: comment.post, comment: body },
config
);
Expand Down Expand Up @@ -251,7 +251,7 @@ const SocialComment = ({ comment, post,setPost }) => {
if (liked) {
try {
const res = await axios.post(
`https://scicommons-backend-vkyc.onrender.com/api/feedcomment/unlike/`,
`/api/feedcomment/unlike/`,
{ comment: comment.id },
config
);
Expand All @@ -263,7 +263,7 @@ const SocialComment = ({ comment, post,setPost }) => {
} else {
try {
const res = await axios.post(
`https://scicommons-backend-vkyc.onrender.com/api/feedcomment/like/`,
`/api/feedcomment/like/`,
{ comment: comment.id },
config
);
Expand Down Expand Up @@ -320,7 +320,7 @@ const SocialComment = ({ comment, post,setPost }) => {
}
try {
const res = await axios.get(
`https://scicommons-backend-vkyc.onrender.com/api/feedcomment/?limit=20&offset=${repliesData.length}`,
`/api/feedcomment/?limit=20&offset=${repliesData.length}`,
config
);
let temp = {...post};
Expand Down
10 changes: 5 additions & 5 deletions src/Context/StateContext.jsx
@@ -1,5 +1,5 @@
import axios from 'axios';
import React, { useContext, useEffect, useRef, useState } from 'react';
import axios from "../utils/axios";


const AppContext = React.createContext()
Expand All @@ -18,13 +18,13 @@ const AppProvider = ({ children }) => {

const getCurrentUser = async () => {
try {
const token = localStorage.getItem('token');
const response = await axios.get('https://scicommons-backend-vkyc.onrender.com/api/user/get_current_user/', {
const token = localStorage.getItem('token');

const response = await axios.get('/api/user/get_current_user/', {
headers: {
Authorization: `Bearer ${token}`,
},
});
});
const user = response.data.success;
await loadUserData(user);
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions src/Pages/AdminArticlePage/AdminArticlePage.jsx
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from "react";
import axios from "axios";
import axios from '../../utils/axios';
import {useNavigate} from 'react-router-dom';
import Loader from "../../Components/Loader/Loader";
import ToastMaker from "toastmaker";
Expand All @@ -20,7 +20,7 @@ const AcceptModal = ({setShowAccept,article,community, handleModified}) => {
"Content-Type": "application/json",
}
}
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/article/${article}/approve_for_review/`,{community: community}, config)
const res = await axios.post(`/api/article/${article}/approve_for_review/`,{community: community}, config)
await handleModified(article);
if(res.status === 200){
ToastMaker(res.data.success, 3500,{
Expand Down Expand Up @@ -68,7 +68,7 @@ const RejectModal = ({setShowReject,article,community, handleReject}) => {
Authorization: `Bearer ${token}`
}
}
const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/article/${article}/reject_article/`,{community:community}, config)
const res = await axios.post(`/api/article/${article}/reject_article/`,{community:community}, config)
await handleReject(article)
if(res.status === 200){
ToastMaker(res.data.success, 3500,{
Expand Down Expand Up @@ -139,7 +139,7 @@ const PublishModal = ({setShowPublish,article,community}) => {
}
}

const res = await axios.post(`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/article/${article}/publish/`,form_data, config)
const res = await axios.post(`/api/community/${community}/article/${article}/publish/`,form_data, config)
if(res.status === 200){
ToastMaker(res.data.success, 3500,{
valign: 'top',
Expand Down Expand Up @@ -261,7 +261,7 @@ const AdminArticlePage = ({community}) => {
};
try {
const response = await axios.get(
`https://scicommons-backend-vkyc.onrender.com/api/community/${community}/articles/`,
`/api/community/${community}/articles/`,
config
);
await loadData(response.data.success);
Expand Down