# Ein Widget neu laden/aktualisieren, wenn ein anderes Widget aktualisiert wird

**URL:** <https://meta.discourse.org/t/reload-refresh-a-widget-on-refresh-of-another-widget/204356>\
**Category:** Development\
**Created:** [24. September 2021 um 06:16 UTC](https://meta.discourse.org/t/reload-refresh-a-widget-on-refresh-of-another-widget/204356 "2021-09-24T06:16:46Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![saurabhmasc](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@saurabhmasc](https://meta.discourse.org/u/saurabhmasc)\
**Post date:** [24. September 2021 um 06:16 UTC](https://meta.discourse.org/t/reload-refresh-a-widget-on-refresh-of-another-widget/204356/1 "2021-09-24T06:16:47Z")

</div>

Hallo zusammen,

wir haben ein Widget namens „topic-timeline-bookmark" erstellt, das den Lesezeichen-Button auf Themen-Ebene nach dem Widget „topic-timeline" anzeigt.

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/b/4b988d1b7603d2dbbdea5e444e0a4600b98f9397.png)

Wenn wir nun auf den Lesezeichen-Button von _ **topic-timeline** _ klicken, wird das Modal-Fenster zum Festlegen des Lesezeichens angezeigt. Beim Speichern des Lesezeichens werden die Lesezeichen-Buttons unter den _ **first-post-menu** _-Buttons und den _ **topic-footer-button** _ aktualisiert, aber der Button von _ **topic-timeline** _ selbst wird nicht aktualisiert, bis das Widget _ **topic-timeline** _ neu geladen wird (d. h. bis wir scrollen), und umgekehrt.

### first-post-menu

![image](https://global.discourse-cdn.com/meta/original/3X/6/3/630140d08aede405680568aa64a19df38940623c.png)

* * *

### topic-footer-button

![image](https://global.discourse-cdn.com/meta/original/3X/f/9/f90ab85e13915de396501c07977b7ad0758f7358.png)

Ich habe festgestellt, dass das Widget _ **post-stream** _ immer dann neu geladen wird, wenn ein Lesezeichen gesetzt oder entfernt wird. Daher funktionieren die Lesezeichen-Buttons im Post-Menü und im topic-footer-button synchron.

> <https://github.com/discourse/discourse/blob/57f17854fb93e2d88c7b4eddc040338530c98239/app/assets/javascripts/discourse/app/controllers/topic.js#L755>

Wie kann ich nun mein Widget „topic-timeline-bookmark" immer dann neu laden, wenn ein Lesezeichen gesetzt oder entfernt wird oder wenn das Widget _ **post-stream** _ neu geladen wird? Hier ist mein Code:

```plaintext
<script type="text/discourse-plugin" version="0.8">
  const { h } = require('virtual-dom');
  const { getOwner } = require("discourse-common/lib/get-owner");
  const topicController = getOwner(this).lookup("controller:topic");

  api.createWidget("topic-timeline-bookmark", {  
      tagName: 'div.discourse-bookmark-button-wrapper',
      buildKey: () => `topic-timeline-bookmark`,
      toggleBookmark() {
        topicController.send('toggleBookmark');
      },
      html(attrs, state) { 
        let contents = [];
        const user = api.getCurrentUser();
        if (user) {
            let tooltip = 'bookmarked.help.bookmark';
            let label = 'bookmarked.title';
            let buttonClass = 'btn btn-default bookmark';
            let icon = "bookmark";  
            let bookmarkedPosts = topicController.model.bookmarked_posts;
            let bookmarkCount = 0;

            if(bookmarkedPosts && bookmarkedPosts.length > 0){
              bookmarkCount = bookmarkedPosts.length;
              
              //Icon
              if (bookmarkedPosts.some((bookmark) => bookmark.reminder_at))
                icon = "discourse-bookmark-clock";
              else
                icon = "bookmark";

              //Label
              if (bookmarkCount === 0)               
                  label = "bookmarked.title";          
              else if (bookmarkCount === 1)
                  label = "bookmarked.edit_bookmark"; 
              else 
                  label = "bookmarked.clear_bookmarks";

              //Tooltip
              if (bookmarkedPosts.length === 1)
                  tooltip = 'bookmarked.help.edit_bookmark';
              else if (bookmarkedPosts.find((x) => x.reminder_at))
                  tooltip = 'bookmarked.help.unbookmark_with_reminder';
              
              //Append CSS class if bookmark is set
              if (bookmarkCount > 0) { buttonClass += ' bookmarked' }
            }
    
            contents.push(
            this.attach('button', {
              action: 'toggleBookmark',
              title: tooltip,
              label: label,
              icon: icon,
              className: buttonClass
            })
          );
        }
        return contents;
      }, 
    });
 
  api.decorateWidget('topic-timeline:after', function(helper) {
    return helper.attach('topic-timeline-bookmark');
  });
</script>

```

---

_[View the full topic](https://meta.discourse.org/t/reload-refresh-a-widget-on-refresh-of-another-widget/204356)._
