Skip to content

Commit

Permalink
pwa stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-thepie committed Sep 24, 2024
1 parent e080e4e commit 13bccf5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ <h3>Explanation of Levels:</h3>
</main>

<footer>
<p class="installstrap">You can <button class="install">Install this as an app</button> to find it easily later, if
your browser supports it :)</p>
<p>Any questions? <a href="https://discord.com/servers/computing-uni-of-portsmouth-760155974467059762">Join us on
Discord</a> or email [email protected]</p>
</footer>
Expand Down
22 changes: 21 additions & 1 deletion docs/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as core from './core.js';

let data = {};
let deferredPrompt;
const ui = {};
ui.main = document.querySelector('main');
ui.header = document.querySelector('header');
ui.footer = document.querySelector('footer');
ui.levels = document.querySelectorAll('section.level');
ui.topnav = document.querySelector('.top-nav');
ui.coursenav = document.querySelector('.course-nav');
Expand Down Expand Up @@ -248,7 +249,25 @@ function populateEvent(day, event) {
eventElem.dataset.time = event.time;
}

function bindInstall() {
const installApp = ui.footer.querySelector('.install');
installApp.addEventListener('click', async () => {
if (deferredPrompt !== null) {
deferredPrompt.prompt();
const { outcome } = await deferredPrompt.userChoice;
if (outcome === 'accepted') {
deferredPrompt = null;
}
}
});
}

async function main() {
window.addEventListener('beforeinstallprompt', (e) => {
deferredPrompt = e;
});


await fetchData();
setTitle();
populate();
Expand All @@ -257,6 +276,7 @@ async function main() {
if (localStorage.getItem('course') && localStorage.getItem('level')) {
showPlan();
}
bindInstall();
}

main();
4 changes: 1 addition & 3 deletions docs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ footer {
text-align: center;
}

footer p {
margin: 3.5em;
}


header {
background: var(--main-bg-color);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index"
"start": "node svr"
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit 13bccf5

Please sign in to comment.