Skip to content
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

Convert AccountEdit and AccountEditAvatar to typescript #11209

Merged
merged 36 commits into from
May 16, 2024

Conversation

notbakaneko
Copy link
Collaborator

@notbakaneko notbakaneko commented May 13, 2024

Moved the extensions on the html element handling the state into a separate class.

Also removed the value == prevValue check since the request can be aborted before or after the server has already processed it, which means the last value may or may not be wrong already.

A proper check would be to check against the known saved value or initial value which doesn't happen since the way it's currently set up, the first known value is after the change.
only fixed initial value check for where the defaultValue is usable (so not checkboxes)
Removed the no update on default check because things may not update as expected when navigating away and restoring the page state, regardless of cancelling the xhr or not due to the actually state being nebulous unless all the settings are fully reloaded.

Because when navigating away during an update, the actually settings may or may not have been successfully updated if the page's state is restored, so the 'default' value may actually be wrong without refreshing the page.
Comment on lines 19 to 21
const elem = this.main[0];

return elem instanceof HTMLElement ? elem : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well just use querySelector and assign on page load or something

$(document).on('dragover', '.js-account-edit-avatar', this.overlayHover);
}

initialize = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private readonly?

private readonly handleInputChange = (e: ContainerEvent) => {
const container = e.currentTarget;

if (container.dataset.accountEditAutoSubmit !== '1') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well use different class altogether. Saves checking dataset everywhere

Comment on lines 33 to 34
container.state ??= new AccountEditState(container, this.core);
container.state.saving();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a this.getState(container)?

private getValue() {
let value: string | string[] | undefined;

if (this.dataset.accountEditType === 'array') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case?

Comment on lines 81 to 82
this.timeout = window.setTimeout(() => {
this.dataset.accountEditState = '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setTimeout(this.clear, ...)?

this.dataset.accountEditState = 'saving';
}

private getMultiValue() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and getValue can probably be merged into data?

(and if anything this is more like getMultiData since it includes the field name)

let value: string | string[] | undefined;

if (this.dataset.accountEditType === 'array') {
value = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the initial empty string is required to allow unselecting everything

Comment on lines 108 to 110
if (value == null) {
throw new Error('missing radio value');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be in the radio case? 🤨 or at least the message implies so

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, I guess it does narrow the type down properly for the return 🤔

@nanaya nanaya enabled auto-merge May 16, 2024 12:32
@nanaya nanaya merged commit 02204e9 into ppy:master May 16, 2024
3 checks passed
@notbakaneko notbakaneko deleted the feature/ts-account-edit branch May 17, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants