Finished re-working navbar

This commit is contained in:
rainbow napkin 2026-10-17 03:57:16 -04:00
parent 03fecaddc2
commit 05c1875158
5 changed files with 53 additions and 11 deletions

View file

@ -19,6 +19,7 @@ const config = require('../../config.json');
//Local Imports //Local Imports
const csrfUtils = require('../utils/csrfUtils'); const csrfUtils = require('../utils/csrfUtils');
const presenceUtils = require('../utils/presenceUtils');
/* You could make the argument this should be middleware that passes a properties object to user /* You could make the argument this should be middleware that passes a properties object to user
But then I'd writing out all the other controllers properties as I am below, or worse. Not a great option.*/ But then I'd writing out all the other controllers properties as I am below, or worse. Not a great option.*/
@ -30,6 +31,7 @@ module.exports.render = async function(req, res, template, properties = {}){
properties.links = config.links; properties.links = config.links;
properties.user = req.session.user properties.user = req.session.user
properties.csrfToken = csrfUtils.generateToken(req) properties.csrfToken = csrfUtils.generateToken(req)
properties.userCount = (await presenceUtils.getOnlineUsers()).length;
//Render out template, passing given properties with navbar required properties added //Render out template, passing given properties with navbar required properties added
return res.render(template, properties); return res.render(template, properties);

View file

@ -28,6 +28,26 @@ const tolerance = 2 * (60 * 1000);
//Defaults to five minutes //Defaults to five minutes
const offlineTimeout = 5 * (60 * 1000); const offlineTimeout = 5 * (60 * 1000);
module.exports.getOnlineUsers = async function(){
//Define array to hold list of online users
const users = [];
//Iterate through all users in the RAM-Backed activity map (only ones that would be online)
for(const key of Array.from(activityMap.keys())){
//Grab current user, should grab from ram since we're polling activityMap
const user = await module.exports.getPresence(key);
//If the user is online
if(user.status == "Streaming" || user.status == "Recently Active"){
//Addem' to da list
users.push(user);
}
}
//Return all found users
return users;
}
module.exports.getPresence = async function(user, userDB){ module.exports.getPresence = async function(user, userDB){
//If we don't have a user //If we don't have a user
if(user == null || user == '' || user == 'Tokebot'){ if(user == null || user == '' || user == 'Tokebot'){
@ -44,7 +64,7 @@ module.exports.getPresence = async function(user, userDB){
//If we couldn't find anything in RAM //If we couldn't find anything in RAM
if(activity == null){ if(activity == null){
//If we wheren't handed a free user doc //If we wheren't handed a free user doc, and we're allowed to pull from DB
if(userDB == null){ if(userDB == null){
//Pull one from the username //Pull one from the username
userDB = await userModel.findOne({user: user}); userDB = await userModel.findOne({user: user});

View file

@ -14,28 +14,33 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. %> along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<div id="navbar"> <div id="navbar">
<span class="navbar-item"> <span class="navbar-item" id="left-navbar-cluster">
<%#<a class="navbar-item" href="/" id="instance-title">%><%#= instance %><%#</a><p class="navbar-item"> - <a class="navbar-item" href="/about">about</a></p>%> <%#<a class="navbar-item" href="/" id="instance-title">%><%#= instance %><%#</a><p class="navbar-item"> - <a class="navbar-item" href="/about">about</a></p>%>
<a class="navbar-item" href="/" id="instance-title"><%= instance %></a> <a class="navbar-item" href="/" id="instance-title"><%= instance %></a>
<p class="navbar-item" id="right-controls"> <p class="navbar-item" id="left-controls">
<span class="navbar-item-seperator first"> - </span><a class="navbar-item first" href="javascript:">Channel Guide</a> <span class="navbar-item-seperator first"> - </span>
<a class="navbar-item first" href="javascript:">Channel Guide</a>
<% for(link of Object.keys(links)){ %> <% for(link of Object.keys(links)){ %>
<span class="navbar-item-seperator"> - </span><a target="_blank" class="navbar-item" href="<%- links[link] %>"><%= link %></a> -
<a target="_blank" class="navbar-item" href="<%- links[link] %>"><%= link %></a>
<% } %> <% } %>
</p> </p>
</span> </span>
<span class="navbar-item" id="right-controls"> <span class="navbar-item" id="right-navbar-cluster">
<% if(user){ %> <% if(user){ %>
<p class="navbar-item">Welcome, <a class="navbar-item" id="username" href="/profile"><%= user.user %></a> - <p class="navbar-item" id="right-controls">
Welcome, <a class="navbar-item" id="username" href="/profile"><%= user.user %></a> -
<span class="navbar-item" title="<%- userCount %> User<% if(userCount > 1){ %>s<% } %> Online site-wide">
<%- userCount %> User<% if(userCount > 1){ %>s<% } %> Online
</span>
-
<% if(user.rank == "mod" || user.rank == "admin"){ %> <% if(user.rank == "mod" || user.rank == "admin"){ %>
<a target="_blank" href="/adminPanel" title="Admin Panel" class="bi bi-server navbar-item"></a> - <a target="_blank" href="/adminPanel" title="Admin Panel" class="bi bi-server navbar-item"></a> -
<% } %> <% } %>
<span id="channel-settings-button-span" class="navbar-item" style="display: none;"> <span id="channel-settings-button-span" class="navbar-item" style="display: none;">
<a target="_blank" href="" title="Channel Settings" class="bi bi-projector-fill navbar-item"></a> <a target="_blank" href="" title="Channel Settings" class="bi bi-projector-fill navbar-item"></a>
- -
</span> </span>
<a class="navbar-item" href="javascript:" id="logout-button">Logout</a> <a class="navbar-item" href="javascript:" id="logout-button">Logout</a>
</p> </p>
<% }else{ %> <% }else{ %>
@ -43,7 +48,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<input class="navbar-item login-prompt" id="remember-me" type="checkbox"> <input class="navbar-item login-prompt" id="remember-me" type="checkbox">
<input class="navbar-item login-prompt" id="username-prompt" placeholder="username"> <input class="navbar-item login-prompt" id="username-prompt" placeholder="username">
<input class="navbar-item login-prompt" id="password-prompt" placeholder="password" type="password"> <input class="navbar-item login-prompt" id="password-prompt" placeholder="password" type="password">
<p class="navbar-item"><a class="navbar-item" href="javascript:" id="login-button">Login</a> - <a class="navbar-item" href="/passwordReset">Forgot Password</a> - <a class="navbar-item" href="/register">Register</a> <p class="navbar-item">
<a class="navbar-item" href="javascript:" id="login-button">Login</a>
-
<a class="navbar-item" href="/passwordReset">Forgot Password</a>
-
<a class="navbar-item" href="/register">Register</a>
</p> </p>
<% } %> <% } %>
</span> </span>

View file

@ -92,6 +92,8 @@ button i{
display: flex; display: flex;
padding: 0 0.5em; padding: 0 0.5em;
justify-content: space-between; justify-content: space-between;
height: 2.45em;
align-items: center;
} }
.navbar-item{ .navbar-item{
@ -102,6 +104,12 @@ button i{
#instance-title{ #instance-title{
font-size: 1.2em; font-size: 1.2em;
padding-right: 0.25em;
}
#right-navbar-cluster, #left-navbar-cluster{
display: flex;
align-items: center;
} }
p.navbar-item, input.navbar-item{ p.navbar-item, input.navbar-item{
@ -110,6 +118,7 @@ p.navbar-item, input.navbar-item{
.navbar-item input{ .navbar-item input{
padding: 0.2em; padding: 0.2em;
margin-right: 0.5em;
} }
/* Popup Container */ /* Popup Container */

View file

@ -320,6 +320,7 @@ input.control-prompt, input.control-prompt:focus{
/* navbar */ /* navbar */
#navbar{ #navbar{
background-image: var(--bg1-gradient); background-image: var(--bg1-gradient);
overflow: hidden;
} }
.navbar-item{ .navbar-item{
@ -337,7 +338,7 @@ input.control-prompt, input.control-prompt:focus{
} }
.navbar-item.first{ .navbar-item.first{
margin-left: 0.25em; margin-left: 0.5em;
} }
.navbar-item-seperator.first{ .navbar-item-seperator.first{