Skip to content

Commit

Permalink
FS: bUG FIXES
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav Bhattarai committed Jan 19, 2021
1 parent e3265a9 commit 8ac7198
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Route, Switch, withRouter } from 'react-router';
import ProfilePicture from './ProfilePicture/profile-picture';
import MainPost from './MainPost/main-post';

const ImageConfig = ({ history, RemoveProfileCard }) => {
const ImageConfig = ({ history, RemoveProfileCard, SetNewProfile }) => {

// state is manage from here;
const [ profile_pic, SetProfilePic ] = useState( null );
Expand Down Expand Up @@ -43,6 +43,7 @@ const ImageConfig = ({ history, RemoveProfileCard }) => {
const FinalizeProfile = (event)=>{
event.preventDefault();
if(profile_pic){
SetNewProfile(profile_pic);
history.push('/forms/mainpost')
}else{
// error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

.message-me {
margin-left: auto;
margin-right: 2%;
padding: 10px 3%;
background-color: $theme-color;
color: white;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MessageHeader = ({ Username, ProfilePicture, history }) => {
<header className='message-header'>
<span
onClick={
() => history.push('/main-app')
() => history.push('/main')
}
style = {{ marginRight: '2%', marginTop: '5px' }}

Expand Down
13 changes: 12 additions & 1 deletion client/src/Components/UI/MatchAlert/match-alert.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import React, { Fragment } from 'react';
import { IconContext } from 'react-icons';
import { FaHeart } from 'react-icons/fa';
import './match-alert.scss';

const LoveIcon = ()=>{
return (
<IconContext.Provider value={{ className: 'love-icon' }}>
<FaHeart/>
</IconContext.Provider>
)
}

const MatchAlert = () => {
return (
<Fragment>
<main className='match-alert-container'>

<LoveIcon/>
<div>You're a Match</div>
</main>
</Fragment>
)
Expand Down
35 changes: 35 additions & 0 deletions client/src/Components/UI/MatchAlert/match-alert.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@import '../../../_variables';

@keyframes glow{
from{
transform: scale(0.5);
filter: drop-shadow(10px $theme-color);
}
to{
transform: scale(1);
}
}

.love-icon{
font-size: 300px;
color: $theme-color;
}

.match-alert-container{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: fixed;
left: 40%;
top: 21%;
animation-name: glow;
animation-duration: 0.3s;

div{
font-weight: 800;
color: #333;
font-size: 22px;
margin-top: 15px;
}
}
34 changes: 18 additions & 16 deletions client/src/Containers/MainPage/mainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ const MainPage = ({ authenticate, history }) => {
SetJoinedRoom(null);
};

const SetNewProfile = (profile)=>{
SetMyProfilePic(profile);
}

const TwoWayMatchHandler = (context) => {
SetMatchFoundTimeout(true);
RemoveRequestData(context.FriendName);
AddMatchData(context.FriendName, context.FriendProfile);
AddMatchData(context.FriendProfile, context.FriendName);
AddToMatchesBackend(context.FriendName, context.FriendProfile);
RemoveRequestSectionBackend(context.FriendName);
};
Expand Down Expand Up @@ -355,10 +359,6 @@ const MainPage = ({ authenticate, history }) => {
authenticate(true);
};

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

const NotifyInPeopleCard = (sender) => {
if (joined_room !== sender) {
const dummy = [...people_list];
Expand All @@ -378,7 +378,6 @@ const MainPage = ({ authenticate, history }) => {
}
AudioPlay();
}
AddMessagePopupAudio();
}
};

Expand All @@ -395,7 +394,7 @@ const MainPage = ({ authenticate, history }) => {
const AddMatchData = (pp, username) => {
// Add to match data array after accepting match request;
const match_data = [...people_list];
const current_date = Date.now();
const current_date = Date.now().toString();
match_data.unshift({
username: username,
Profile_Picture: pp,
Expand Down Expand Up @@ -691,7 +690,7 @@ const MainPage = ({ authenticate, history }) => {
if(match_found_timeout){
setTimeout(()=>{
SetMatchFoundTimeout(false);
}, 2000);
}, 1000);
}
})

Expand Down Expand Up @@ -733,6 +732,8 @@ const MainPage = ({ authenticate, history }) => {
}
});

console.log(people_list)

let people_list_jsx = null;
if (people_list) {
if (current_sidebar_value === 0) {
Expand Down Expand Up @@ -841,7 +842,7 @@ const MainPage = ({ authenticate, history }) => {
const post_data = [...post_list];
const required_data = post_data[0];
post_area_jsx = (
<PostContainer blur={profile_alert || logout_popup ? "5px" : "0px"}>
<PostContainer blur={profile_alert || logout_popup || match_found_timeout ? "5px" : "0px"}>
<ImageContainer
ProfilePicture={required_data.ProfilePicture}
MainPost={required_data.MainPost}
Expand All @@ -856,15 +857,15 @@ const MainPage = ({ authenticate, history }) => {
);
} else {
post_area_jsx = (
<NoPost blur={profile_alert || logout_popup ? "5px" : "0px"} />
<NoPost blur={profile_alert || logout_popup || match_found_timeout ? "5px" : "0px"} />
);
}
}

return (
<Fragment>
<SideBar
blur={dropdown_info || profile_alert || logout_popup ? "5px" : "0px"}
blur={dropdown_info || profile_alert || logout_popup || match_found_timeout ? "5px" : "0px"}
>
<SidebarHeader
profile_picture={my_profile_pic}
Expand Down Expand Up @@ -908,7 +909,7 @@ const MainPage = ({ authenticate, history }) => {
>
{message_info ? (
<AsyncMessageRoute
blur={profile_alert || logout_popup ? "5px" : "0px"}
blur={profile_alert || logout_popup || match_found_timeout ? "5px" : "0px"}
MessageInputValue={messageInput}
ChangeMessageInput={(e) => ChangeMessageInput(e)}
RecentMessages={recent_messages}
Expand Down Expand Up @@ -937,7 +938,7 @@ const MainPage = ({ authenticate, history }) => {
>
{message_info ? (
<AsyncMessageRoute
blur={profile_alert || logout_popup ? "5px" : "0px"}
blur={profile_alert || logout_popup || match_found_timeout ? "5px" : "0px"}
MessageInputValue={messageInput}
ChangeMessageInput={(e) => ChangeMessageInput(e)}
RecentMessages={recent_messages}
Expand All @@ -958,7 +959,7 @@ const MainPage = ({ authenticate, history }) => {
return (
<Suspense fallback={<LogoPage />}>
<AsyncSettings
blur={profile_alert || logout_popup ? "5px" : "0px"}
blur={profile_alert || logout_popup || match_found_timeout ? "5px" : "0px"}
/>
</Suspense>
);
Expand Down Expand Up @@ -987,7 +988,7 @@ const MainPage = ({ authenticate, history }) => {
</main>
)}

<RequestBar blur={profile_alert || logout_popup ? "5px" : "0px"}>
<RequestBar blur={profile_alert || logout_popup || match_found_timeout ? "5px" : "0px"}>
<RequestHeader />
<RequestNav
TriggerNotificationNav={(ref) => TriggerNotificationNav(ref)}
Expand All @@ -1006,12 +1007,13 @@ const MainPage = ({ authenticate, history }) => {
</RequestBar>

{profile_alert ? (
<ImageConfig RemoveProfileCard={TriggerProfileAlert} />
<ImageConfig RemoveProfileCard={TriggerProfileAlert} SetNewProfile={(profile)=>SetNewProfile(profile)} />
) : null}

{
(match_found_timeout) ? <MatchAlert/> : null
}

</Fragment>
);
};
Expand Down
4 changes: 1 addition & 3 deletions server/Routes/change-reacted-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ router.put("/", (req, res) => {
})
.exec()
.then((response) => {
const dummy = [...response.ReactedProfiles];
dummy.push(ReactedPersonName);
response.ReactedProfiles = dummy.sort();
response.ReactedProfiles.push(ReactedPersonName);
response.save().then(() => {
cache.del(`posts/${MyName}`, () => {
return res.json({
Expand Down
13 changes: 4 additions & 9 deletions server/Routes/friend-request.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import express from 'express';
import redis from 'redis';
import RequestCache from '../Middleware/redis-request-cache.js';
// import RequestCache from '../Middleware/redis-request-cache.js';
import RegisterModel from '../Models/register-model.js';

const router = express.Router();
const cache = redis.createClient();

router.get('/:Username', RequestCache, (req, res)=>{
router.get('/:Username', (req, res)=>{
const Username = req.params.Username;
RegisterModel.find().where("Username").equals(Username).then((response)=>{
if(response.length === 1){
Expand All @@ -15,7 +15,7 @@ router.get('/:Username', RequestCache, (req, res)=>{
})

}else{
cache.set(`friend-req/${Username}`, JSON.stringify(response[0].Requests), ()=>{
cache.set(`friend-req/${Username}`, JSON.stringify({no_requests: true}), ()=>{
return res.json({no_requests: true});
})
}
Expand Down Expand Up @@ -52,13 +52,8 @@ router.put('/', (req, res)=>{
router.post('/', (req, res)=>{
const MyName = req.body.MyName;
const RequestName = req.body.RequestName;
console.log(MyName, RequestName);
RegisterModel.findOne({ Username: MyName }).exec().then((profile)=>{
const Requests = [...profile.Requests];
const index = Requests.findIndex((element)=>{
return element.sender === RequestName;
});
Requests.splice(index, 1);
const Requests = profile.Requests.filter(element=> element.sender !== RequestName)
profile.Requests = Requests;
profile.save().then(()=>{
cache.set(`friend-req/${MyName}`, JSON.stringify(Requests), ()=>{
Expand Down
1 change: 0 additions & 1 deletion server/Routes/login-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ router.post('/', (req, res)=>{
const Username = req.body.Username;
const Password = req.body.Password;

console.log(true);
// checking for the existance of the user provided credential;
RegisterModel.find().where('Username').equals(Username).then((response)=>{
if(response.length === 1){
Expand Down
10 changes: 5 additions & 5 deletions server/Routes/matches-route.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import express from 'express';
import UserModel from '../Models/user-model.js';
import redis from 'redis';
import MatchCache from '../Middleware/redis-match-cache.js';
// import MatchCache from '../Middleware/redis-match-cache.js';

const cache = redis.createClient();
const router = express.Router();

router.get('/:Username', MatchCache, (req, res)=>{
router.get('/:Username', (req, res)=>{
const Username = req.params.Username ;
UserModel.find().where("Username").equals(Username).then((response)=>{
if(response.length === 1){
const data = response[0].Matches;
if(data.length >= 1){
cache.set(`matches/${Username}`, JSON.stringify(data), ()=>{
return res.json({ data })
return res.json(data)
})
}else{
cache.set(`matches/${Username}`, JSON.stringify({no_matches: true}), ()=>{
Expand All @@ -36,13 +36,13 @@ router.post('/', (req, res)=>{
UserModel.findOne({Username: YourName}).exec().then((sender_profile)=>{
if(sender_profile){
const match_data = [...sender_profile.Matches];
match_data.push({ username: FriendName, Profile_Picture: FriendProfilePic });
match_data.push({ username: FriendName, Profile_Picture: FriendProfilePic, LastInteraction: Date.now(), Messages: [] });
sender_profile.Matches = match_data
sender_profile.save().then(()=>{
UserModel.findOne({ Username: FriendName }).exec().then((receiver_profile)=>{
if(receiver_profile){
const receiver_match_data = [...receiver_profile.Matches];
receiver_match_data.push({ username: YourName, Profile_Picture: YourProfilePic })
receiver_match_data.push({ username: YourName, Profile_Picture: YourProfilePic, LastInteraction: Date.now(), Messages: [] })
receiver_profile.Matches = receiver_match_data
receiver_profile.save().then(()=>{
cache.set(`matches/${YourName}`, JSON.stringify(match_data), ()=>{
Expand Down
4 changes: 2 additions & 2 deletions server/Routes/posts-route.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import express from 'express';
import RedisPostCache from '../Middleware/redis-post-cache.js';
// import RedisPostCache from '../Middleware/redis-post-cache.js';
import RegistrationModel from '../Models/register-model.js';
import redis from 'redis';

const cache = redis.createClient();

const router = express.Router();

router.get('/:number/:Username', RedisPostCache, (req, res)=>{
router.get('/:number/:Username', (req, res)=>{
const number = parseInt(req.params.number);
const Username = req.params.Username;

Expand Down

0 comments on commit 8ac7198

Please sign in to comment.