Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: message not sending #614

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions client/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"singleQuote": true,
"trailingComma": "es5",
"bracketSameLine": false,
"endOfLine": "lf",
"editorconfig": true
"endOfLine": "lf"
}
20 changes: 10 additions & 10 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const clientID = import.meta.env.VITE_IMPORTANT;

function App() {
const { isLoggedIn, dispatchAuth } = useAuth();
const { loadUserSettings, updateOnlineStatus, app } = useApp();
const { loadUserSettings, updateOnlineStatus, app } = useApp();

const { settings } = app
const [onlineStatus, setOnlineStatus] = useState(null)
const { settings } = app;
const [onlineStatus, setOnlineStatus] = useState(null);

const isTabActive = useIsTabActive()
const isTabActive = useIsTabActive();

async function loginWithEmail(email) {
try {
Expand Down Expand Up @@ -68,19 +68,19 @@ function App() {

useEffect(() => {
if (!isLoggedIn) {
return
return;
}

if (isTabActive) {
setOnlineStatus('online')
setOnlineStatus('online');
} else {
setOnlineStatus(new Date)
setOnlineStatus(new Date());
}
}, [isTabActive])
}, [isTabActive]);

useEffect(() => {
updateOnlineStatus(onlineStatus)
}, [onlineStatus])
updateOnlineStatus(onlineStatus);
}, [onlineStatus]);

return (
<KindeProvider
Expand Down
64 changes: 29 additions & 35 deletions client/src/components/Anonymous.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const centerItems = `flex items-center justify-center`;
const Anonymous = ({ onChatClosed }) => {
const { app, endSearch } = useApp();
const { currentChatId, onlineStatus } = app;
const { clearTimer } = useCheckTimePassed()
const { clearTimer } = useCheckTimePassed();

const currentChatIdRef = useRef(currentChatId);

const [isTyping, setIsTyping] = useState(false);
const [autoSearchAfterClose, setAutoSearchAfterClose] = useState(false);
const [disconnected, setDisconnected] = useState(false);
const [buddyOnlineStatus, setBuddyOnlineStatus] = useState(null)
const [buddyOnlineStatus, setBuddyOnlineStatus] = useState(null);

const autoSearchRef = useRef();
autoSearchRef.current = autoSearchAfterClose;
Expand Down Expand Up @@ -107,7 +107,7 @@ const Anonymous = ({ onChatClosed }) => {
navigate('/');
}

clearTimer()
clearTimer();
});
};

Expand Down Expand Up @@ -162,11 +162,7 @@ const Anonymous = ({ onChatClosed }) => {
// Set today's date to the beginning of the day
today.setHours(0, 0, 0, 0);
const yesterday = new Date(today);
yesterday
.setDate(
yesterday
.getDate() - 1
); // Set it to yesterday
yesterday.setDate(yesterday.getDate() - 1); // Set it to yesterday

let formattedDate;
if (date >= today) {
Expand All @@ -182,12 +178,12 @@ const Anonymous = ({ onChatClosed }) => {
const options = { year: 'numeric', month: 'short', day: 'numeric' };
formattedDate = date.toLocaleString('en-US', options);
}
setBuddyOnlineStatus(formattedDate)
setBuddyOnlineStatus(formattedDate);

return
return;
}
setBuddyOnlineStatus(onlineStatusState)
}
setBuddyOnlineStatus(onlineStatusState);
};

for (const event in connectionEvents) {
socket.on(event, connectionEvents[event]);
Expand All @@ -214,15 +210,11 @@ const Anonymous = ({ onChatClosed }) => {

useEffect(() => {
if (!onlineStatus) {
return
return;
}

socket.timeout(5000)
.emit(
NEW_EVENT_ONLINE_STATUS,
{ onlineStatus, chatId: currentChatId })

}, [onlineStatus])
socket.timeout(5000).emit(NEW_EVENT_ONLINE_STATUS, { onlineStatus, chatId: currentChatId });
}, [onlineStatus]);

return (
<div
Expand Down Expand Up @@ -258,28 +250,30 @@ const Anonymous = ({ onChatClosed }) => {
/>
</Whisper>
</div>
<div className='flex flex-col gap-2 items-center sm:items-start'>
<div className="flex flex-col gap-2 items-center sm:items-start">
<h2 className=" text-xl font-semibold">Anonymous User</h2>
<div className='flex items-center gap-3'>
<div className="flex items-center gap-3">
{isTyping && <span>Typing</span>}
{buddyOnlineStatus && <span className=' text-gray-400 text-sm'>{buddyOnlineStatus}</span>}
{buddyOnlineStatus && (
<span className=" text-gray-400 text-sm">{buddyOnlineStatus}</span>
)}
</div>
</div>

<Dropdown placement="leftStart" style={{ zIndex: 3 }} renderToggle={MenuToggle} noCaret>
<Dropdown.Item onClick={() => handleClose()} className='sm:w-[200px]'>
<div className="flex items-center justify-between gap-2 flex-wrap">
<span>Close Chat</span>
<span className="text-gray-500 text-xs">Ctrl + Shift + X</span>
</div>
</Dropdown.Item>
<Dropdown.Item onClick={() => handleClose(true)} className='sm:w-[200px]'>
<div className="flex items-center justify-between gap-2 flex-wrap">
<span>Find a new buddy</span>
<span className="text-gray-500 text-xs">Ctrl + Alt + N</span>
</div>
</Dropdown.Item>
</Dropdown>
<Dropdown.Item onClick={() => handleClose()} className="sm:w-[200px]">
<div className="flex items-center justify-between gap-2 flex-wrap">
<span>Close Chat</span>
<span className="text-gray-500 text-xs">Ctrl + Shift + X</span>
</div>
</Dropdown.Item>
<Dropdown.Item onClick={() => handleClose(true)} className="sm:w-[200px]">
<div className="flex items-center justify-between gap-2 flex-wrap">
<span>Find a new buddy</span>
<span className="text-gray-500 text-xs">Ctrl + Alt + N</span>
</div>
</Dropdown.Item>
</Dropdown>
</div>
<div
className={createClassesFromArray([
Expand Down
Loading
Loading