From 14c5e1e159ef45db2c51fc3529f0fa7beff00a60 Mon Sep 17 00:00:00 2001 From: mithandir Date: Thu, 30 Nov 2023 12:25:39 +0100 Subject: [PATCH] Fix page update after new posts --- .../ch/climbd/newsfeed/views/LatestView.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/climbd/newsfeed/views/LatestView.java b/src/main/java/ch/climbd/newsfeed/views/LatestView.java index e201436..42c1967 100644 --- a/src/main/java/ch/climbd/newsfeed/views/LatestView.java +++ b/src/main/java/ch/climbd/newsfeed/views/LatestView.java @@ -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") @@ -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")); @@ -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 + } + }); })); }