Skip to content

Commit

Permalink
refactor: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedAmrNabil committed Dec 26, 2024
1 parent b24e36b commit 9704e8d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const NotificationsDropdown = ({ onOpen }: { onOpen: () => void }) => {
}, []);

const { socket } = useContext(UserContext);

useEffect(() => {
function addNotification(notification: INotifications) {
setNotifications((prevNotifications) => [
Expand Down
4 changes: 2 additions & 2 deletions client/src/store/userContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAuthJwtToken } from '@/utils/auth';
import { createContext, useCallback, useEffect, useState,useRef } from 'react';
import { createContext, useCallback, useEffect, useState, useRef } from 'react';
import io from 'socket.io-client';
import { Socket } from 'socket.io-client';

Expand Down Expand Up @@ -124,7 +124,7 @@ export const UserContextProvider: React.FC<{ children: React.ReactNode }> = ({
role: userState.role,
isBanned: userState.isBanned,
profilePicture: userState.profilePicture,
socket:socket.current,
socket: socket.current,
setUser,
setUsername,
};
Expand Down
15 changes: 9 additions & 6 deletions server/src/controllers/messageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ export async function sendMessage(req: Request, res: Response) {
url: `/jobs/${req.params.jobId}/manage`,
},
);

}


if (req.user!.role === 'freelancer' || req.user!.role === 'admin') {
const accountResult = await db.query(
'SELECT client_id FROM jobs WHERE id = $1',
Expand All @@ -114,7 +112,6 @@ export async function sendMessage(req: Request, res: Response) {
url: `/jobs/${req.params.jobId}/manage`,
},
);

}

const messageTobeSent: IMessage = {
Expand All @@ -136,7 +133,10 @@ export async function sendMessage(req: Request, res: Response) {
},
};

io.to(`job-chat-${req.params.jobId}`).emit('recieve-message', messageTobeSent);
io.to(`job-chat-${req.params.jobId}`).emit(
'recieve-message',
messageTobeSent,
);

res.json({
status: true,
Expand All @@ -145,7 +145,7 @@ export async function sendMessage(req: Request, res: Response) {
message: messageTobeSent,
},
});
} catch (err){
} catch (err) {
console.log(err);
res.status(500).json({ status: false, message: 'Error sending message' });
}
Expand All @@ -166,7 +166,10 @@ export async function deleteMessage(req: Request, res: Response) {
[req.params.messageId, req.params.jobId, req.params.freelancerId],
);

io.to(`job-chat-${req.params.jobId}`).emit('delete-message', req.params.messageId);
io.to(`job-chat-${req.params.jobId}`).emit(
'delete-message',
req.params.messageId,
);

res.json({ status: true, message: 'Message deleted' });
} catch {
Expand Down
2 changes: 1 addition & 1 deletion server/src/controllers/milestoneController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function completeMilestone(req: Request, res: Response) {
);

res.json({ status: true, message: 'Milestone completed' });
} catch(err) {
} catch (err) {
console.error(err);
res
.status(500)
Expand Down
2 changes: 1 addition & 1 deletion server/src/models/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ export interface IMessage {
username: string;
isAdmin: boolean;
};
}
}
4 changes: 3 additions & 1 deletion server/src/sockets/chatHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export function chatHandler(io: Server, socket: Socket) {

socket.on('unsubscribe-chat', (jobId: string) => {
socket.leave(`job-chat-${jobId}`);
console.log(`User ${socket.data.user.id} unsubscribed to job chat ${jobId}`);
console.log(
`User ${socket.data.user.id} unsubscribed to job chat ${jobId}`,
);
});
}

0 comments on commit 9704e8d

Please sign in to comment.