Skip to content

Commit

Permalink
Add request marker
Browse files Browse the repository at this point in the history
Added a red circle to profile picture on sidebar to show number of friend requests that user has.
  • Loading branch information
MichaelLaffan1 committed Nov 9, 2023
1 parent 5f1da50 commit 20cd8b1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
18 changes: 0 additions & 18 deletions client/agora/public/css/notification.css

This file was deleted.

17 changes: 17 additions & 0 deletions client/agora/public/js/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var displayedUsers = new Set();
const userSearch = document.getElementById( 'user-search' );
const searchButton = document.getElementById( 'btn-search' );
const friendsDashboard = document.getElementById( 'friends-dashboard' );
const redCircle = document.getElementById( 'requestCount' );
var authUser = [ ];
var friends = [ ];
var requests = [ ];
Expand All @@ -24,8 +25,24 @@ window.onload = getResources = () => {
friends.push( response[1] );
requests.push( response[2] );
} );
fetch( "api/v1/auth/friends/requestCount", {

Check failure on line 28 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L28

Expected indentation of 4 spaces but found 8 (indent)
method: "GET",

Check failure on line 29 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L29

Expected indentation of 8 spaces but found 12 (indent)
headers: { 'Content-Type': 'application/json' },

Check failure on line 30 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L30

Expected indentation of 8 spaces but found 12 (indent)
})

Check failure on line 31 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L31

Expected indentation of 4 spaces but found 8 (indent)

Check failure on line 31 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L31

There must be a space before this paren (space-in-parens)
.then( ( response ) => response.json() )

Check failure on line 32 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L32

Expected indentation of 8 spaces but found 12 (indent)
.then( ( response ) => {

Check failure on line 33 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L33

Expected indentation of 8 spaces but found 12 (indent)
let requestCount = response[0].count;

Check failure on line 34 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L34

Expected indentation of 12 spaces but found 16 (indent)
console.log(requestCount);

Check failure on line 35 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L35

Expected indentation of 12 spaces but found 16 (indent)

Check failure on line 35 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L35

There must be a space after this paren (space-in-parens)

Check failure on line 35 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L35

There must be a space before this paren (space-in-parens)
if ( requestCount > 0){

Check failure on line 36 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L36

Expected indentation of 12 spaces but found 16 (indent)

Check failure on line 36 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L36

There must be a space before this paren (space-in-parens)
let span = document.createElement("span");

Check failure on line 37 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L37

Expected indentation of 16 spaces but found 20 (indent)

Check failure on line 37 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L37

There must be a space after this paren (space-in-parens)

Check failure on line 37 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L37

There must be a space before this paren (space-in-parens)
span.textContent = requestCount;

Check failure on line 38 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L38

Expected indentation of 16 spaces but found 20 (indent)
redCircle.appendChild(span);

Check failure on line 39 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L39

Expected indentation of 16 spaces but found 20 (indent)

Check failure on line 39 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L39

There must be a space after this paren (space-in-parens)

Check failure on line 39 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L39

There must be a space before this paren (space-in-parens)
redCircle.style.display = "flex";

Check failure on line 40 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L40

Expected indentation of 16 spaces but found 20 (indent)
}

Check failure on line 41 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L41

Expected indentation of 12 spaces but found 16 (indent)
})

Check failure on line 42 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L42

Expected indentation of 8 spaces but found 12 (indent)

Check failure on line 42 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L42

There must be a space before this paren (space-in-parens)

Check failure on line 42 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L42

Missing semicolon (semi)
};


// queries the users by username
searchButton.addEventListener( 'click', queryUsers = () => {

Check failure on line 47 in client/agora/public/js/friends.js

View workflow job for this annotation

GitHub Actions / ESLint

client/agora/public/js/friends.js#L47

'queryUsers' is not defined (no-undef)
fetch( "/api/v1/auth/user/username/" + userSearch.value, {
Expand Down
3 changes: 2 additions & 1 deletion client/agora/views/dashboard/side-menu/side-menu.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
<% if(locals.authUser) { %>
<a href="/profile/manageProfile"
style="width:100%; position: absolute;bottom: 0; left: -15px;border-top:solid;border-radius:2px;">
<div id="requestCount" style="position: absolute; top:0; left: 65px; padding: 5px; border-radius: 50%; background-color: red;
color: white; font-weight: bold; font-size: 14px; display: none;"></div>
<% if( locals.authUser.profileFilename.toString().substring(0, 7)=="http://" ||
locals.authUser.profileFilename.toString().substring(0, 8)=="https://" ) { %>
<img src="<%- locals.authUser.profileFilename %>" alt="User Dashboard avatar"
Expand Down
1 change: 0 additions & 1 deletion client/agora/views/profile/manage.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<%- include('../partials/head'); %>
<link rel="stylesheet" href="/css/notification.css">
</head>
<body id="page-top">
<!-- Navigation-->
Expand Down
18 changes: 18 additions & 0 deletions server/service/friendService.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ exports.getAllFriends = async ( userID ) => {
}
};

exports.getUnreadFriendRequestCount = async ( userID ) => {
let text = `SELECT COUNT(*) FROM friendships WHERE recipient_id = $1 AND friendship_status = $2`;
let values = [ userID, 'pending'];

try{
let res = await db.query( text, values );
if ( res.rows.length > 0){
return res.rows;
}
else{
return false;
}
}
catch ( e ){
console.log( e.stack );
}
};

// Send a friend request
exports.sendFriendRequest = async ( requesterID, recipientID ) => {

Expand Down

0 comments on commit 20cd8b1

Please sign in to comment.