-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add cropping support when modifying the user/org/repo avatar #33498
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
Conversation
When coding, need to do the best to avoid the unmaintainable code caused by copy-paste: 546f133 |
web_src/js/features/admin/common.ts
Outdated
@@ -258,4 +259,6 @@ export function initAdminCommon(): void { | |||
window.location.href = this.getAttribute('data-redirect'); | |||
}); | |||
} | |||
|
|||
initAvatarUploaderWithCropper(document.querySelector('.admin.edit.user input[name="avatar"]')); |
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.
That looks like a really fragile selector to me.
Can we perhaps have a distinct js class instead?
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.
Actually it is the right thing to do.
If you want to introduce a general selector, it needs much more work to make it compatible with multiple elements on the same page, which is not our case.
The current approach should be good and clear enough, and it is easy to refactor in the future.
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.
If you think it's worth to introduce a general selector, feel free to try to propose some changes to see whether it would be simpler and more stable than this selector.
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 mean…
As far as I can see, it's always the same action we perform.
So, wouldn't it make sense to invert the calls from each specific component takes care of initializing only its selector using the same method
to all elements matching this selector inside the document are initialized
?
Or am I missing any case where we need additional logic?
If we don't need to customize the initialization of any avatar cropper (-> all avatar croppers are initialized exactly the same), then we can unify the logic.
Otherwise, I agree with you.
So, can you think of a case where we might want separate initialization logic or are already using it?
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.
So, can you think of a case where we might want separate initialization logic or are already using it?
Yes, you are right, that's the key point.
Actually I have tried to use a general selector js-avatar-with-cropper
(some traces were still left in 006dd61 🤣 ), but at last I decided to drop it because overall it looks stranger in this case ......
TBH at the moment I haven't got a real case, that's just my opinion that such selector should be flexible and clear enough. (The combo-markdown-editor has a similar case: auto-init or not .... but that's another story)
gitea/web_src/js/features/common-form.ts
Line 34 in 7e596bd
queryElems<HTMLElement>(document, '.combo-markdown-editor:not(.custom-init)', (el) => initComboMarkdownEditor(el)); |
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.
By the way, I am planning some frontend changes to make the JS init system more stable. A brief idea is like this:
<button data-global-click="show-panel"></button>
<a data-global-click="link-acton"></a>
<div class="dropdown" data-global-init="initMyDropdown"></div>
<div class="editor" data-global-init="initComboMarkdownDropdown"></div>
<input name="avatar" data-global-init="initAvatarUploaderWithCropper">
Then we could resolve many longstanding problems:
- avoid many duplicate "init" calls (the case in this PR)
- incorrect init & double init (especially when use htmx or partial reloading)
But it is only a brief idea, just FYI
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.
If no more suggestions, I will vote my approval
…a#33498) Fixed go-gitea#33321 --------- Co-authored-by: wxiaoguang <[email protected]>
* giteaofficial/main: refactor: decouple context from migration structs (go-gitea#33399) Move gitgraph from modules to services layer (go-gitea#33527) Add go wrapper around git diff-tree --raw -r -M (go-gitea#33369) [skip ci] Updated translations via Crowdin Update MAINTAINERS (go-gitea#33529) Add cropping support when modifying the user/org/repo avatar (go-gitea#33498) [skip ci] Updated translations via Crowdin Add alphabetical project sorting (go-gitea#33504) Refactor gitdiff test (go-gitea#33507)
Fixed #33321