From 4f27259e275a15093a550f8bca0956706cec8885 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 26 Jun 2017 14:30:09 -0400 Subject: [PATCH] UX: Make the edit wiki button more prominent --- .../discourse/widgets/post-menu.js.es6 | 48 ++++++++++++++++++- config/locales/client.en.yml | 1 + 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 index 4c39f4a5421..2333135fc71 100644 --- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 @@ -86,6 +86,35 @@ registerButton('edit', attrs => { } }); +registerButton('reply-small', attrs => { + if (!attrs.canCreatePost) { return; } + + const args = { + action: 'replyToPost', + title: 'post.controls.reply', + icon: 'reply', + className: 'reply', + }; + + return args; +}); + +registerButton('wiki-edit', attrs => { + if (attrs.canEdit) { + const args = { + action: 'editPost', + className: 'edit create', + title: 'post.controls.edit', + icon: 'pencil-square-o', + alwaysShowYours: true + }; + if (!attrs.mobileView) { + args.label = 'post.controls.edit_action'; + } + return args; + } +}); + registerButton('replies', (attrs, state, siteSettings) => { const replyCount = attrs.replyCount; @@ -180,6 +209,13 @@ registerButton('delete', attrs => { } }); +function replaceButton(buttons, find, replace) { + const idx = buttons.indexOf(find); + if (idx !== -1) { + buttons[idx] = replace; + } +} + export default createWidget('post-menu', { tagName: 'section.post-menu-area.clearfix', @@ -209,7 +245,17 @@ export default createWidget('post-menu', { const allButtons = []; let visibleButtons = []; - siteSettings.post_menu.split('|').forEach(i => { + + const orderedButtons = siteSettings.post_menu.split('|'); + + // If the post is a wiki, make Edit more prominent + if (attrs.wiki) { + replaceButton(orderedButtons, 'edit', 'reply-small'); + replaceButton(hiddenButtons, 'edit', 'reply-small'); + replaceButton(orderedButtons, 'reply', 'wiki-edit'); + } + + orderedButtons.forEach(i => { const button = this.attachButton(i, attrs); if (button) { allButtons.push(button); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 4e7bcd34123..8aa17f9e58a 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1848,6 +1848,7 @@ en: has_liked: "you've liked this post" undo_like: "undo like" edit: "edit this post" + edit_action: "Edit" edit_anonymous: "Sorry, but you need to be logged in to edit this post." flag: "privately flag this post for attention or send a private notification about it" delete: "delete this post"