FIX: restore button to add user notes to post admin menu (#85)

* FIX: use api.addPostAdminMenuButton for modifying post admin menu instead of widget

We use app events here to force refresh of specific post, as previously the behaviour of the widget would trigger the re-render at the same time as the primary actions. This could also be handled in the modal instead of via the action passed by the button.

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
Kelv 2023-10-26 18:07:30 +08:00 committed by GitHub
parent 134fcba29b
commit 6b66a06174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 15 deletions

View File

@ -1,2 +1,3 @@
< 3.2.0.beta2-dev: 134fcba29baf2ca92ec555dab1707c096712af14
3.1.999: 20f8f68d127a923942cca11a586caf4ea14019eb
2.9.0.beta12: 7137499c69065928c0fdd8795a3fb8d175e1ff3d

View File

@ -10,6 +10,8 @@ export default {
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
const currentUser = container.lookup("current-user:main");
const appEvents = container.lookup("service:app-events");
if (
!siteSettings.user_notes_enabled ||
!currentUser ||
@ -68,8 +70,13 @@ export default {
return;
}
const cfs = dec.attrs.userCustomFields || {};
if (cfs.user_notes_count > 0) {
const post = dec.getModel();
if (!post) {
return;
}
const ucf = post.user_custom_fields || {};
if (ucf.user_notes_count > 0) {
return dec.attach("user-notes-icon");
}
});
@ -79,23 +86,39 @@ export default {
return;
}
const cfs = dec.attrs.userCustomFields || {};
if (cfs.user_notes_count > 0) {
const post = dec.getModel();
if (!post) {
return;
}
const ucf = post.user_custom_fields || {};
if (ucf.user_notes_count > 0) {
return dec.attach("user-notes-icon");
}
});
api.addPostAdminMenuButton((attrs) => {
return {
icon: "pencil-alt",
label: "user_notes.attach",
action: (post) => {
showUserNotes(
store,
attrs.user_id,
(count) => {
const ucf = post.user_custom_fields || {};
ucf.user_notes_count = count;
post.set("user_custom_fields", ucf);
api.decorateWidget("post-admin-menu:after", (dec) => {
return dec.h(
"ul",
dec.attach("post-admin-menu-button", {
icon: "pencil-alt",
label: "user_notes.attach",
action: "showUserNotes",
secondaryAction: "closeAdminMenu",
className: "add-user-note",
})
);
appEvents.trigger("post-stream:refresh", {
id: post.id,
});
},
{ postId: attrs.id }
);
},
secondaryAction: "closeAdminMenu",
className: "add-user-note",
};
});
api.attachWidgetAction("post", "showUserNotes", widgetshowUserNotes);