feat: added user greeting
This commit is contained in:
parent
cd3827e47f
commit
f7dac7c3d9
1 changed files with 12 additions and 6 deletions
|
@ -44,20 +44,27 @@ public class MainLayout extends AppLayout {
|
||||||
viewTitle = new H1();
|
viewTitle = new H1();
|
||||||
viewTitle.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.Margin.NONE);
|
viewTitle.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.Margin.NONE);
|
||||||
|
|
||||||
|
// Retrieve the authenticated user's name
|
||||||
|
String username = authContext.getPrincipalName().orElse("Guest");
|
||||||
|
|
||||||
|
// Create a Span to display "Hi, username"
|
||||||
|
Span greeting = new Span("Hi, " + username);
|
||||||
|
greeting.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.FontWeight.BOLD);
|
||||||
|
greeting.getStyle().set("margin-right", "20px");
|
||||||
|
|
||||||
// Creating the logout button
|
// Creating the logout button
|
||||||
Button logout = new Button("Logout", click -> this.authContext.logout());
|
Button logout = new Button("Logout", click -> this.authContext.logout());
|
||||||
|
|
||||||
// Adding some padding to the logout button
|
// Adding some padding to the logout button
|
||||||
logout.getStyle().set("padding", "10px");
|
logout.getStyle().set("padding", "10px");
|
||||||
|
|
||||||
// Creating the header and adding the logout button to the far left
|
// Creating the header and adding the greeting and logout button
|
||||||
HorizontalLayout header = new HorizontalLayout(logout);
|
HorizontalLayout header = new HorizontalLayout(greeting, logout);
|
||||||
header.setWidthFull(); // Make the header take the full width
|
header.setWidthFull(); // Make the header take the full width
|
||||||
header.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.CENTER);
|
header.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.CENTER);
|
||||||
header.setJustifyContentMode(FlexComponent.JustifyContentMode.END); // Align items to the start (left)
|
header.setJustifyContentMode(FlexComponent.JustifyContentMode.END); // Align items to the end (right)
|
||||||
header.getStyle().set("padding", "0 10px"); // Add padding around the header if needed
|
header.getStyle().set("padding", "0 10px"); // Add padding around the header if needed
|
||||||
|
|
||||||
|
|
||||||
addToNavbar(true, toggle, viewTitle);
|
addToNavbar(true, toggle, viewTitle);
|
||||||
addToNavbar(header);
|
addToNavbar(header);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +92,6 @@ public class MainLayout extends AppLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Footer createFooter() {
|
private Footer createFooter() {
|
||||||
|
|
||||||
return new Footer();
|
return new Footer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue