From ef8a3339b4c9b0b28691cb1c6908e65c157892e2 Mon Sep 17 00:00:00 2001 From: YUCLing Date: Mon, 18 Nov 2024 09:49:25 +0800 Subject: [PATCH] wip: remove jquery removed jquery from components: - AvatarEditor - CommentPost - HeaderList - LogInButton - NotificationGrid - PostMeta - PostsPage - PostStream - ReplyPlaceholder - SignUpModal - WelcomeHero - ComposerState fix: wrong usage of select fix: incorrect selector syntax --- .../components/AutocompleteDropdown.tsx | 2 +- .../src/common/components/EditUserModal.tsx | 2 +- .../js/src/common/components/FormModal.tsx | 4 +- .../js/src/common/utils/heightWithMargin.ts | 4 + .../core/js/src/common/utils/scrollEnd.ts | 24 ++++ .../js/src/forum/components/AvatarEditor.js | 18 +-- .../js/src/forum/components/CommentPost.js | 25 ++-- .../js/src/forum/components/HeaderList.tsx | 16 +-- .../js/src/forum/components/LogInButton.js | 5 +- .../src/forum/components/NotificationGrid.js | 20 ++- .../core/js/src/forum/components/PostMeta.tsx | 2 +- .../js/src/forum/components/PostStream.js | 130 +++++++++--------- .../js/src/forum/components/PostsPage.tsx | 3 +- .../src/forum/components/ReplyPlaceholder.tsx | 4 +- .../core/js/src/forum/components/Search.tsx | 2 +- .../js/src/forum/components/SignUpModal.tsx | 4 +- .../js/src/forum/components/WelcomeHero.tsx | 14 +- .../js/src/forum/states/ComposerState.tsx | 4 +- framework/core/less/forum/Post.less | 2 +- 19 files changed, 160 insertions(+), 125 deletions(-) create mode 100644 framework/core/js/src/common/utils/heightWithMargin.ts create mode 100644 framework/core/js/src/common/utils/scrollEnd.ts diff --git a/framework/core/js/src/common/components/AutocompleteDropdown.tsx b/framework/core/js/src/common/components/AutocompleteDropdown.tsx index b314d881c7..68859dda7d 100644 --- a/framework/core/js/src/common/components/AutocompleteDropdown.tsx +++ b/framework/core/js/src/common/components/AutocompleteDropdown.tsx @@ -107,7 +107,7 @@ export default abstract class AutocompleteDropdown< m.redraw(); this.addEventListener('mouseup', (e) => e.preventDefault(), { once: true }); - this.dispatchEvent(new Event('select')); + this.select(); }); input.addEventListener('blur', () => { component.hasFocus = false; diff --git a/framework/core/js/src/common/components/EditUserModal.tsx b/framework/core/js/src/common/components/EditUserModal.tsx index 75a418dd8f..36707005ac 100644 --- a/framework/core/js/src/common/components/EditUserModal.tsx +++ b/framework/core/js/src/common/components/EditUserModal.tsx @@ -109,7 +109,7 @@ export default class EditUserModal { + let lastTop = container.scrollTop; + + return new Promise((resolve) => { + const animFrame = () => { + if (lastTop === container.scrollTop) { + resolve(); + } else { + requestAnimationFrame(animFrame); + lastTop = container.scrollTop; + } + }; + requestAnimationFrame(animFrame); + }); +} \ No newline at end of file diff --git a/framework/core/js/src/forum/components/AvatarEditor.js b/framework/core/js/src/forum/components/AvatarEditor.js index fd1da14226..c40ae7968e 100644 --- a/framework/core/js/src/forum/components/AvatarEditor.js +++ b/framework/core/js/src/forum/components/AvatarEditor.js @@ -149,15 +149,15 @@ export default class AvatarEditor extends Component { // Create a hidden HTML input element and click on it so the user can select // an avatar file. Once they have, we will upload it via the API. - const $input = $(''); - - $input - .appendTo('body') - .hide() - .click() - .on('input', (e) => { - this.upload($(e.target)[0].files[0]); - }); + const input = document.createElement('input'); + input.type = 'file'; + input.accept = '.jpg, .jpeg, .png, .bmp, .gif'; + input.style.display = 'none'; + input.click(); + input.addEventListener('input', (e) => { + this.upload(e.target.files[0]); + }); + document.body.append(input); } /** diff --git a/framework/core/js/src/forum/components/CommentPost.js b/framework/core/js/src/forum/components/CommentPost.js index ab17245794..7e61d3fb20 100644 --- a/framework/core/js/src/forum/components/CommentPost.js +++ b/framework/core/js/src/forum/components/CommentPost.js @@ -82,12 +82,12 @@ export default class CommentPost extends Post { // all of the