Skip to content

Commit 7b214fc

Browse files
authored
Remove all implementation around badges (#50)
* Remove all implementation around badges * Add subtext
1 parent f7daaea commit 7b214fc

14 files changed

Lines changed: 13 additions & 1100 deletions

File tree

functions/index.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ const express = require('express');
1616
const user = require('./utilities/user');
1717
const { countries } = require('./utilities/countries')
1818

19-
const BADGES = require('./build/badges.json');
2019
const PAGES = require('./build/pages.json');
2120
const LEVELS = ['year6', 'year7', 'year8', 'year9', 'year10', 'year11'];
2221
const LEVEL_NAMES = {year6: 'Level 1', year7: 'Level 2', year8: 'Level 3', year9: 'Level 4', year10: 'Level 5', year11: 'Level 6', graduated: 'Graduated'};
2322
const LEVEL_NAMES_WITH_AGES = {year6: 'Level 1 (ages 11 and below)', year7: 'Level 2 (age 11-12)', year8: 'Level 3 (age 12–13)', year9: 'Level 4 (age 13–14)', year10: 'Level 5 (age 14–15)', year11: 'Level 6 (ages 15 and above)', graduated: 'Graduated'};
2423
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
25-
const BADGE_NAMES = {ancient: 'Ancient Hero', geometry: 'Geometry', historic: 'Historic Hero', number: 'Number', modern: 'Modern Hero'};
2624

2725
const PAGES_MAP = {};
2826
for (let l of LEVELS) {
@@ -83,13 +81,11 @@ app.use((req, res, next) => {
8381
res.locals.isProduction = process.env.NODE_ENV === 'production';
8482
res.locals.user = req.user;
8583
res.locals.profileComplete = isProfileComplete(req.user);
86-
res.locals.badges = BADGES;
8784
res.locals.pages = {};
8885
res.locals.now = Date.now();
8986
res.locals.levels = LEVELS;
9087
res.locals.levelNames = LEVEL_NAMES;
9188
res.locals.levelNamesWithAges = LEVEL_NAMES_WITH_AGES;
92-
res.locals.badgeNames = BADGE_NAMES;
9389
res.locals.path = req.path.replace(/\/$/, '');
9490
res.locals.scoreClass = scoreClass;
9591

@@ -201,9 +197,6 @@ app.get('/login', (req, res) => {
201197
if(res?.locals?.user?.code){
202198
res.redirect('/dashboard')
203199
}
204-
if(res?.locals?.user){
205-
res.redirect('/badges')
206-
}
207200
res.redirect('/');
208201
})
209202

@@ -219,11 +212,6 @@ app.get('/home-educator-form', (req, res) => {
219212
res.render('home-educator');
220213
});
221214

222-
app.get('/badges', (req, res) => {
223-
if (!req.user) return error(res, 401);
224-
res.render('badges', {showAllBadges: ('reveal' in req.query)});
225-
});
226-
227215
app.get('/signup', (req, res) => {
228216
if (req.user) res.redirect('/');
229217

@@ -332,25 +320,7 @@ app.get('/:pid', (req, res, next) => {
332320
const userData = {answers, uid: req.user ? req.user.uid : '',
333321
submitted: ('reveal' in req.query) || answers.submitted || false};
334322

335-
let badgeLevel = req?.user?.level;
336-
337-
if(['year5', 'year6'].includes(req?.user?.level)) badgeLevel = 'year7';
338-
if(['year12', 'year13'].includes(req?.user?.level)) badgeLevel = 'year11';
339-
340-
let newBadge = null;
341-
if (req.user && !req.user.code) {
342-
for (let b of BADGES[badgeLevel]) {
343-
if (b.score <= req.user.points && req.user.badges.indexOf(b.id) < 0) {
344-
req.user.badges.push(b.id);
345-
newBadge = b;
346-
userDB.doc(req.user.uid) // async
347-
.update({badges: req.user.badges.join(',')})
348-
.catch(() => console.error('Failed to update badges', req.user.uid));
349-
}
350-
}
351-
}
352-
353-
res.render('parallelogram', {pid, body, page: PAGES_MAP[pid], userData, newBadge});
323+
res.render('parallelogram', {pid, body, page: PAGES_MAP[pid], userData});
354324
});
355325

356326
app.use((req, res) => error(res, 404));

functions/utilities/user.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const firebase = require('firebase-admin');
22
const cookieParser = require('cookie-parser')();
33
const PAGES = require('../build/pages.json');
4-
const BADGES = require('../build/badges.json');
54

65
const LEVELS = ['year6', 'year7', 'year8', 'year9', 'year10', 'year11'];
76

@@ -38,7 +37,6 @@ async function getUserData(uid) {
3837

3938
if (!data.level) data.level = 'year8';
4039
if (!data.answers) data.answers = {};
41-
data.badges = data.badges ? data.badges.split(',') : [];
4240
data.uid = uid;
4341

4442
data.allPoints = {};
@@ -48,8 +46,6 @@ async function getUserData(uid) {
4846
}
4947

5048
data.points = data.level ? (data.allPoints[data.level] || 0) : 0;
51-
data.visibleBadges = data.level ? (BADGES[data.level] || [])
52-
.filter(b => (data.points >= b.score)).reverse().slice(0, 4) : [];
5349

5450
data.sidebarLevels = getSidebarLevels(data)
5551

functions/views/_layout.pug

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ html
9292

9393
.sidebar-circles-item: a(href="/circles")
9494
div Parallel Circles
95-
.sidebar-circles-subtext(id="sidebar-circles-text") Interactive live maths sessions
95+
.sidebar-subtext(id="sidebar-circles-text") Interactive live maths sessions
9696
.status.live.hidden(id="sidebar-circles-marker") LIVE
9797

9898
if !user
@@ -109,14 +109,9 @@ html
109109
a(v-on:click="user.toggleReset()") {{ user.loginForm.reset ? 'Back to login' : 'Reset password' }}
110110

111111
if user && !user.code
112-
.sidebar-field: a(href="/badges")
113-
| Your Badges
114-
if user.visibleBadges.length
115-
.badge-row
116-
for b in user.visibleBadges
117-
.badge(style='background-image: url(/images/badges/' + b.id + '.jpg); color: #' + b.color)
118-
if user.visibleBadges.length > 4
119-
.badge.more +
112+
.sidebar-field: a(href="/awards")
113+
div Your Awards
114+
.sidebar-subtext(id="sidebar-circles-text") Badges are now part of the new Awards section
120115

121116
if !user || user.code || user.level !== 'year6'
122117
div(class="toggle space-around")

functions/views/badges.pug

Lines changed: 0 additions & 27 deletions
This file was deleted.

functions/views/parallelogram.pug

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ block content
2525
else
2626
button#submit(v-on:click="c.submit") Submit Answers
2727

28-
//- if newBadge
29-
//- #new-badge.modal(v-if="c.showBadgeModal")
30-
//- .modal-background(v-on:click="c.showBadgeModal = false")
31-
//- .modal-body(style="background: #" + newBadge.color)
32-
//- h2 Congratulations!
33-
//- p You’ve scored enough points to receive a new badge:
34-
//- img(src='/images/badges/' + newBadge.id + '.jpg' width=160 height-180)
35-
//- h3= newBadge.name
36-
//- p !{newBadge.description}
37-
//- p: a.badge-btn(href=newBadge.link target="_blank") Learn more…
38-
//- .close(v-on:click="c.showBadgeModal = false") ×
39-
4028
script!= 'window.PARALLELOGRAM = ' + JSON.stringify(page) + ';'
4129
script!= 'window.PARALLEL_USER_DATA = ' + JSON.stringify(userData) + ';'
4230

pages/7-01-school-of-rock.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ These challenges are a random walk through the mysteries of mathematics. Be prep
1616

1717
* Tackle each Parallelogram in one go. Don’t get distracted.
1818
* When you finish, remember to hit the SUBMIT button.
19-
* NEW! You can new earn reward points and badges – [find out more here](/badges).
19+
* NEW! You can new earn reward points and badges – [find out more here](/awards).
2020
* Finish by midnight on Sunday if your whole class is doing parallelograms.
2121

2222
__IMPORTANT__ – it does not really matter what score you get, because the main thing is that you think hard about the problems... and then examine the solution sheet to learn from your mistakes.

pages/8-01-wizard-of-oz.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ These challenges are a random walk through the mysteries of mathematics. Be prep
1616

1717
* Tackle each Parallelogram in one go. Don’t get distracted.
1818
* When you finish, remember to hit the SUBMIT button.
19-
* NEW! You can new earn reward points and badges – [find out more here](/badges).
19+
* NEW! You can new earn reward points and badges – [find out more here](/awards).
2020
* Finish by midnight on Sunday if your whole class is doing parallelograms.
2121

2222
__IMPORTANT__ – it does not really matter what score you get, because the main thing is that you think hard about the problems... and then examine the solution sheet to learn from your mistakes.

pages/9-01-sing-a-long.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ These challenges are a random walk through the mysteries of mathematics. Be prep
1616

1717
* Tackle each Parallelogram in one go. Don’t get distracted.
1818
* When you finish, remember to hit the SUBMIT button.
19-
* NEW! You can new earn reward points and badges – [find out more here](/badges).
19+
* NEW! You can new earn reward points and badges – [find out more here](/awards).
2020
* Finish by midnight on Sunday if your whole class is doing parallelograms.
2121

2222
__IMPORTANT__ – it does not really matter what score you get, because the main thing is that you think hard about the problems... and then examine the solution sheet to learn from your mistakes.

pages/badges.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/get-badges.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)