Js.composer.reply_placeholder 适用于新主题和回复

问题描述

js.compser.reply_placeholder 文本在创建主题时似乎与撰写器中的文本耦合,尽管它是回复特定的。

如何重现?

可以通过比较占位符文本的修改版本和撰写器来看到这一点。

一些想到的修复方法

一种修复方法可能是更改占位符的名称,但是我们非常希望能够单独修改回复和创建的占位符。

为什么创建和回复占位符会很有用?

如下所示,我们已开始为新主题使用以下占位符文本。但是,在回复的上下文中,此指南毫无意义。


image

如果此修复程序导致回复和创建都有占位符,我们将能够为所有用户提供改进的即时指导(这对我们这样的支持社区来说将是惊人的)。

2 个赞

也许这个主题中的代码能帮到你

2 个赞

:heart: 这是一个很棒的发现。我快速试了一下,它似乎能很好地分离回复并创建占位符。很希望看到这个更改被合并到核心代码中,但我也很高兴能使用 Joe 提供的更改。感谢分享 @Moin

4 个赞

作为后续,Joe 发布的代码片段在我们新的主题按钮中未能按预期工作:当用户在阅读某个主题时创建新主题,他们会收到回复文本。

下面是一种替代方法,它:

  • 为新主题提供占位符,无论它们是在“分类”页面还是在主题内启动的
  • 为回复提供不同的占位符
<script type="text/discourse-plugin" version="0.8">
// Custom placeholders
const placeHolderForReplies = `When helping someone else:

1. Describe what you think the problem is
2. Tell them what you think they should do
3. Show them how to do it (code snippets, images, etc)
4. Include links and references `;

const placeHolderForNewTopics = `Type here.

1. Tell us what you're trying to do.
2. Tell us what you already tried.
3. Post error logs as code snippets.`;

// Import required modules
const discourseComputed = require("discourse-common/utils/decorators").default;
const currentLocale = I18n.currentLocale();
I18n.translations[currentLocale].js.composer.custom_reply_placeholder = placeHolderForReplies;
I18n.translations[currentLocale].js.composer.custom_topic_placeholder = placeHolderForNewTopics;

api.modifyClass("component:composer-editor", {
  @discourseComputed("composer.replyingToTopic", "composer.creatingTopic")
  replyPlaceholder(replyingToTopic, creatingTopic) {
    // Determine if the composer is for replying or creating a new topic
    if (creatingTopic) {
      return "composer.custom_topic_placeholder";  // New topic placeholder
    } else if (replyingToTopic) {
      return "composer.custom_reply_placeholder";  // Reply placeholder
    }
    return this._super(...arguments);  // Fallback to default behavior
  }
});

</script>

2 个赞

还有

3 个赞