DEV: Convert actions-summary to a component (#26337)
This commit is contained in:
parent
0aec53ee9b
commit
e840d01151
|
@ -0,0 +1,30 @@
|
||||||
|
import avatar from "discourse/helpers/bound-avatar-template";
|
||||||
|
import formatDate from "discourse/helpers/format-date";
|
||||||
|
import dIcon from "discourse-common/helpers/d-icon";
|
||||||
|
|
||||||
|
const ActionsSummary = <template>
|
||||||
|
{{#each @data.actionsSummary as |as|}}
|
||||||
|
<div class="post-action">{{as.description}}</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
{{/each}}
|
||||||
|
{{#if @data.deleted_at}}
|
||||||
|
<div class="post-action deleted-post">
|
||||||
|
{{dIcon "far-trash-alt"}}
|
||||||
|
<a
|
||||||
|
class="trigger-user-card"
|
||||||
|
data-user-card={{@data.deletedByUsername}}
|
||||||
|
title={{@data.deletedByUsername}}
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
{{avatar
|
||||||
|
@data.deletedByAvatarTemplate
|
||||||
|
"tiny"
|
||||||
|
title=@data.deletedByUsername
|
||||||
|
}}
|
||||||
|
</a>
|
||||||
|
{{formatDate @data.deleted_at format="tiny"}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</template>;
|
||||||
|
|
||||||
|
export default ActionsSummary;
|
|
@ -0,0 +1,75 @@
|
||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
import avatar from "discourse/helpers/bound-avatar-template";
|
||||||
|
import { userPath } from "discourse/lib/url";
|
||||||
|
import i18n from "discourse-common/helpers/i18n";
|
||||||
|
import getURL from "discourse-common/lib/get-url";
|
||||||
|
|
||||||
|
export default class SmallUserList extends Component {
|
||||||
|
@service currentUser;
|
||||||
|
|
||||||
|
smallUserAtts(user) {
|
||||||
|
return {
|
||||||
|
template: user.avatar_template,
|
||||||
|
username: user.username,
|
||||||
|
post_url: user.post_url,
|
||||||
|
url: userPath(user.username_lower),
|
||||||
|
unknown: user.unknown,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get users() {
|
||||||
|
let users = this.args.data.users;
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.args.data.addSelf &&
|
||||||
|
!users.some((u) => u.username === this.currentUser.username)
|
||||||
|
) {
|
||||||
|
users = users.concat(this.smallUserAtts(this.currentUser));
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
get postUrl() {
|
||||||
|
const url = this.users.find((user) => user.post_url);
|
||||||
|
if (url) {
|
||||||
|
return getURL(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<template>
|
||||||
|
{{#each this.users as |user|}}
|
||||||
|
{{#if user.unknown}}
|
||||||
|
<div
|
||||||
|
title={{i18n "post.unknown_user"}}
|
||||||
|
class="unknown"
|
||||||
|
role="listitem"
|
||||||
|
></div>
|
||||||
|
{{else}}
|
||||||
|
<a
|
||||||
|
class="trigger-user-card"
|
||||||
|
data-user-card={{user.username}}
|
||||||
|
title={{user.username}}
|
||||||
|
aria-hidden="false"
|
||||||
|
role="listitem"
|
||||||
|
>
|
||||||
|
{{avatar user.template "tiny"}}
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
{{#if @data.description}}
|
||||||
|
{{#if this.postUrl}}
|
||||||
|
<a href={{this.postUrl}}>
|
||||||
|
<span aria-hidden="true" class="list-description">
|
||||||
|
{{i18n @data.description count=@data.count}}
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
{{else}}
|
||||||
|
<span aria-hidden="true" class="list-description">
|
||||||
|
{{i18n @data.description count=@data.count}}
|
||||||
|
</span>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
</template>
|
||||||
|
}
|
|
@ -1,20 +1,8 @@
|
||||||
import { h } from "virtual-dom";
|
import { hbs } from "ember-cli-htmlbars";
|
||||||
import { userPath } from "discourse/lib/url";
|
import RenderGlimmer, {
|
||||||
import hbs from "discourse/widgets/hbs-compiler";
|
registerWidgetShim,
|
||||||
import { avatarFor } from "discourse/widgets/post";
|
} from "discourse/widgets/render-glimmer";
|
||||||
import { createWidget } from "discourse/widgets/widget";
|
import { createWidget } from "discourse/widgets/widget";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
|
||||||
import I18n from "discourse-i18n";
|
|
||||||
|
|
||||||
export function smallUserAtts(user) {
|
|
||||||
return {
|
|
||||||
template: user.avatar_template,
|
|
||||||
username: user.username,
|
|
||||||
post_url: user.post_url,
|
|
||||||
url: userPath(user.username_lower),
|
|
||||||
unknown: user.unknown,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
createWidget("small-user-list", {
|
createWidget("small-user-list", {
|
||||||
tagName: "div.clearfix.small-user-list",
|
tagName: "div.clearfix.small-user-list",
|
||||||
|
@ -31,89 +19,22 @@ createWidget("small-user-list", {
|
||||||
return attributes;
|
return attributes;
|
||||||
},
|
},
|
||||||
|
|
||||||
html(atts) {
|
html(attrs) {
|
||||||
let users = atts.users;
|
return [
|
||||||
if (users) {
|
new RenderGlimmer(
|
||||||
const currentUser = this.currentUser;
|
this,
|
||||||
if (
|
"span.small-user-list-content",
|
||||||
atts.addSelf &&
|
hbs`<SmallUserList @data={{@data.attrs}}/>`,
|
||||||
!users.some((u) => u.username === currentUser.username)
|
{
|
||||||
) {
|
attrs,
|
||||||
users = users.concat(smallUserAtts(currentUser));
|
|
||||||
}
|
|
||||||
|
|
||||||
let description = null;
|
|
||||||
|
|
||||||
if (atts.description) {
|
|
||||||
description = h(
|
|
||||||
"span.list-description",
|
|
||||||
{ attributes: { "aria-hidden": true } },
|
|
||||||
I18n.t(atts.description, { count: atts.count })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// oddly post_url is on the user
|
|
||||||
let postUrl;
|
|
||||||
const icons = users.map((u) => {
|
|
||||||
postUrl = postUrl || u.post_url;
|
|
||||||
if (u.unknown) {
|
|
||||||
return h("div.unknown", {
|
|
||||||
attributes: {
|
|
||||||
title: I18n.t("post.unknown_user"),
|
|
||||||
role: "listitem",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return avatarFor.call(this, "small", u, {
|
|
||||||
role: "listitem",
|
|
||||||
"aria-hidden": false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (postUrl) {
|
|
||||||
description = h(
|
|
||||||
"a",
|
|
||||||
{ attributes: { href: getURL(postUrl) } },
|
|
||||||
description
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let buffer = [icons];
|
|
||||||
if (description) {
|
|
||||||
buffer.push(description);
|
|
||||||
}
|
|
||||||
return buffer;
|
|
||||||
}
|
}
|
||||||
|
),
|
||||||
|
];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
createWidget("action-link", {
|
registerWidgetShim(
|
||||||
tagName: "span.action-link",
|
"actions-summary",
|
||||||
template: hbs`<a>{{attrs.text}}. </a>`,
|
"section.post-actions",
|
||||||
|
hbs`<ActionsSummary @data={{@data}} /> `
|
||||||
buildClasses(attrs) {
|
);
|
||||||
return attrs.className;
|
|
||||||
},
|
|
||||||
|
|
||||||
click() {
|
|
||||||
this.sendWidgetAction(this.attrs.action);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default createWidget("actions-summary", {
|
|
||||||
tagName: "section.post-actions",
|
|
||||||
template: hbs`
|
|
||||||
{{#each attrs.actionsSummary as |as|}}
|
|
||||||
<div class='post-action'>{{as.description}}</div>
|
|
||||||
<div class='clearfix'></div>
|
|
||||||
{{/each}}
|
|
||||||
{{#if attrs.deleted_at}}
|
|
||||||
<div class='post-action deleted-post'>
|
|
||||||
{{d-icon "far-trash-alt"}}
|
|
||||||
{{avatar size="small" template=attrs.deletedByAvatarTemplate username=attrs.deletedByUsername}}
|
|
||||||
{{date attrs.deleted_at}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
`,
|
|
||||||
});
|
|
||||||
|
|
|
@ -6,11 +6,11 @@ import AdminPostMenu from "discourse/components/admin-post-menu";
|
||||||
import DeleteTopicDisallowedModal from "discourse/components/modal/delete-topic-disallowed";
|
import DeleteTopicDisallowedModal from "discourse/components/modal/delete-topic-disallowed";
|
||||||
import { formattedReminderTime } from "discourse/lib/bookmark";
|
import { formattedReminderTime } from "discourse/lib/bookmark";
|
||||||
import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback";
|
import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback";
|
||||||
|
import { userPath } from "discourse/lib/url";
|
||||||
import {
|
import {
|
||||||
NO_REMINDER_ICON,
|
NO_REMINDER_ICON,
|
||||||
WITH_REMINDER_ICON,
|
WITH_REMINDER_ICON,
|
||||||
} from "discourse/models/bookmark";
|
} from "discourse/models/bookmark";
|
||||||
import { smallUserAtts } from "discourse/widgets/actions-summary";
|
|
||||||
import RenderGlimmer from "discourse/widgets/render-glimmer";
|
import RenderGlimmer from "discourse/widgets/render-glimmer";
|
||||||
import { applyDecorators, createWidget } from "discourse/widgets/widget";
|
import { applyDecorators, createWidget } from "discourse/widgets/widget";
|
||||||
import discourseLater from "discourse-common/lib/later";
|
import discourseLater from "discourse-common/lib/later";
|
||||||
|
@ -53,6 +53,16 @@ function registerButton(name, builder) {
|
||||||
_builders[name] = builder;
|
_builders[name] = builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function smallUserAtts(user) {
|
||||||
|
return {
|
||||||
|
template: user.avatar_template,
|
||||||
|
username: user.username,
|
||||||
|
post_url: user.post_url,
|
||||||
|
url: userPath(user.username_lower),
|
||||||
|
unknown: user.unknown,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function buildButton(name, widget) {
|
export function buildButton(name, widget) {
|
||||||
let { attrs, state, siteSettings, settings, currentUser } = widget;
|
let { attrs, state, siteSettings, settings, currentUser } = widget;
|
||||||
|
|
||||||
|
|
|
@ -534,7 +534,14 @@ aside.quote {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.small-user-list .unknown {
|
.small-user-list {
|
||||||
|
.small-user-list-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unknown {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background-color: var(--primary-low);
|
background-color: var(--primary-low);
|
||||||
width: 25px;
|
width: 25px;
|
||||||
|
@ -542,6 +549,7 @@ aside.quote {
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
margin-right: 0.25em;
|
margin-right: 0.25em;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-hidden {
|
.post-hidden {
|
||||||
|
|
Loading…
Reference in New Issue