-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💻 autosave feature #5311
💻 autosave feature #5311
Conversation
- debounced every 1min
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @hasan-sh!
A few notes:
The (i) text appears in a weird place:
(not sure that is caused by this PR?)
The back button does not work anymore:
For the password save, I doubt whether we want an autosave? Somehow that (like making a profile public) feels like a very deliberate action. What do you think?
Which one exactly?
Correct! I think @Annelein was going to fix this issue after adding all go back buttons?
I agree, shall i remove it? |
Great, that's now solved by #5349 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hasan-sh! This is a very cool feature, and I love it. I just had a couple of comments about code and functionality. Thanks!
static/js/autosave.ts
Outdated
) { | ||
// Debounce function to prevent excessive requests | ||
const formElement = document.getElementById(formId) as HTMLFormElement; | ||
console.log(formId, formElement, customEvent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opps, can you delete this debug console log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks will do:)
const DEBOUNCE_TIMEOUT = 1000; | ||
|
||
let timeoutId: ReturnType<typeof setTimeout> | null = null; | ||
function debounce<F extends (...args: any[]) => any> (func: F, delay: number): (...args: Parameters<F>) => void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this solution!
templates/customize-adventure.html
Outdated
@@ -209,4 +210,13 @@ <h3>{{_('adventure_exp_classes')}}</h3> | |||
</div> | |||
</div> | |||
</div> | |||
<script> | |||
document.addEventListener("DOMContentLoaded", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A while ago we were trying to get away from adding scripts to the templates, because we wanted all javascript code to be in a single place. I think you could use initiliaze.ts
to initialize these functions in JavaScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why though? I mean we don't really need to initialize anything if the route is not in the wanted page! What I do know is that the main issues with having different scripts is that it could cause a sluggish experience. Was there another (specific) problem we faced? I see that we still use it in some places!!
We could put it in initialize.ts, but it's not as incapsulated as this is! Perhaps it's a matter of docummentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason is that if all code is in one place, it is easy to see what is there. In the past we ran into the issue that similar code was in multiple places and when something was changed, some locations were overlooked. People might not look for js inside an HTML file (it is a sort of separation of concerns)
So I support the idea of having as much in one place as possible!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree about the separation of cencerns concern. Will change it.
Two points. First, so the current scripts that are in html files we still have to clean up? And second there's several downsides of our current approach. The main and crucial one is that gradually more and more TS must be loaded even though it's not in use yet. This affects the overall performance of our app. If you're satisfied with the overall performance, we tackle it when needed. Just good to keep it in mind i think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two points. First, so the current scripts that are in html files we still have to clean up?
Yes, I would assume so! There is a lot of places where we still have js/ts in the HTML files, and we like to move that to HTMX or to a typescript file. I don't necessarily think we should do all of that right away, but maybe if you encounter it while working on other things, you can try to clean it up piece by piece. You can also do a bit of cleanup in between other tasks if you think it is a fun palet cleanser!
The main and crucial one is that gradually more and more TS must be loaded even though it's not in use yet.
I don't think that is where the bottle neck of performance is, but yes let's keep it in mind!
templates/profile.html
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to prevent this page from reloading every time I click on one of the options? The autosave works great, but that makes this page a little bit annoying to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which options do you mean? I see it only reloads if we change the language or keyword language! These require a reload since the Ui changes accordingly!
Should be good to go @jpelay !! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork). |
Fixes #4888
Note
The
autoSave
function that i created can be used generically. So, in case we need it in the future, these are the steps that are needed:Furthermore, sometimes there's an element that we cannot attach an event listener on, like the CKEditor. In this case, you can pass an event as a secon argument to the
autoSave
function. When you do this, we simply invoke the submit trigger on the form element.The customize-class page has two differently implemented features. The sortable adventures and the other inputs below. These two have to be syncronized. If we hide all quizzes, for instance, we want the adventure tabs to be updated. Now, instead of changing the whole structure, a third argument could be passed indicating that we should trigger an event on a certain element. See the autosave.ts file on how it's used.
How to test?
check the description of #4888 and test these pages.