From 6dd0c0e915609437b03dd09b6b45383eb5381ddd Mon Sep 17 00:00:00 2001 From: IanM <16573496+imorland@users.noreply.github.com> Date: Sun, 29 Sep 2024 12:06:04 +0100 Subject: [PATCH] [1.x] [extensibility] chore: make PostMeta extensible (#4040) * chore: make PostMeta extensible * add prio for ip item --- .../core/js/src/forum/components/PostMeta.js | 101 ++++++++++++------ 1 file changed, 69 insertions(+), 32 deletions(-) diff --git a/framework/core/js/src/forum/components/PostMeta.js b/framework/core/js/src/forum/components/PostMeta.js index 78573db5bf..4a82f82a66 100644 --- a/framework/core/js/src/forum/components/PostMeta.js +++ b/framework/core/js/src/forum/components/PostMeta.js @@ -2,6 +2,7 @@ import app from '../../forum/app'; import Component from '../../common/Component'; import humanTime from '../../common/helpers/humanTime'; import fullTime from '../../common/helpers/fullTime'; +import ItemList from '../../common/utils/ItemList'; /** * The `PostMeta` component displays the time of a post, and when clicked, shows @@ -14,38 +15,7 @@ import fullTime from '../../common/helpers/fullTime'; */ export default class PostMeta extends Component { view() { - const post = this.attrs.post; - const time = post.createdAt(); - const permalink = this.getPermalink(post); - const touch = 'ontouchstart' in document.documentElement; - - // When the dropdown menu is shown, select the contents of the permalink - // input so that the user can quickly copy the URL. - const selectPermalink = function (e) { - setTimeout(() => $(this).parent().find('.PostMeta-permalink').select()); - - e.redraw = false; - }; - - return ( -
- - {humanTime(time)} - - -
- {app.translator.trans('core.forum.post.number_tooltip', { number: post.number() })}{' '} - {fullTime(time)} {post.data.attributes.ipAddress} - {touch ? ( - - {permalink} - - ) : ( - e.stopPropagation()} /> - )} -
-
- ); + return
{this.viewItems().toArray()}
; } /** @@ -57,4 +27,71 @@ export default class PostMeta extends Component { getPermalink(post) { return app.forum.attribute('baseOrigin') + app.route.post(post); } + + /** + * When the dropdown menu is shown, select the contents of the permalink + * input so that the user can quickly copy the URL. + * @param {Event} e + */ + selectPermalink(e) { + setTimeout(() => $(this.element).parent().find('.PostMeta-permalink').select()); + + e.redraw = false; + } + + /** + * @returns {ItemList} + */ + viewItems() { + const items = new ItemList(); + const post = this.attrs.post; + const time = post.createdAt(); + + items.add( + 'time', + this.selectPermalink(e)} data-toggle="dropdown"> + {humanTime(time)} + , + 100 + ); + + items.add('meta-dropdown',
{this.metaItems().toArray()}
, 90); + + return items; + } + + /** + * @returns {ItemList} + */ + metaItems() { + const items = new ItemList(); + const post = this.attrs.post; + const touch = 'ontouchstart' in document.documentElement; + const permalink = this.getPermalink(post); + const time = post.createdAt(); + + items.add( + 'post-number', + {app.translator.trans('core.forum.post.number_tooltip', { number: post.number() })} , + 100 + ); + + items.add('post-time', {fullTime(time)}, 90); + + items.add('post-ip', {post.data.attributes.ipAddress}, 80); + + items.add( + 'permalink', + touch ? ( + + {permalink} + + ) : ( + e.stopPropagation()} /> + ), + 0 + ); + + return items; + } }