Skip to content

Commit

Permalink
Fix page update after new posts
Browse files Browse the repository at this point in the history
  • Loading branch information
mithandir committed Nov 30, 2023
1 parent 7aa6a4e commit 14c5e1e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/ch/climbd/newsfeed/views/LatestView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.beans.factory.annotation.Value;

import java.util.LinkedList;
import java.util.concurrent.Executors;

@Route("latest")
@PageTitle("Climbd Cycling News - Latest News")
Expand Down Expand Up @@ -82,15 +83,7 @@ public void init() {
protected void onAttach(AttachEvent attachEvent) {
UI ui = attachEvent.getUI();
broadcasterRegistration = Broadcaster.register(newsEntry -> ui.access(() -> {
sourceData.add(0, newsEntry);
newsItems.removeAll();

for (int i = 0; i < 100; i++) {
newsItems.add(newsItemComponent.buildNewsItem(i + 1, sourceData.get(i)));
}

var notification = new Notification();

var div = new Div(new Text("New story: "), new Anchor(newsEntry.getLink(), newsEntry.getTitle(), AnchorTarget.BLANK));

Button closeButton = new Button(new Icon("lumo", "cross"));
Expand All @@ -106,6 +99,15 @@ protected void onAttach(AttachEvent attachEvent) {
notification.setDuration(30000);
notification.setPosition(Notification.Position.TOP_END);
notification.open();

Executors.newVirtualThreadPerTaskExecutor().execute(() -> {
try {
Thread.sleep(10000);
ui.getPage().reload();
} catch (Exception e) {
// DO NOTHING
}
});
}));
}

Expand Down

0 comments on commit 14c5e1e

Please sign in to comment.