Skip to content

Commit

Permalink
FS: notification-bug-fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav Bhattarai committed Jan 15, 2021
1 parent 3033b38 commit ceed5cd
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 40 deletions.
1 change: 1 addition & 0 deletions client/debug.log
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
[0114/100932.186:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[0114/123718.140:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[0114/174328.094:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[0115/100922.816:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import React, { Fragment, useRef } from 'react';
import '../Signup/signup.scss';
import { TimesIcon } from '../Signup/signup';
import { Error } from '../Login/login';

const PasswordChange = ({ SubmitChange, password, confirm, ChangePasswordValue, ChangeConfirmValue, Cancel }) => {
const PasswordChange = ({ SubmitChange, password, confirm, ChangePasswordValue, ChangeConfirmValue, Cancel, error }) => {

const UsernameRef = useRef(null);
const PasswordRef = useRef(null);

let password_error_jsx = null;
let confirm_error_jsx = null;
let cred_error_jsx = null

if(error){
if(error === 'length'){
UsernameRef.current.style.border = '1px solid #ff385c';
password_error_jsx = <Error error_msg = 'Password should be atleast 8 characters long'/>
}
else if(error === 'Number'){
UsernameRef.current.style.border = '1px solid #ff385c';
password_error_jsx = <Error error_msg = 'Password should contain number'/>
}

else if(error === 'no match'){
PasswordRef.current.style.border = '1px solid #ff385c';
confirm_error_jsx = <Error error_msg = "Password's do not match"/>
}
else{
UsernameRef.current.style.border = '1px solid #ff385c';
PasswordRef.current.style.border = '1px solid #ff385c'
cred_error_jsx = <div className='invalid-cred-error'>Invalid Credentials</div>;
}
}

return (
<Fragment>
<main className='signup-container login-container'>
Expand All @@ -17,6 +43,7 @@ const PasswordChange = ({ SubmitChange, password, confirm, ChangePasswordValue,
fontSize: '18px'
}}>Login to Continue</div>
</header>
{ cred_error_jsx }
<form onSubmit = { SubmitChange }>

<main className='signup-input-container'>
Expand All @@ -31,6 +58,7 @@ const PasswordChange = ({ SubmitChange, password, confirm, ChangePasswordValue,
value={ password }
ref={ UsernameRef }
/>
{ password_error_jsx }
</div>

<label>Confirm Password</label>
Expand All @@ -42,6 +70,7 @@ const PasswordChange = ({ SubmitChange, password, confirm, ChangePasswordValue,
value={ confirm }
ref={ PasswordRef }
/>
{ confirm_error_jsx }
</div>

</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Fragment } from 'react';
import './notification-card.scss';

const NotificationCard = ({ sender, profile }) => {
console.log(sender, profile);
return (
<Fragment>
<main className='notification-card-container'>
Expand Down
18 changes: 17 additions & 1 deletion client/src/Containers/LandingPage/landingPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const LandingPage = ({ authenticate }) => {
const [ new_password_popup, SetNewPasswordPopup ] = useState( false );
const [ new_password_password, SetNewPassword ] = useState( '' );
const [ new_password_confirm, SetPasswordConfirm ] = useState( '' );
const [ new_password_err, SetNewPasswordErr ] = useState( null );

const SignupCardHandler = ()=>{
SetSignupCard(!signup_card)
Expand Down Expand Up @@ -107,8 +108,20 @@ const LandingPage = ({ authenticate }) => {
SetNewPasswordPopup(false);
}else{
// error's;
SetNewPasswordErr('Cred');
}
});
}else{
SetNewPasswordErr('Number');
}
}else{

if(new_password_password.length < 8){
SetNewPasswordErr('length');
}

else if(new_password_confirm !== new_password_password){
SetNewPasswordErr('no match');
}
}
}
Expand Down Expand Up @@ -246,9 +259,11 @@ const LandingPage = ({ authenticate }) => {
SetForgetCard(false);
SetNewPasswordPopup(true);
}else{
SetForgetCredError('Wrong Number input');
SetForgetCredError('Wrong OTP entered');
}
})
}else{
SetForgetCredError('The OTP length should be 5 characters');
}
};

Expand Down Expand Up @@ -358,6 +373,7 @@ const LandingPage = ({ authenticate }) => {
ChangeConfirmValue = { (e) => ChangeNewPasswordConfirm(e) }
SubmitChange = { (e) => SubmitNewPassword(e) }
Cancel = { ()=> SetNewPasswordPopup(false) }
error = { new_password_err }
/>
: null
}
Expand Down
99 changes: 62 additions & 37 deletions client/src/Containers/MainPage/mainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ const MainPage = ({ authenticate, history, match }) => {
authenticate(true);
};

const NotifyInPeoplaCard = (sender)=>{
const AddMessagePopupAudio = ()=>{
// add audio effect for new message;
}

const NotifyInPeopleCard = (sender)=>{
if(joined_room !== sender){
const dummy = [...people_list];
const findSender = dummy.findIndex((element)=>{
Expand All @@ -301,6 +305,7 @@ const MainPage = ({ authenticate, history, match }) => {
SetNavNotification([sender]);
}
}
AddMessagePopupAudio();
}
}

Expand Down Expand Up @@ -381,7 +386,7 @@ const MainPage = ({ authenticate, history, match }) => {
dummy.push({sender, profile});
SetNotificationList(dummy);
}else{
SetNotificationList({sender, profile});
SetNotificationList([{sender, profile}]);
}
}

Expand All @@ -401,6 +406,12 @@ const MainPage = ({ authenticate, history, match }) => {
})
}

const FetchNotifications = ()=>{
axios.get(`/add-notification/${localStorage.getItem('Username')}`).then((response)=>{
SetNotificationList(response.data)
});
}

const FetchFriendrequest = ()=>{
axios.get(`/friend-requests/${ localStorage.getItem('Username') }`).then((response)=>{
const error = {no_requests: true}
Expand Down Expand Up @@ -456,6 +467,9 @@ const MainPage = ({ authenticate, history, match }) => {

// this fetches my profile picture;
GetProfilePic();

// fetch notifications;
FetchNotifications();

// join my_sockek_room
JoinSocketRoom();
Expand Down Expand Up @@ -578,7 +592,7 @@ const MainPage = ({ authenticate, history, match }) => {
socket.on('receive-message-client', (sender, message)=>{
// Message Socket Receiver;
AddMessage(sender, message, false);
NotifyInPeoplaCard(sender);
NotifyInPeopleCard(sender);
})

socket.on('notification-client', ( from, profile_pic )=>{
Expand Down Expand Up @@ -644,48 +658,57 @@ const MainPage = ({ authenticate, history, match }) => {
}

let request_list_jsx = null;
if(requests){
if(requests && current_request_bar_value === 0){
if( requests.length === 0 ){
// use Default page
request_list_jsx = <Nodata/>;
}else{
const request_list = [...requests];
if(current_request_bar_value === 0){
request_list_jsx = (
<RequestListContainer>
{
request_list.map((request, i)=>{
return (
<RequestCard
key={i}
sender={ request.sender }
profile_picture= { request.ProfilePicture }
AcceptRequest={ (e, profile_image, username)=> AcceptMatchRequest(e, profile_image, username) }
DeclineRequest={ (e, username)=> RejectMatchRequest(e, username) }
request_list_jsx = (
<RequestListContainer>
{
request_list.map((request, i)=>{
return (
<RequestCard
key={i}
sender={ request.sender }
profile_picture= { request.ProfilePicture }
AcceptRequest={ (e, profile_image, username)=> AcceptMatchRequest(e, profile_image, username) }
DeclineRequest={ (e, username)=> RejectMatchRequest(e, username) }
/>
)
})
}
</RequestListContainer>
);
}
}

let notification_list_jsx = null
if(notification_list && current_request_bar_value === 1){
if(notification_list.length === 0){
notification_list_jsx = <Nodata/>;
}else{
const notification_dummy = [...notification_list]
notification_list_jsx = (
<RequestListContainer>
{
notification_dummy.map((notification, i)=>{
return <NotificationCard
key = { i }
sender = { notification.sender }
profile = { notification.ProfilePicture }
/>
)
})
}
</RequestListContainer>
);
}else{
request_list_jsx = (
<RequestListContainer>
{
notification_list.map((notification, i)=>{
return <NotificationCard
key = { i }
username = { notification.sender }
profile_picture = { notification.profile }
/>
})
}
</RequestListContainer>
);
}
})
}
</RequestListContainer>
);
}
}

console.log(notification_list_jsx);
console.log(request_list_jsx)


let post_area_jsx = null;
if(post_list){
Expand Down Expand Up @@ -849,7 +872,9 @@ const MainPage = ({ authenticate, history, match }) => {
TriggerNotificationNav={ (ref)=> TriggerNotificationNav(ref) }
TriggerRequestNav= { (ref)=>TriggerRequestNav(ref) }
/>
{ ( !request_list_jsx ) ? <LoadSpinner/> : request_list_jsx }
{ ( !request_list_jsx && current_request_bar_value === 0 ) ? <LoadSpinner/> : request_list_jsx }

{ ( notification_list_jsx && current_request_bar_value === 1 ) ? notification_list_jsx : null }
</RequestBar>

{ ( profile_alert ) ? <ImageConfig RemoveProfileCard={ TriggerProfileAlert }/> : null }
Expand Down
11 changes: 10 additions & 1 deletion server/Routes/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import RegistrationModel from '../Models/register-model.js';

const router = express.Router();

router.get('/:Username', (req, res)=>{
const Username = req.params.Username;
RegistrationModel.findOne({Username}).exec().then((response)=>{
if(response){
return res.json(response.Notification);
}
})
})

router.put('/', (req, res)=>{
const Sender = req.body.Sender;
const ProfilePicture = req.body.ProfilePicture;
const Username = req.body.Username;
RegistrationModel.findOne({Username: Username}).exec().then((response)=>{
if(response){
const dummy = [...response.Notification];
dummy.push({Sender, ProfilePicture});
dummy.push({sender: Sender, ProfilePicture});
response.Notification = dummy;
response.save().then(()=>{
return res.json({ notification_added: true });
Expand Down

0 comments on commit ceed5cd

Please sign in to comment.