في نهاية المطاف، أحتاج إلى زر موضوع جديد في جسم قائمة الموضوعات في سمة Discourse المركزية. كل مهندس يشتكي من أنه لا يحب زر “بدء محادثة جديدة” الموجود في أسفل قائمة الموضوعات داخل كل فئة. لا يريدون استخدام خيار قائمة “موضوع جديد” في الأعلى لأن ذلك لا يبدأ الموضوع في الفئة التي يتواجدون فيها حاليًا.
لقد قمت بتشغيل هذا عبر Llama 3.1 405B وكذلك GPT-4 عبر ask.discourse.com ولكن لم أتمكن من الحصول على إصدار من JavaScript يمكن تجميعه. أحصل باستمرار على خطأ في التجميع: SyntaxError: Private field must be used in an enclosing class
أحصل أيضًا على خطأ في سجل الأدوات (widget registry error) ولكن ذلك لأن الأداة المخصصة (custom widget) لا يتم إنشاؤها أبدًا بسبب خطأ تجميع JavaScript.
أنا أستخدم سمة 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>
{{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>

