Skip to content

Commit

Permalink
FS: matches and request route bug-fix || PeopleListCard U/.UX
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav Bhattarai committed Jan 5, 2021
1 parent e13f979 commit 915f62a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
3 changes: 2 additions & 1 deletion client/src/Components/PeopleListCard/people-list-card.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { Fragment } from 'react';
import './people-list-card.scss';

const PeopleListCard = ({ profile_picture, username }) => {
const PeopleListCard = ({ profile_picture, username, lastupdate }) => {
return (
<Fragment>
<main className='people-list-card-container'>
<img src={ profile_picture } alt='profile-pic'/>
<div className='people-list-card-container-desc-area'>
<header>{ username }</header>
<footer>LastUpdatedAt: { lastupdate }</footer>
</div>
</main>
</Fragment>
Expand Down
23 changes: 17 additions & 6 deletions client/src/Components/PeopleListCard/people-list-card.scss
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
.people-list-card-container{
width: 100%;
height: 40px;
padding: 10px 3%;
padding: 20px 3%;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: flex-start;
margin-top: 5px;
background-color: rgb(219, 219, 219);

img{
width: 35px;
height: 35px;
width: 55px;
height: 55px;
border-radius: 50%;
}

&-desc-area{
width: 70%;
width: 60%;
margin-left: 5%;
display: flex;
flex: column;
flex-direction: column;

header{
font-weight: 500;
font-size: 15px;
font-size: 23px;
padding: 2px 2%;
letter-spacing: 2px;
}

footer{
font-weight: 500;
font-size: 15px;
color: grey;
margin-top: 2px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
28 changes: 14 additions & 14 deletions client/src/Containers/MainPage/mainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,15 @@ const MainPage = ({ authenticate }) => {

const AddMatchData = (pp, username)=>{
const match_data = [...people_list];
match_data.unshift({username: username, Profile_Picture: pp});
const current_date = new Date(parseInt(Date.now())).toLocaleDateString();
match_data.unshift({username: username, Profile_Picture: pp, Messages: [], LastInteraction: current_date});
SetPeopleList(match_data);
}

const RemoveRequestSectionBackend = (username)=>{
const context = {
YourName: localStorage.getItem('Username'),
FriendName: username
}

axios.post('/friend-requests', context).then(()=>{})
}

Expand All @@ -183,7 +182,7 @@ const MainPage = ({ authenticate }) => {
RemoveRequestSectionBackend(username);
RemoveRequestData(username);
AddMatchData(profile_image, username);
AddToMatchesBackend(username, profile_image);
// AddToMatchesBackend(username, profile_image);
SendSocketMatch(username);
}

Expand All @@ -195,16 +194,16 @@ const MainPage = ({ authenticate }) => {

const FetchMatches = ()=>{
axios.get(`/matches/${localStorage.getItem('Username')}`).then((response)=>{
const error = {error_type: 'Username', message: 'Wrong Username'}
const no_match = {no_matches: true}
const error = {error_type: 'Username', message: 'Wrong Username'};
const no_res = {no_matches: true};
if(JSON.stringify(response.data) !== JSON.stringify(error)){
if(JSON.stringify(response.data) === JSON.stringify(no_match)){
SetPeopleList('use-default-page');
}else{
if(JSON.stringify(response.data) !== JSON.stringify(no_res)){
SetPeopleList(response.data.data);
}else{
SetPeopleList([]);
}
}else{
SetPeopleList('use-default-page');
SetPeopleList([]);
}
})
}
Expand Down Expand Up @@ -299,7 +298,7 @@ const MainPage = ({ authenticate }) => {

let people_list_jsx = null;
if(people_list){
if( people_list === 'use-default-page' ){
if( people_list.length === 0 ){
people_list_jsx = <Nodata/>
}else{
if(current_sidebar_value === 0){
Expand All @@ -311,8 +310,9 @@ const MainPage = ({ authenticate }) => {
return (
<PeopleListCard
key={i}
profile_picture= { user.Profile_Picture }
profile_picture = { user.Profile_Picture }
username = { user.username }
lastupdate = { user.LastInteraction }
/>
)
})
Expand Down Expand Up @@ -348,7 +348,7 @@ const MainPage = ({ authenticate }) => {
// use Default page
request_list_jsx = <Nodata/>;
}else{
const request_list = [...requests]
const request_list = [...requests];
if(current_request_bar_value === 0){
request_list_jsx = (
<RequestListContainer>
Expand All @@ -370,7 +370,7 @@ const MainPage = ({ authenticate }) => {
}else{
request_list_jsx = (
<RequestListContainer>

</RequestListContainer>
);
}
Expand Down
21 changes: 5 additions & 16 deletions server/Routes/friend-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,16 @@ router.put('/', (req, res)=>{
})

router.post('/', (req, res)=>{
const YourName = req.body.YourName;
const FriendName = req.body.FriendName;
RegisterModel.findOne({ Username: YourName }).exec().then((my_profile)=>{
const Requests = [...my_profile.Requests];
RegisterModel.findOne({ Username: FriendName }).exec().then((profile)=>{
const Requests = [...profile.Requests];
const index = Requests.findIndex((element)=>{
return element.sender === FriendName;
});
Requests.splice(index, 1);
my_profile.Requests = Requests;
my_profile.save().then(()=>{
RegisterModel.findOne({ Username: FriendName }).exec().then((friend_profile)=>{
const friend_profile_Requests = [...my_profile.Requests];
const friend_profile_index = friend_profile_Requests.findIndex((element)=>{
return element.sender === YourName;
});
friend_profile_Requests.splice(friend_profile_index, 1);
friend_profile.Requests = friend_profile_Requests;
friend_profile.save().then(()=>{
return res.json({ request_deleted: true })
});
})
profile.Requests = Requests;
profile.save().then(()=>{
return res.json({request_deleted: true});
})
})
})
Expand Down
4 changes: 4 additions & 0 deletions server/Routes/matches-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ router.post('/', (req, res)=>{
receiver_profile.save().then(()=>{
return res.json({'matched': true});
})
}else{
return res.json({not_added_to_matches: true});
}
})
})
}else{
return res.json({not_added_to_matches: true});
}
})
});
Expand Down

0 comments on commit 915f62a

Please sign in to comment.