Skip to content

Commit

Permalink
Improve notifications
Browse files Browse the repository at this point in the history
Now with link to the article
  • Loading branch information
mithandir committed Sep 12, 2023
1 parent 3d6fe40 commit 76f184f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/main/java/ch/climbd/newsfeed/views/LatestView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}));
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ management:
web.exposure.include: health

spring:
main:
lazy-initialization: true
jmx.enabled: false

0 comments on commit 76f184f

Please sign in to comment.