最終的に、Discourse Central テーマのトピックリスト本文に新しいトピックボタンが必要です。すべてのエンジニアが、各カテゴリ内のトピックリストの最下部にある「新しい会話を開始」ボタンを気に入らないと不満を言っています。上部の「新しいトピック」メニュー選択肢を使いたくないのは、現在いるカテゴリでトピックが開始されないためです。
これは Llama 3.1 405B および ask.discourse.com 経由の GPT-4 で試しましたが、コンパイルできる JavaScript のバージョンが得られません。常に「コンパイルエラー: SyntaxError: プライベートフィールドは囲むクラスで使用する必要があります」というエラーが発生します。
カスタムウィジェットが JS コンパイルエラーのために作成されないため、ウィジェットレジストリエラーも発生します。
Discourse Central テーマを使用しています。
このヘッダーセクションを与えられた場合:
"<script type=\"text/discourse-plugin\" version=\"0.8.18\">
api.createWidget('custom-new-topic-button', {
tagName: 'div.custom-new-topic-button',
buildKey: () => `custom-new-topic-button`,
html() {
return [
this.attach('button', {
className: 'btn btn-primary',
action: 'createNewTopic',
contents: 'New Topic'
})
];
},
click() {
const composerController = this.container.lookup("controller:composer");
const currentCategory = this.container.lookup("controller:navigation/category").get("model.id");
composerController.open({
action: require("discourse/models/composer").default.CREATE_TOPIC,
draftKey: require("discourse/models/composer").default.DRAFT,
categoryId: currentCategory,
});
return false;
},
});
api.decorateWidget('topic-list:before', (helper) => {
if (api.getCurrentUser()) {
helper.appendChild(helper.createWidget('custom-new-topic-button'));
}
});
</script>"
このヘッダーセクションで:
<script>
{{#if currentUser}}
<div class="topic-list-body-new-topic">
{{custom-new-topic-button}}
</div>
{{/if}}
</script>
そしてこのCSS:
.topic-list-body::before {
content: "";
display: block;
position: relative; /* Important to allow absolute positioning within */
}
.topic-list-body-new-topic {
position: absolute;
top: 0;
left: 0;
padding: 10px;
background: #f2f3f5;
border-bottom: 1px solid #ccc;
}
.custom-new-topic-button .btn.btn-primary {
background-color: #007bff;
border-color: #007bff;
color: #fff;
}
これが私の元のコードでした。最新の推奨事項は次のとおりです。
<script type="text/discourse-plugin" version="0.8.18">
api.createWidget('custom-new-topic-button', {
tagName: 'div.custom-new-topic-button',
buildKey() {
return 'custom-new-topic-button';
},
defaultState() {
return {};
},
html() {
return [
this.attach('button', {
className: 'btn btn-primary',
action: 'createNewTopic',
contents: 'New Topic'
})
];
},
createNewTopic() {
const composerController = this.container.lookup("controller:composer");
const currentCategory = this.container.lookup("controller:navigation/category").get("model.id");
const Composer = require("discourse/models/composer").default;
composerController.open({
action: Composer.CREATE_TOPIC,
draftKey: Composer.DRAFT,
categoryId: currentCategory,
});
return false;
},
});
api.decorateWidget('topic-list:before', (helper) => {
if (api.getCurrentUser()) {
helper.appendChild(helper.createWidget('custom-new-topic-button'));
}
});
</script>

