Skip to content

Commit

Permalink
fix: deleting a message not working (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dun-sin authored Sep 25, 2023
1 parent 60dfacf commit 3dfc41f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
2 changes: 1 addition & 1 deletion client/.eslintcache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\index.jsx":"1","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\Chat.jsx":"2","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\App.jsx":"3","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\BuddyMatcher.jsx":"4","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\NavBar.jsx":"5","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\AuthContext.jsx":"6","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\reducers\\authReducer.js":"7","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\pages\\Login.jsx":"8"},{"size":884,"mtime":1694964057426,"results":"9","hashOfConfig":"10"},{"size":17585,"mtime":1694967723092,"results":"11","hashOfConfig":"10"},{"size":2805,"mtime":1694963210343,"results":"12","hashOfConfig":"10"},{"size":5823,"mtime":1694963523692,"results":"13","hashOfConfig":"10"},{"size":6081,"mtime":1694967589027,"results":"14","hashOfConfig":"10"},{"size":2709,"mtime":1694962059116,"results":"15","hashOfConfig":"10"},{"size":1056,"mtime":1694963184111,"results":"16","hashOfConfig":"10"},{"size":1615,"mtime":1694964010596,"results":"17","hashOfConfig":"10"},{"filePath":"18","messages":"19","suppressedMessages":"20","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"9zzh3x",{"filePath":"21","messages":"22","suppressedMessages":"23","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","suppressedMessages":"26","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"27","messages":"28","suppressedMessages":"29","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"30","messages":"31","suppressedMessages":"32","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"33","messages":"34","suppressedMessages":"35","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"36","messages":"37","suppressedMessages":"38","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"39","messages":"40","suppressedMessages":"41","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\index.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\Chat.jsx",[],["42"],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\App.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\BuddyMatcher.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\NavBar.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\AuthContext.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\reducers\\authReducer.js",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\pages\\Login.jsx",[],[],{"ruleId":"43","severity":1,"message":"44","line":450,"column":1,"nodeType":"45","messageId":"46","endLine":450,"endColumn":87,"suppressions":"47"},"max-len","This line has a length of 86. Maximum allowed is 80.","Program","max",["48"],{"kind":"49","justification":"50"},"directive",""]
[{"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\index.jsx":"1","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\Chat.jsx":"2","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\App.jsx":"3","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\BuddyMatcher.jsx":"4","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\NavBar.jsx":"5","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\AuthContext.jsx":"6","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\reducers\\authReducer.js":"7","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\pages\\Login.jsx":"8","C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\lib\\badWords.js":"9"},{"size":884,"mtime":1694964057426,"results":"10","hashOfConfig":"11"},{"size":17509,"mtime":1695667339919,"results":"12","hashOfConfig":"11"},{"size":2805,"mtime":1694963210343,"results":"13","hashOfConfig":"11"},{"size":5823,"mtime":1694963523692,"results":"14","hashOfConfig":"11"},{"size":6081,"mtime":1694967589027,"results":"15","hashOfConfig":"11"},{"size":2709,"mtime":1694962059116,"results":"16","hashOfConfig":"11"},{"size":1056,"mtime":1694963184111,"results":"17","hashOfConfig":"11"},{"size":1615,"mtime":1694964010596,"results":"18","hashOfConfig":"11"},{"size":248,"mtime":1695662438185,"results":"19","hashOfConfig":"11"},{"filePath":"20","messages":"21","suppressedMessages":"22","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"9zzh3x",{"filePath":"23","messages":"24","suppressedMessages":"25","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"26","messages":"27","suppressedMessages":"28","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"29","messages":"30","suppressedMessages":"31","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"32","messages":"33","suppressedMessages":"34","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"35","messages":"36","suppressedMessages":"37","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"38","messages":"39","suppressedMessages":"40","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"41","messages":"42","suppressedMessages":"43","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","suppressedMessages":"46","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\index.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\Chat.jsx",[],["47","48","49"],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\App.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\BuddyMatcher.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\components\\NavBar.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\AuthContext.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\context\\reducers\\authReducer.js",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\pages\\Login.jsx",[],[],"C:\\Users\\Dunsin\\Documents\\Programming\\whisper\\client\\src\\lib\\badWords.js",[],[],{"ruleId":"50","severity":1,"message":"51","line":241,"column":1,"nodeType":"52","messageId":"53","endLine":241,"endColumn":137,"suppressions":"54"},{"ruleId":"50","severity":1,"message":"55","line":416,"column":1,"nodeType":"52","messageId":"53","endLine":416,"endColumn":105,"suppressions":"56"},{"ruleId":"50","severity":1,"message":"57","line":447,"column":1,"nodeType":"52","messageId":"53","endLine":447,"endColumn":87,"suppressions":"58"},"max-len","This line has a length of 136. Maximum allowed is 80.","Program","max",["59"],"This line has a length of 104. Maximum allowed is 80.",["60"],"This line has a length of 86. Maximum allowed is 80.",["61"],{"kind":"62","justification":"63"},{"kind":"62","justification":"63"},{"kind":"62","justification":"63"},"directive",""]
1 change: 0 additions & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function App() {
}}
>
<div className={`flex flex-col-reverse md:flex-row h-screen`}>
{/* TODO: Create layouts */}
{isLoggedIn && <NavBar />}
<Routes>
<Route
Expand Down
1 change: 0 additions & 1 deletion client/src/components/Anonymous.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const Anonymous = ({ onChatClosed }) => {
Close Chat
</Dropdown.Item>

{/* TODO: Use a checkbox in modal dialog instead */}
<Dropdown.Item onClick={() => handleClose(true)}>
Find a new buddy
</Dropdown.Item>
Expand Down
29 changes: 10 additions & 19 deletions client/src/components/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,7 @@ const Chat = () => {
}

return false;
} finally {
// Socket.emit('privatemessage', message);
// addMessage({
// id: senderId,
// message,
// time,
// room: 'anon',
// });
}
}

return true;
};
Expand All @@ -209,31 +201,32 @@ const Chat = () => {
return;
}

const message = getMessage(id);
const messageObject = getMessage(id);
const { message } = messageObject

if (message.includes('Warning Message')) {
return;
}

updateMessage(id, {
...message,
...messageObject,
status: 'pending',
});

try {
const messageDeleted = await deleteMessage({
id,
chatId: message.room,
chatId: messageObject.room,
});

if (!messageDeleted) {
updateMessage(id, message);
updateMessage(id, messageObject);
return;
}

removeMessage(id, message.room);
removeMessage(id, messageObject.room);
} catch {
updateMessage(id, message);
updateMessage(id, messageObject);
}
};

Expand Down Expand Up @@ -271,7 +264,7 @@ const Chat = () => {

const splitMessage = message.split(' ');
for (const word of splitMessage) {
// We need a better way to implement this
// TODO: We need a better way to implement this
if (listOfBadWordsNotAllowed.includes(word)) {
message = 'Warning Message: send a warning to users';
}
Expand Down Expand Up @@ -326,8 +319,6 @@ const Chat = () => {
const handleEdit = (id) => {
inputRef.current.focus();
const { message } = getMessage(id);
console.log('first', message)


if (message.includes('Warning Message')) {
cancelEdit();
Expand Down Expand Up @@ -378,7 +369,7 @@ const Chat = () => {
<div className="w-full md:h-[90%] min-h-[100%] pb-[25px] flex flex-col justify-between">
<div className="max-h-[67vh]">
<p className="text-[0.8em] font-semibold mb-[10px] mt-[20px] text-center">
Connected with a random User
Connected with a random User{sortedMessages.length === 0 && ', Be the first to send {"Hello"}'}
</p>
<ScrollToBottom
initialScrollBehavior="auto"
Expand Down

1 comment on commit 3dfc41f

@vercel
Copy link

@vercel vercel bot commented on 3dfc41f Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.