From fe61c766de90ccda4a712fac308e2e33f85feeb6 Mon Sep 17 00:00:00 2001 From: Geoffrey Wu Date: Sun, 24 Dec 2023 21:12:13 -0600 Subject: [PATCH] add frequency list pages --- client/frequency-list/index.html | 119 +++++++++++++++++++++++++ client/frequency-list/subcategory.html | 91 +++++++++++++++++++ client/frequency-list/subcategory.js | 23 +++++ client/index.html | 3 + routes/frequency-list.js | 12 +++ routes/index.js | 2 + 6 files changed, 250 insertions(+) create mode 100644 client/frequency-list/index.html create mode 100644 client/frequency-list/subcategory.html create mode 100644 client/frequency-list/subcategory.js create mode 100644 routes/frequency-list.js diff --git a/client/frequency-list/index.html b/client/frequency-list/index.html new file mode 100644 index 00000000..f844a529 --- /dev/null +++ b/client/frequency-list/index.html @@ -0,0 +1,119 @@ + + + + + QB Reader + + + + + + + + + + + + + + + + +
+

+ Choose a link below to view frequency lists for that subcategory: +

+
+ + + + + + diff --git a/client/frequency-list/subcategory.html b/client/frequency-list/subcategory.html new file mode 100644 index 00000000..34c2dc89 --- /dev/null +++ b/client/frequency-list/subcategory.html @@ -0,0 +1,91 @@ + + + + + QB Reader + + + + + + + + + + + + + + + + +
+

+ + The 100 most frequent answers in questions: + + + Back to all frequency lists + +

+ + + + + + + + + +
#AnswerFrequency
+
Loading...
+
+ + + + + + + diff --git a/client/frequency-list/subcategory.js b/client/frequency-list/subcategory.js new file mode 100644 index 00000000..908b03a5 --- /dev/null +++ b/client/frequency-list/subcategory.js @@ -0,0 +1,23 @@ +function titleCase(name) { + return name.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase()); +} + +const subcategory = titleCase(window.location.pathname.split('/').at(-1)); +document.getElementById('subcategory-name').textContent = subcategory; + +fetch(`/api/frequency-list?subcategory=${subcategory}`) + .then(response => response.json()) + .then(response => { + const { frequencyList } = response; + const table = document.getElementById('frequency-list'); + + for (const index in frequencyList) { + const { answer, count } = frequencyList[index]; + const row = table.insertRow(); + row.insertCell().textContent = parseInt(index) + 1; + row.insertCell().textContent = answer; + row.insertCell().textContent = count; + } + + document.getElementsByClassName('spinner-border')[0].remove(); + }); diff --git a/client/index.html b/client/index.html index 061d6dc6..ee0f16d5 100644 --- a/client/index.html +++ b/client/index.html @@ -113,6 +113,9 @@

Feature of the Day:

Check out your geoword category stats by going to the stats page for a packet!

+

+ Check out frequency lists for the qbreader database here! +

diff --git a/routes/frequency-list.js b/routes/frequency-list.js new file mode 100644 index 00000000..fc420a6b --- /dev/null +++ b/routes/frequency-list.js @@ -0,0 +1,12 @@ +import { Router } from 'express'; +const router = Router(); + +router.get('/', (req, res) => { + res.sendFile('index.html', { root: './client/frequency-list' }); +}); + +router.get('/:subcategory', (req, res) => { + res.sendFile('subcategory.html', { root: './client/frequency-list' }); +}); + +export default router; diff --git a/routes/index.js b/routes/index.js index f1bbf289..7af07da1 100644 --- a/routes/index.js +++ b/routes/index.js @@ -5,6 +5,7 @@ import apiDocsRouter from './api-docs.js'; import authRouter from './auth/index.js'; import backupsRouter from './backups.js'; import databaseRouter from './database.js'; +import frequencyListRouter from './frequency-list.js'; import geowordRouter from './geoword/index.js'; import multiplayerRouter from './multiplayer.js'; import settingsRouter from './settings.js'; @@ -97,6 +98,7 @@ router.use('/api-docs', apiDocsRouter); router.use('/auth', authRouter); router.use('/backups', backupsRouter); router.use('/db', databaseRouter); +router.use('/frequency-list', frequencyListRouter); router.use('/geoword', geowordRouter); router.use('/multiplayer', multiplayerRouter); router.use('/settings', settingsRouter);