Skip to content

Commit d1a099b

Browse files
Merge pull request #18 from jae1911/jae-feat-sessions-view
feat: session list page
2 parents b265f1a + aaec14a commit d1a099b

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

helpers/preprocessing.js

+31-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ function preProcessSession(json) {
3131
return json;
3232
}
3333

34+
/**
35+
* Preprocesses the session list and returns an array of the top X sessions to display on the webpage.
36+
*
37+
* @param {SessionsList} json object of the full session API endpoint
38+
* @param {SessionCount} int number of sessions to return for the page
39+
* @returns The transformed sessions object for viewing.
40+
*/
41+
function preProcessSessionList(json, count){
42+
const sessions = json
43+
.sort((a, b) => b.totalJoinedUsers - a.totalJoinedUsers)
44+
.slice(0, count);
45+
46+
json.sessions = sessions.map((session) => {
47+
// We convert the name here since the JSON format for
48+
// this is different from the other responses
49+
session.name = preProcessName(session.name);
50+
return preProcessSession(session);
51+
});
52+
53+
return json;
54+
}
55+
3456
/**
3557
* Preprocesses the world information return from SkyFrost to a format suitable for viewing.
3658
*
@@ -57,9 +79,11 @@ function preProcessWorld(json) {
5779
*/
5880
export function preProcess(json, type) {
5981

60-
// ensure page title
61-
json.title = DOMPurify.sanitize(json.name);
62-
json.name = preProcessName(json.name);
82+
if (type != "sessionList"){
83+
// ensure page title
84+
json.title = DOMPurify.sanitize(json.name);
85+
json.name = preProcessName(json.name);
86+
}
6387

6488
switch (type) {
6589
case "session":
@@ -68,7 +92,10 @@ export function preProcess(json, type) {
6892
case "world":
6993
json = preProcessWorld(json);
7094
break;
95+
case "sessionList":
96+
json = preProcessSessionList(json, 15);
97+
break;
7198
}
7299

73100
return json;
74-
}
101+
}

public/stylesheets/style.css

+25-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,28 @@
5555
.btn:hover {
5656
background: #3f6a47;
5757
text-decoration: none;
58-
}
58+
}
59+
60+
.grid {
61+
display: grid;
62+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
63+
gap: 10px;
64+
}
65+
66+
.grid-item {
67+
border: 1px solid rgba(0, 0, 0, 0.8);
68+
padding: 20px;
69+
text-align: center;
70+
display: flex;
71+
flex-direction: column;
72+
justify-content: center;
73+
align-items: center;
74+
}
75+
76+
.grid-item p {
77+
margin: 5px 0;
78+
font-size: 16px;
79+
white-space: normal;
80+
word-break: break-word;
81+
text-align: center;
82+
}

routes/index.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ router.get('/', function(req, res, next) {
1515
router.get('/session/:sessionId', (req,res, next) => handle("session", req, res, next));
1616
router.get('/session/:sessionId/json', (req,res, next) => handleJson("session", req, res, next));
1717

18+
router.get('/sessions', (req, res, next) => handle("sessionList", req, res, next));
19+
router.get('/sessions/json', (req, res, next) => handleJson("sessionList", req, res, next));
20+
1821
// Register world/ and record/
1922
for (const word of ["world", "record"]) {
2023
router.get(`/${word}/:ownerId/:recordId`, (req,res, next) => handle("world", req, res, next));
@@ -36,6 +39,9 @@ function getUrl(type, req) {
3639
return `${baseUrl}/users/${req.params.ownerId}/records/${req.params.recordId}/`;
3740
case "session":
3841
return `${baseUrl}/sessions/` + req.params.sessionId;
42+
case "sessionList":
43+
return `${baseUrl}/sessions`
44+
break;
3945
default:
4046
throw new Error(`Unknown url type: ${type}`);
4147
}
@@ -80,6 +86,10 @@ async function handle(type, req, res, next) {
8086
return next(createError(400, "go.resonite.com only works for Session and world link."));
8187
}
8288

89+
if (type === "sessionList"){
90+
json.title = getOpenGraphTitle(type);
91+
}
92+
8393
json = preProcess(json, type);
8494
json.urlPath = req.getUrl();
8595

@@ -117,7 +127,7 @@ async function handleJson(type, req, res, next) {
117127
author_name: title,
118128
author_url: req.getUrl().replace("/json",""),
119129
provider_name: "Resonite",
120-
provider_url: "https://resonite.com"
130+
provider_url: "https://resonite.com",
121131
});
122132
}
123133

@@ -134,6 +144,9 @@ function getOpenGraphTitle(type) {
134144
return `${app} Session`;
135145
case "world":
136146
return `${app} World`;
147+
case "sessionList":
148+
return `${app} Sessions list`;
149+
break;
137150
default:
138151
return `${app} World`;
139152
}

views/index.pug

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ block content
44
h1 go.resonite.com
55
p go.resonite.com is used to link to worlds and sessions from the web. It's home page doesn't have any functionality at the moment.
66

7-
p Would you like to
8-
a(href="https://resonite.com") Go to our Main Website?
7+
p Would you like to
8+
ul
9+
li
10+
a(href="/sessions") See the current active public sessions
11+
li
12+
a(href="https://resonite.com") Go to our Main Website?
913

views/sessionList.pug

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
extends layout
2+
3+
block head
4+
meta(property="og:title" content=title)
5+
meta(property="og:type" content="resonite.sessionList")
6+
meta(property="og:description" content="Active sessions on Resonite")
7+
link(type="application/json+oembed" href=`${urlPath}json`)
8+
9+
block content
10+
h1 Active Sessions
11+
12+
div(class="grid")
13+
each session in sessions
14+
div(class="grid-item")
15+
p !{session.name}
16+
p= `Users: ${session.joinedUsers}/${session.maxUsers}`
17+
p= `Host: ${session.hostUsername}`
18+
a(href=`/session/${session.sessionId}`) See details

0 commit comments

Comments
 (0)