From 76f184f52d56f44a6388d8dce803dc0a49c5f8d6 Mon Sep 17 00:00:00 2001 From: mithandir Date: Tue, 12 Sep 2023 16:32:07 +0200 Subject: [PATCH] Improve notifications Now with link to the article --- .../ch/climbd/newsfeed/views/LatestView.java | 27 ++++++++++++++++--- src/main/resources/application.yaml | 2 -- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/climbd/newsfeed/views/LatestView.java b/src/main/java/ch/climbd/newsfeed/views/LatestView.java index ab846a2..e201436 100644 --- a/src/main/java/ch/climbd/newsfeed/views/LatestView.java +++ b/src/main/java/ch/climbd/newsfeed/views/LatestView.java @@ -5,10 +5,14 @@ import ch.climbd.newsfeed.views.components.*; import com.vaadin.flow.component.AttachEvent; import com.vaadin.flow.component.DetachEvent; +import com.vaadin.flow.component.Text; import com.vaadin.flow.component.UI; -import com.vaadin.flow.component.html.H1; -import com.vaadin.flow.component.html.Image; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.button.ButtonVariant; +import com.vaadin.flow.component.html.*; +import com.vaadin.flow.component.icon.Icon; import com.vaadin.flow.component.notification.Notification; +import com.vaadin.flow.component.notification.NotificationVariant; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.router.PageTitle; @@ -84,9 +88,24 @@ protected void onAttach(AttachEvent attachEvent) { for (int i = 0; i < 100; i++) { newsItems.add(newsItemComponent.buildNewsItem(i + 1, sourceData.get(i))); } - var notification = Notification.show(newsEntry.getTitle()); - notification.setDuration(15000); + + 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")); + closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); + closeButton.setAriaLabel("Close"); + closeButton.addClickListener(event -> notification.close()); + + HorizontalLayout layout = new HorizontalLayout(div, closeButton); + layout.setAlignItems(Alignment.CENTER); + + notification.add(layout); + notification.addThemeVariants(NotificationVariant.LUMO_PRIMARY); + notification.setDuration(30000); notification.setPosition(Notification.Position.TOP_END); + notification.open(); })); } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index d1ec3d2..0fbdc13 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -7,6 +7,4 @@ management: web.exposure.include: health spring: - main: - lazy-initialization: true jmx.enabled: false \ No newline at end of file