feat: added user icon

This commit is contained in:
effe 2024-09-07 00:31:27 -04:00
parent f7dac7c3d9
commit 1133dec3f6

View file

@ -22,6 +22,8 @@ import com.vaadin.flow.spring.security.AuthenticationContext;
import com.vaadin.flow.theme.lumo.LumoUtility; import com.vaadin.flow.theme.lumo.LumoUtility;
import org.vaadin.lineawesome.LineAwesomeIcon; import org.vaadin.lineawesome.LineAwesomeIcon;
import javax.swing.*;
/** /**
* The main view is a top-level placeholder for other views. * The main view is a top-level placeholder for other views.
*/ */
@ -47,23 +49,26 @@ public class MainLayout extends AppLayout {
// Retrieve the authenticated user's name // Retrieve the authenticated user's name
String username = authContext.getPrincipalName().orElse("Guest"); String username = authContext.getPrincipalName().orElse("Guest");
// Create the user icon
final var userIcon = LineAwesomeIcon.USER.create();
userIcon.addClassNames(LumoUtility.FontSize.LARGE);
// Create a Span to display "Hi, username" // Create a Span to display "Hi, username"
Span greeting = new Span("Hi, " + username); Span greeting = new Span("Hi, " + username);
greeting.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.FontWeight.BOLD); greeting.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.FontWeight.BOLD);
greeting.getStyle().set("margin-right", "20px");
// Creating the logout button // Combine the user icon and greeting in a horizontal layout
HorizontalLayout userInfoLayout = new HorizontalLayout(userIcon, greeting);
userInfoLayout.setAlignItems(FlexComponent.Alignment.CENTER); // Center vertically
// Create 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
logout.getStyle().set("padding", "10px");
// Creating the header and adding the greeting and logout button // Creating the header and adding the greeting and logout button
HorizontalLayout header = new HorizontalLayout(greeting, logout); HorizontalLayout header = new HorizontalLayout(userInfoLayout, 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 end (right) header.setJustifyContentMode(FlexComponent.JustifyContentMode.END); // Align items to the right
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);