Update javascript app structure

This commit is contained in:
Patrick Jentsch
2024-12-03 15:59:08 +01:00
parent 12a3ac1d5d
commit aafb3ca3ec
23 changed files with 342 additions and 183 deletions

View File

@ -9,8 +9,9 @@
output='gen/nopaque.%(version)s.js',
'js/index.js',
'js/app.js',
'js/app.ui.js',
'js/app.users.js',
'js/app/ui.js',
'js/app/user-live-registry.js',
'js/app/users.js',
'js/utils.js',
'js/forms/index.js',
@ -75,41 +76,35 @@
{% endassets -%}
<script>
// TODO: Implement an app.run method and use this for all of the following
const app = new nopaque.App();
app.init();
// TODO: Implement an app.run method and use this for all of the following
const app = new nopaque.App();
app.init();
{% if current_user.is_authenticated -%}
// TODO: Set this as a property of the app object
const currentUserId = {{ current_user.hashid|tojson }};
{% if current_user.is_authenticated -%}
const currentUserId = {{ current_user.hashid|tojson }};
// Subscribe to the current user's data events
app.users.subscribe(currentUserId)
app.liveUserRegistry.add(currentUserId)
.catch((error) => {throw JSON.stringify(error);});
// Get the current user's data
app.users.get(currentUserId, true, true)
.catch((error) => {throw JSON.stringify(error);});
{% if not current_user.terms_of_use_accepted -%}
M.Modal.getInstance(document.querySelector('#terms-of-use-modal')).open();
{% endif -%}
{% endif -%}
{% if not current_user.terms_of_use_accepted -%}
M.Modal.getInstance(document.querySelector('#terms-of-use-modal')).open();
{% endif -%}
{% endif -%}
// Display flashed messages
for (let [category, message] of {{ get_flashed_messages(with_categories=True)|tojson }}) {
// Display flashed messages
for (let [category, message] of {{ get_flashed_messages(with_categories=True)|tojson }}) {
app.ui.flash(message, message);
}
}
</script>
<script>
let languageModalSwitch = document.querySelector('#terms-of-use-modal-switch');
let termsOfUseModalContent = document.querySelectorAll('.terms-of-use-modal-content');
if (languageModalSwitch) {
languageModalSwitch.addEventListener('change', function() {
termsOfUseModalContent.forEach(content => {
let languageModalSwitch = document.querySelector('#terms-of-use-modal-switch');
let termsOfUseModalContent = document.querySelectorAll('.terms-of-use-modal-content');
if (languageModalSwitch) {
languageModalSwitch.addEventListener('change', () => {
termsOfUseModalContent.forEach(content => {
content.classList.toggle('hide');
});
});
});
}
}
</script>