If we successfully define a select-kit component within a plugin we are easily able to use it within a *.hbs template file using its pluginApiIdentifiers however, in order to attach that component within a widget using JS code I am not able to make it work. For instance:
And the snippet above will work flawlessly, BUT how I will include that component into a widget like:
api.reopenWidget('user-dropdown', {
html(attrs, state) {
if (this.site.mobileView) {
return h('div.profile-dropdown-container', [
this.attach('header-notifications', attrs),
--> I NEED ATTACH THE COMPONENT HERE <--
]);
}
...
}
});
NOTE: much of the code has been skipped to keep the post brief. Feel free to ask for the full code if needed.
PD: I have already tried to describe this issue at How to attach a component to a widget with just markup? but looks like it was a too complicated explanation so I am trying to reduce the information here to make it clear and try to find an answer.
I think it was a matter of ask myself the right question: “How to render a component within a widget?” that’s why I updated the topic title. I have found few results already such as: How to render Component inside Widget? I will take a look and post any useful finding if it is needed.
Sadly enough looks like it is not possible, simply put we need to find a way to create a widget instead to render what we need to and render a widget within a widget, cause using the connector there are a lot of limitations. Check also: Rendering Component in decorativeWidget API
same issue here.
this is really terrible frontend code that uses widgets and ember components in the same page, it’s really hard to revamp and maintain.
can’t understand what’s the logic
I wasn’t there when widgets were created, but as far as I can tell, it was created for performance reasons at a time where frontend and especially mobile frontend had huge performance issues. And for dev simplicity it was added the possibility to inject components into widgets.
You got to understand that Discourse carries some history and we can’t start from scratch every year.
آه… من المحتمل جدًا أن الترجمة المضمنة لا تعمل (حتى الآن) في مكونات السمات. يجب أن تعمل في المكونات الإضافية (منذ هذا الأسبوع). سأرى ما يمكنني فعله لإضافة دعم لمكونات السمات
يتم استدعاء onChangeUpdateTagSet للتغيير، ويتم استدعاء actionForClick عند الضغط على الزر.
ومع ذلك، أواجه صعوبة في إبقاء مُختار العلامات ممتلئًا.
بمجرد إدخال الإجراء المخصص الخاص بي لـ onChange، يفشل العنصر في تحديث العلامات المحددة في واجهته (على الرغم من أن المتغير المخصص الخاص بي يحتوي على القيم الصحيحة).
وإذا لم أقم بتضمين الإجراء المخصص الخاص بي لـ onChange، فإن واجهة المستخدم للعناصر تعمل مرة أخرى، ولكن لا يمكنني ملء مجموعتي.
حاولت إضافة this.scheduleRerender() إلى الدالة onChangeUpdateTagSet ولكن هذا يظهر كـ undefined - من الواضح أنه ليس في نطاقه؟
أضفت حدث نقر إلى الأداة وهي تقوم بعد ذلك بالتحديث مع عرض البيانات الصحيحة.
ومع ذلك، يبدو أن الربط يسير في اتجاه واحد فقط، لذا لا يمكنني استخدام العنصر لتحديث البيانات الخارجية، فقط لدفع بيانات جديدة إلى العنصر.
أعتقد أنك ستحتاج إلى استخدام widget ‘state’ بدلاً من الوصول إلى this.chosen - مثيلات الأداة قصيرة العمر و “عديمة الحالة”. ستحصل على مثيل جديد عند كل إعادة عرض، مما يعني أنه سيتم إعادة تعيين this.chosen.