Skip to content

Commit 9529551

Browse files
author
Jiaping Zeng
committed
asdf
1 parent baeffec commit 9529551

File tree

3 files changed

+88
-66
lines changed

3 files changed

+88
-66
lines changed

routes/user.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ router.get('/dashboard', loggedIn(), (req, res) => {
1616
})
1717
})
1818

19+
router.get('/profile', (req, res) => {
20+
res.redirect('index')
21+
})
22+
1923
router.get('/login', passport.authenticate('auth0', {
2024
scope: 'openid email profile'
2125
}), (req, res) => {
2226
res.redirect('/')
2327
})
2428

25-
router.get('/dashboard', loggedIn(), (req, res, next) => {
29+
router.get('/index', loggedIn(), (req, res, next) => {
2630
const { _raw, _json, ...userProfile } = req.user
2731
res.render('user/dashboard', {
2832
userProfile: JSON.stringify(userProfile, null, 2),

views/user/dashboard.ejs

+82-64
Original file line numberDiff line numberDiff line change
@@ -124,60 +124,71 @@
124124
height: auto;
125125
text-align: left;
126126
margin-bottom: 2rem;
127-
}
128-
img{
129-
/* margin-top: 10px; */
130-
width:1.5rem;
131-
height:1.5rem;
132-
-moz-transform: scaleX(-1);
127+
}
128+
129+
img {
130+
/* margin-top: 10px; */
131+
width: 1.5rem;
132+
height: 1.5rem;
133+
-moz-transform: scaleX(-1);
133134
-o-transform: scaleX(-1);
134135
-webkit-transform: scaleX(-1);
135136
transform: scaleX(-1);
136137
filter: FlipH;
137138
-ms-filter: "FlipH";
138-
}
139-
#scoreboard-inner{
140-
min-height: 100%;
141-
border-radius: 16px;
142-
background: #2d2d2d;
143-
margin-left: 4rem;
144-
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
145-
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
146-
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
147-
}
148-
@media (max-width: 900px){
149-
html{
150-
overflow-x: hidden
151-
}
152-
h1{
153-
margin-left: 1rem;
154-
}
155-
#body{
156-
min-height: 0;
157-
max-width: 100%
158-
}
159-
#user{
160-
max-width: 100%;
161-
}
162-
#main{
163-
display: block;
164-
}
165-
.player{
166-
padding: 1rem;
167-
padding-top: 1.5rem
168-
}
169-
#scoreboard-inner{
170-
margin: -0.75rem;
171-
margin-bottom: 1rem;
172-
margin-top: 1rem;
173-
padding: 0rem;
174-
padding-bottom: 1rem;
175-
}
176-
}
177-
178-
</style>
179-
<body>
180-
<div style="display:none" id="data"><%= userProfile %></div>
139+
}
140+
141+
#scoreboard-inner {
142+
min-height: 100%;
143+
border-radius: 16px;
144+
background: #2d2d2d;
145+
margin-left: 4rem;
146+
-webkit-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.75);
147+
-moz-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.75);
148+
box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.75);
149+
}
150+
151+
@media (max-width: 900px) {
152+
html {
153+
overflow-x: hidden
154+
}
155+
156+
h1 {
157+
margin-left: 1rem;
158+
}
159+
160+
#body {
161+
min-height: 0;
162+
max-width: 100%
163+
}
164+
165+
#user {
166+
max-width: 100%;
167+
}
168+
169+
#main {
170+
display: block;
171+
}
172+
173+
.player {
174+
padding: 1rem;
175+
padding-top: 1.5rem
176+
}
177+
178+
#scoreboard-inner {
179+
margin: -0.75rem;
180+
margin-bottom: 1rem;
181+
margin-top: 1rem;
182+
padding: 0rem;
183+
padding-bottom: 1rem;
184+
}
185+
}
186+
</style>
187+
188+
<body>
189+
<div style="display:none" id="data">
190+
<%= userProfile %>
191+
</div>
181192
<div style="max-width: 800px; width: 100%; margin: 0 auto">
182193
<h1 id="user-name"></h1>
183194
</div>
@@ -228,24 +239,43 @@ box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
228239
url: 'https://hasura-codeday.herokuapp.com/v1alpha1/graphql',
229240
contentType: 'application/json',
230241
data: JSON.stringify({
231-
query: "{ user { name points } event {name time location}}"
242+
query: "{ user { name points } event { name time location }}"
232243
})
233244
}).done((data) => {
234245
console.log(data.data.event)
235246
players = []
247+
events = []
236248
data.data.user.forEach((item) => {
237249
players.push({
238250
name: item.name,
239251
score: item.points
240252
})
241253
})
254+
data.data.event.forEach((item) => {
255+
events.push({
256+
name: item.name,
257+
time: item.time.substring(0,10) + " " + item.time.substring(11, 19),
258+
location: item.location.name
259+
})
260+
})
242261
players.sort((a, b) => -1 * a.score + b.score)
243262
const iEnd = players.length > 9 ? 9 : players.length
244263
for (let i = 0; i < iEnd; i++) {
245264
scoreboardElement.append(toPlayersHtml(players[i].name, players[i].score, i))
246265
}
266+
if (events.length == 0) {
267+
eventsElement.html(`
268+
<div style="padding: 2rem; color: #FFFFFFAA; background: #FFFFFF11; border: 2px dashed #FFFFFF22 ">
269+
You haven't been invited to any events :(
270+
</div>
271+
`)
272+
} else {
273+
events.forEach(i => {
274+
eventsElement.append(toEventHtml(i.name, i.time, i.location, i.id))
275+
})
276+
}
277+
247278
})
248-
players.sort((a, b) => -1 * a.score + b.score)
249279
function toEventHtml(name, time, location, id) {
250280
return `
251281
<a href="/event/${id}">
@@ -294,7 +324,7 @@ box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
294324
return `
295325
<div class="player">
296326
<div class="player-name">${name}</div>
297-
<div class="player-score">${score}</div>
327+
<div class="player-score">${score} <img src="/axe.png"></img></div>
298328
</div>
299329
</div>
300330
`
@@ -304,18 +334,6 @@ box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
304334
const eventsElement = $('#events')
305335
const scoreboardElement = $('#scoreboard-inner')
306336
$('#events-button').click(() => window.location.href = "/event/create")
307-
if (events.length == 0) {
308-
eventsElement.html(`
309-
<div style="padding: 2rem; color: #FFFFFFAA; background: #FFFFFF11; border: 2px dashed #FFFFFF22 ">
310-
You haven't been invited to any events :(
311-
</div>
312-
`)
313-
} else {
314-
events.forEach(i => {
315-
eventsElement.append(toEventHtml(i.name, i.time, i.location, i.id))
316-
})
317-
}
318-
319337
320338
const html = `<div id="see" style="
321339
width: 100%;

views/user/index.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
url: 'https://hasura-codeday.herokuapp.com/v1alpha1/graphql',
214214
contentType: 'application/json',
215215
data: JSON.stringify({
216-
query: "{ user { name points }}"
216+
query: "{ user { name points } event { name time location }}"
217217
})
218218
}).done((data) => {
219219
players = []

0 commit comments

Comments
 (0)