Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
MONGO_URL = mongodb+srv://atrieu:Copycopy27@band.mrp7y.mongodb.net/social?retryWrites=true&w=majority
REACT_APP_PUBLIC_FOLDER = https://localhost:8800/images/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
build/
8 changes: 1 addition & 7 deletions index.js → anbm-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ app.use("/api/users", userRoute);
app.use("/api/auth", authRoute);
app.use("/api/posts", postRoute);

app.use(express.static(path.join(__dirname,"/anbm/build")));

app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname,'/anbm/build','index.html'));
});

app.listen(process.env.PORT || 8800, () => {
app.listen(8800, () => {
console.log("Backend sever is running!")
})
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 0 additions & 1 deletion routes/auth.js → anbm-api/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ router.post("/login", async (req, res) => {

res.status(200).json(user);
} catch (err) {
console.log(err);
res.status(500).json(err);
}
});
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion anbm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "GENERATE_SOURCEMAP=false && react-scripts build",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Expand Down
Empty file removed anbm/public/favicon.ico
Empty file.
2 changes: 1 addition & 1 deletion anbm/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="/assets/style.css">
<link rel="stylesheet" href="http://localhost:3000/assets/style.css">
<title>Social App</title>
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions anbm/src/apiCalls.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { axiosInstance } from "./config";
import axios from "axios";

export const loginCall = async (userCredentials, dispatch) => {
dispatch ({ type: "LOGIN_START"});
try{
const res = await axiosInstance.post("auth/login", userCredentials);
const res = await axios.post("auth/login", userCredentials);
dispatch ({ type: "LOGIN_SUCCESS", payload: res.data});
} catch (err){
dispatch ({ type: "LOGIN_FAILURE", payload: err});
Expand Down
6 changes: 3 additions & 3 deletions anbm/src/components/mainfeed/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import "./feed.css";
import Post from "../post/Post";
import Share from "../share/Share";
import { useContext, useEffect, useState } from "react";
import axios from "axios"
import { AuthContext } from "../../context/AuthContext";
import { axiosInstance } from "../../config";

export default function Feed({ username }) {
const [posts, setPosts] = useState([])
const { user } = useContext(AuthContext)
useEffect(() => {
const fetchPosts = async () => {
const res = username
? await axiosInstance.get("/posts/profile/" + username)
: await axiosInstance.get("posts/timeline/" + user._id)
? await axios.get("/posts/profile/" + username)
: await axios.get("posts/timeline/" + user._id)
setPosts(res.data)
};
fetchPosts();
Expand Down
10 changes: 5 additions & 5 deletions anbm/src/components/post/Post.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "./post.css"
import { MoreVert, ThumbDown, ThumbUp, Comment, Save, Share } from "@material-ui/icons"
import { useState, useEffect, useContext } from "react";
import axios from "axios"
import { format } from "timeago.js"
import { Link } from "react-router-dom";
import { AuthContext } from "../../context/AuthContext";
import { axiosInstance } from "../../config";

export default function Post({ post }) {
const [like, setLike] = useState(post.likes.length)
Expand All @@ -13,7 +13,7 @@ export default function Post({ post }) {
const { user: currentUser } = useContext(AuthContext)
const likeHandler = () => {
try {
axiosInstance.put("/posts/" + post._id + "/like", { userId: currentUser._id })
axios.put("/posts/" + post._id + "/like", { userId: currentUser._id })
} catch (err) {

}
Expand All @@ -24,7 +24,7 @@ export default function Post({ post }) {
const [isDisliked, setIsDisliked] = useState(false)
const dislikeHandler = () => {
try {
axiosInstance.put("/posts/" + post._id + "/dislike", { userId: currentUser._id })
axios.put("/posts/" + post._id + "/dislike", { userId: currentUser._id })
} catch (err) {

}
Expand All @@ -40,7 +40,7 @@ export default function Post({ post }) {

useEffect(() => {
const fetchUser = async () => {
const res = await axiosInstance.get(`/users?userId=${post.userId}`)
const res = await axios.get(`/users?userId=${post.userId}`)
setUser(res.data)
};
fetchUser();
Expand All @@ -52,7 +52,7 @@ export default function Post({ post }) {
<div className="postLeft">
<div className="postLeftTop">
<div className="postLeftTopLeft">
<Link to={`/profile/${user.username}`}>
<Link to={`profile/${user.username}`}>
<img
className="postProfileImg"
src={user.profilePicture ? PF + user.profilePicture : PF + "profile/noAvatar.png"}
Expand Down
2 changes: 1 addition & 1 deletion anbm/src/components/rightsidebar/Rightsidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ export default function Rightsidebar({ user }) {
</div>
</div>
);
}
}
75 changes: 63 additions & 12 deletions anbm/src/components/share/Share.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,73 @@
import "./share.css"
import { PermMedia, Label, Room, EmojiEmotions } from "@material-ui/icons"
import { PermMedia, Label, Room, EmojiEmotions, Cancel } from "@material-ui/icons"
import { useContext, useRef, useState } from "react";
import { AuthContext } from "../../context/AuthContext";
import axios from "axios";

export default function Share() {
const { user } = useContext(AuthContext);
const PF = process.env.REACT_APP_PUBLIC_FOLDER;
const desc = useRef();
const [file, setFile] = useState(null);

const submitHandler = async (e) => {
e.preventDefault()
const newPost = {
userId: user._id,
desc: desc.current.value
}
if (file) {
const data = new FormData();
const fileName = Date.now() + file.name;
data.append("file", file)
data.append("name", fileName);
newPost.img = fileName;
try {
await axios.post("/upload", data)
} catch (err) {
console.log(err)
}
}

try {

await axios.post("/posts", newPost)
window.location.reload()
} catch (err) {

}
}
return (
<div className="share">
<div className="shareWrapper">
<div className="shareTop">
<img className="shareProfileImg" src="/assets/profile/template_3.jpg" alt="" />
<img className="shareProfileImg" src={user.profilePicture ? PF + user.profilePicture : PF + "profile/noAvatar.png"} alt="" />
<input
placeholder="what's in your mind Safak?"
placeholder={"what's in your mind" + user.username + "?"}
className="shareInput"
ref={desc}
/>
</div>
<hr className="shareHr" />
<div className="shareBottom">
{file && (
<div className="shareImgContainer">
<img className="shareImg" src={URL.createObjectURL(file)} alt="" />
<Cancel className="shareCancelImg" onClick={() => setFile(null)} />
</div>
)}
<form className="shareBottom" onSubmit={submitHandler}>
<div className="shareOptions">
<div className="shareOption">
<label htmlFor="file" className="shareOption">
<PermMedia htmlColor="tomato" className="shareIcon" />
<span className="shareOptionText">Photo or Video</span>
</div>
<input
style={{ display: "none" }}
type="file"
id="file"
accept=".png,.jpeg,.jpg"
onChange={(e) => setFile(e.target.files[0])}
/>
</label>
<div className="shareOption">
<Label htmlColor="blue" className="shareIcon" />
<span className="shareOptionText">Tag</span>
Expand All @@ -28,13 +77,15 @@ export default function Share() {
<span className="shareOptionText">Location</span>
</div>
<div className="shareOption">
<EmojiEmotions htmlColor="gold" className="shareIcon" />
<span className="shareOptionText">Feeling</span>
<EmojiEmotions htmlColor="goldenrod" className="shareIcon" />
<span className="shareOptionText">Feelings</span>
</div>
</div>
<button className="shareButton">Share</button>
</div>
<button className="shareButton" type="submit">
Share
</button>
</form>
</div>
</div>
)
}
);
}
3 changes: 2 additions & 1 deletion anbm/src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios"

export const axiosInstance = axios.create({
baseURL: "https://band-cs322.herokuapp.com/api"
//baseURL: "https://band-cs322.herokuapp.com/api/"
baseURL : "http://localhost:8800/api"
})
4 changes: 2 additions & 2 deletions anbm/src/pages/home/register/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./register.css";
import {Link} from "react-router-dom";
import { useRef } from "react";
import { useNavigate } from "react-router";
import { axiosInstance } from "../../../config";
import axios from "axios";

export default function Register(){
const username = useRef();
Expand All @@ -24,7 +24,7 @@ export default function Register(){
password: password.current.value,
};
try{
await axiosInstance.post("/auth/register", user);
await axios.post("/auth/register", user);
navigate("/login");
} catch (err) {
console.log(err)
Expand Down
4 changes: 2 additions & 2 deletions anbm/src/pages/profile/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import Rightsidebar from "../../components/rightsidebar/Rightsidebar";
import Feed from '../../components/mainfeed/Feed';
import NavBar from '../../components/NavBar/NavBar';
import { useEffect, useState } from "react";
import axios from "axios"
import { useParams } from "react-router"
import { axiosInstance } from "../../config";

export default function Profile() {
const PF = process.env.REACT_APP_PUBLIC_FOLDER;
const [user, setUser] = useState({})
const username = useParams().username;
useEffect(() => {
const fetchUser = async () => {
const res = await axiosInstance.get(`/users?username=${username}`)
const res = await axios.get(`/users?username=${username}`)
setUser(res.data)
};
fetchUser();
Expand Down
Loading