Skip to content

Commit

Permalink
FS: Settings page removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav Bhattarai committed Jan 21, 2021
1 parent 1bbdeb8 commit 42add66
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 102 deletions.
1 change: 1 addition & 0 deletions client/debug.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[0118/163331.464:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[0119/093126.682:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[0121/094456.011:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[0121/162819.573:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
26 changes: 17 additions & 9 deletions client/src/Containers/MainPage/mainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -606,23 +606,23 @@ const MainPage = ({ authenticate, history }) => {
// Check for post of the matches and deleting that from the new post list;
if (temp_post_list && people_list) {
// O(n.log(n));
const post_list = [...temp_post_list]; // Username
const dummy_list = [...post_list]; // username
const post_list_dummy = [...temp_post_list]; // Username
const dummy_list = [...post_list_dummy]; // username
const matches = [...people_list];
let deletion_num = 0;
if (post_list.length >= 1 && matches.length >= 1) {
if (post_list_dummy.length >= 1 && matches.length >= 1) {
let match = 0;
// O(nlog(n)); WCS = 400 || BCS = O(1) === 1;
for (match of matches) {
let PostListLowerIndex = 0;
let PostListGreatestIndex = post_list.length - 1;
let PostListGreatestIndex = post_list_dummy.length - 1;

while (PostListLowerIndex <= PostListGreatestIndex) {
// Find the mid index
const PostListMidIndex = Math.floor(
(PostListLowerIndex + PostListGreatestIndex) / 2
);
const MidIndexUsername = post_list[PostListMidIndex].Username;
const MidIndexUsername = post_list_dummy[PostListMidIndex].Username;
// If element is present at mid, return True
if (MidIndexUsername === match.username) {
dummy_list.splice(PostListMidIndex - deletion_num, 1);
Expand All @@ -640,19 +640,27 @@ const MainPage = ({ authenticate, history }) => {
}
}
}
SetPostList(dummy_list);
if(post_list){
const posts = [...post_list];
let new_posts = 0;
for (new_posts of dummy_list){
posts.push((new_posts));
};
SetPostList(posts);
}else{
SetPostList(dummy_list);
}
SetTempPostList(null);
SetMileStone(Math.floor(dummy_list.length / 2) + 1);
SetMileStone(Math.floor(post_list.length / 2) + 1);
SetCurrentIndex(0);
if (dummy_list.length <= 20) {
SetApiLimiter(true);
}
} else {
SetPostList(temp_post_list);
SetTempPostList(null);
}
}
}, [temp_post_list, people_list]);
}, [temp_post_list, people_list, post_list]);

const FetchDirectURLMessages = useCallback(
(username) => {
Expand Down
36 changes: 16 additions & 20 deletions client/src/Containers/Settings/Settings Body/settings-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import Simplebar from "simplebar-react";
import "simplebar/dist/simplebar.min.css";
import { AddIcon } from "../Settings Header/settings-header";
import axios from "axios";
import { withRouter } from 'react-router-dom';

const SettingsBody = ({ Profile, ChangeProfile }) => {
const SettingsBody = ({ Profile, ChangeProfile, history }) => {
const InputRef = useRef(null);
const [ new_profile, SetNewProfile ] = useState(Profile);
const [ profile_condition, SetProfileCondition ] = useState(false);
const [ username_condition, SetUsernameCondition ] = useState(false);
const [ username, SetUsername ] = useState(localStorage.getItem("Username"));

const ChangeNewProfile = (event) => {
Expand All @@ -16,6 +19,7 @@ const SettingsBody = ({ Profile, ChangeProfile }) => {
const reader = new FileReader();
reader.onloadend = () => {
SetNewProfile(reader.result);
SetProfileCondition(true);
};
reader.readAsDataURL(file);
}
Expand All @@ -24,34 +28,26 @@ const SettingsBody = ({ Profile, ChangeProfile }) => {
const UsernameChange = (event) => {
const value = event.target.value;
SetUsername(value);
if(localStorage.getItem('Username') !== value && value.length >= 4){
if(username_condition === false){
SetUsernameCondition(true);
}
}else{
SetUsernameCondition(false);
}
};

const SubmitChanges = (event)=>{
event.preventDefault();
if(new_profile && localStorage.getItem('Username') !== username && username.length >= 4){
if(profile_condition || username_condition){
const context = {
ProfilePicture: new_profile,
Username: username
}
axios.put('http://localhost:8000/change-settings/both', context).then(()=>{
axios.put(`http://localhost:8000/change-settings/${localStorage.getItem('Username')}`, context).then(()=>{
localStorage.setItem('Username', username);
ChangeProfile(new_profile);
});
}
else if(new_profile){
const context = {
ProfilePicture: new_profile
}
axios.put('http://localhost:8000/change-settings/profile', context).then(()=>{
ChangeProfile(new_profile);
});
}
else if(localStorage.getItem('Username') !== username && username.length >= 4){
const context = {
Username: username
}
axios.put('http://localhost:8000/change-settings/username', context).then(()=>{
localStorage.setItem('Username', username);
history.push('/posts');
});
}
}
Expand Down Expand Up @@ -97,4 +93,4 @@ const SettingsBody = ({ Profile, ChangeProfile }) => {
);
};

export default SettingsBody;
export default withRouter(SettingsBody);
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
margin: 10px auto;
transition: background 0.3s;

&:focus{
outline: none;
}

&:hover{
background-color: #e6415f;
}
Expand Down
105 changes: 34 additions & 71 deletions server/Routes/change-settings.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,39 @@
import express from "express";
import redis from 'redis';
import RegistrationModel from "../Models/register-model";
// import express from "express";
// import redis from 'redis';
// import RegistrationModel from "../Models/register-model.js";

const caches = redis.createClient();
const router = express.Router();
// const caches = redis.createClient();
// const router = express.Router();

router.put("/:type/:Username", (req, res) => {
const type = req.params.type;
// router.put("/:Username", (req, res) => {

RegistrationModel.findOne({Username: req.params.Username}).exec().then((response)=>{
if(response){
const error = {error: true};
if (type === "both") {
const ProfilePicture = req.body.ProfilePicture;
const Username = req.body.Username;
if(ProfilePicture && Username){
response.Username = Username;
response.ProfilePicture = ProfilePicture;
}else{
return res.json(error)
}
}

else if (type === "profile") {
const ProfilePicture = req.body.ProfilePicture;
if(ProfilePicture){
response.ProfilePicture = ProfilePicture;
}else{
return res.json(error);
}
}

else {
const Username = req.body.Username;
if(Username){
response.Username = Username;
}else{
return res.json(error)
}
}
// RegistrationModel.findOne({Username: req.params.Username}).exec().then((response)=>{
// if(response){
// const error = {error: true};
// const ProfilePicture = req.body.ProfilePicture;
// const Username = req.body.Username;
// if(ProfilePicture && Username){
// if(response.Username !== Username && Username.length >= 4){
// response.Username = Username;
// }
// if(response.ProfilePicture !== ProfilePicture && ProfilePicture.length >= 10){
// response.ProfilePicture = ProfilePicture;
// }
// caches.del(`profile-pic/${req.params.Username}`, ()=>{
// caches.set(`profile-pic/${req.body.Username}`, response.ProfilePicture, ()=>{
// response.save().then(()=>{
// return res.json({updated: true});
// }).catch(()=>{
// return res.json(error)
// })
// })
// })
// }else{
// return res.json(error)
// }
// }
// })

if(type === "both" || type === "profile"){
if(type === "both"){
caches.del(`profile-pic/${req.params.Username}`, ()=>{
caches.set(`profile-pic/${req.body.Username}`, response.ProfilePicture, ()=>{
response.save().then(()=>{
return res.json({updated: true});
}).catch(()=>{
return res.json(error)
})
})
})
}else{
caches.set(`profile-pic/${req.params.Username}`, response.ProfilePicture, ()=>{
response.save().then(()=>{
return res.json({updated: true});
}).catch(()=>{
return res.json(error)
})
})
}
}else{
response.save().then(()=>{
return res.json({updated: true});
}).catch(()=>{
return res.json(error)
})
}
// });

}
})

});

export default router;
// export default router;
4 changes: 2 additions & 2 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ProfileConfirmRoute from './Routes/profile-confirm.js';
import PostReactRoute from './Routes/change-reacted-profile.js';
import NotificationRoute from './Routes/notifications.js';
import CrashNotifyRoute from './Routes/crash-notification.js';
import ChangeSettingsRoute from './Routes/change-settings.js';
// import ChangeSettingsRoute from './Routes/change-settings.js';

dotenv.config();

Expand Down Expand Up @@ -81,7 +81,7 @@ app.use('/profile-confirm', ProfileConfirmRoute);
app.use('/post-react', PostReactRoute);
app.use('/add-notification', NotificationRoute);
app.use('/crash-notification', CrashNotifyRoute);
app.use('/change-settings', ChangeSettingsRoute);
// app.use('/change-settings', ChangeSettingsRoute);

// DB connection
mongoose.connect(process.env.URI, {useNewUrlParser: true, useUnifiedTopology: true}).then(()=>{
Expand Down

0 comments on commit 42add66

Please sign in to comment.