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

Integrated MUI & friendspage wip #12

Merged
merged 2 commits into from
Jan 5, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"react/jsx-no-constructed-context-values": "warn",
"react/no-unescaped-entities": "warn",
"react-hooks/exhaustive-deps": "warn",
"array-callback-return": "warn"
"array-callback-return": "warn",
"jsx-a11y/no-noninteractive-element-interactions": "warn"
}
}
20 changes: 20 additions & 0 deletions backend/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,24 @@ router.get('/allusers', requireLogin, async (req, res) => {
}
})

// save profile picture of users inside mongodb (through cloudinary)

router.put('/uploadProfilePic', requireLogin, async (req, res) => {
try {
const userData = await User.findByIdAndUpdate(
req.user._id,
{
$set: { Photo: req.body.pic },
},
{
new: true,
},
)
res.status(200).json({ success: true })
} catch (error) {
console.log(error)
res.status(422).json({ error: 'Something went wrong...' })
}
})

module.exports = router
2 changes: 2 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Signup from './components/Signup'
import Login from './components/Login'
import FriendsPage from './components/FriendsPage'
import Client from './components/Client'
import LogoutModal from './components/LogoutModal'
import { LoginContext } from './context/LoginContext'

require('dotenv').config()
Expand All @@ -29,6 +30,7 @@ function App() {
<Route path='/client' element={<Client />} />
</Routes>
</BrowserRouter>
{modalOpen ? <LogoutModal /> : ''}
</LoginContext.Provider>
</GoogleOAuthProvider>
</div>
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/components/Client.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import React from 'react'
import { useNavigate } from 'react-router-dom'
import Map from './Map'

function Client() {
return <Map />
const navigate = useNavigate()

const checker = () => {
if (localStorage.getItem('user') !== null) {
;<Map />
} else {
navigate('/login')
}
}

return <div>{checker()}</div>
}

export default Client
84 changes: 84 additions & 0 deletions frontend/src/components/FriendsCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react'
import '../styles/UserCard.css'
import { useNavigate } from 'react-router-dom'
import Button from '@mui/material/Button'

require('dotenv').config()

const PORT = process.env.PORT || 5050
const BASE_API_URI = `http://localhost:${PORT}`

function FriendsCard({
username,
name,
dpLink,
currentUsername,
user,
curruser,
users,
setUsers,
}) {
const navigate = useNavigate()

const handleUnFollow = id => {
fetch(`${BASE_API_URI}/api/unfollow`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${localStorage.getItem('jwt')}`,
},
body: JSON.stringify({
userID: id,
}),
})
.then(res => res.json())
.then(result => {
console.log(result)
const newUsers = users.filter(u => u._id !== id)
setUsers(newUsers)
// setIsFollow(true)
})
.catch(err => console.log(err))
}

return (
<>
{currentUsername !== username &&
curruser._id !== user._id &&
curruser.friends.includes(user._id) === true ? (
<div className='container'>
<div className='card_item'>
<div className='card_inner'>
<img src={dpLink} alt='' />
<div className='Name'>{name}</div>
<div className='userName'>{username}</div>
<div className='userUrl' />
<div className='detail-box'>
<div className='gitDetail'>
<span>College</span>JU
</div>
<div className='gitDetail'>
<span>Following</span>45
</div>
<div className='gitDetail'>
<span>Followers</span>11
</div>
</div>

{/* <Button className="top-margin" size="large" variant="contained" onClick={() => handleUnFollow(user._id)}>Remove Friend</Button> */}
<button
type='button'
className='removeFriend'
onClick={() => handleUnFollow(user._id)}
>
Remove Friend
</button>
</div>
</div>
</div>
) : null}
</>
)
}

export default FriendsCard
Loading
Loading