Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/ui/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ public void loadPage(Page page) throws IOException {

mainPane.setCenter(root);
navbarController.setActivePage(page);
navbarController.updateAuthButton();
}
}
21 changes: 20 additions & 1 deletion src/main/java/ui/controller/MyProfileController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package ui.controller;

public class MyProfileController {
import javafx.fxml.FXML;
import ui.Page;
import util.SessionManager;

import java.util.function.Consumer;

public class MyProfileController implements NavigationAware {

private Consumer<Page> onNavigate;

public void setOnNavigate(Consumer<Page> onNavigate) {
this.onNavigate = onNavigate;
}


@FXML
private void handleSignOut() {
SessionManager.signOut();
onNavigate.accept(Page.HOME);
}
}
17 changes: 15 additions & 2 deletions src/main/java/ui/controller/NavbarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import ui.Page;
import util.SessionManager;

public class NavbarController {

Expand All @@ -28,7 +29,7 @@ public void setActivePage(Page page) {
Button buttonForPage = switch (page) {
case HOME -> homeBtn;
case ORGANIZATIONS -> orgBtn;
case SIGNIN -> signInBtn;
case SIGNIN, PROFILE -> signInBtn;
default -> null;
};

Expand All @@ -42,7 +43,11 @@ public void goHome() {
}

public void goToSignIn() {
onNavigate.accept(Page.SIGNIN);
if (SessionManager.isSignedIn()) {
onNavigate.accept(Page.PROFILE);
} else {
onNavigate.accept(Page.SIGNIN);
}
}

public void goToOrganizations() {
Expand All @@ -52,4 +57,12 @@ public void goToOrganizations() {
public void goToMyProfile() {
onNavigate.accept(Page.PROFILE);
}

public void updateAuthButton() {
if (SessionManager.isSignedIn()) {
signInBtn.setText("My Profile");
} else {
signInBtn.setText("Sign In");
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/util/SessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void signIn(User user) {
currentUser = user;
}

public static void logout() {
public static void signOut() {
SignedIn = false;
currentUser = null;
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/resources/view/MyProfile.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="692.0" prefWidth="620.0" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ui.controller.MyProfileController">
<top>
<fx:include source="Navbar.fxml" />
</top>
<BorderPane xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ui.controller.MyProfileController">
<center>
<ScrollPane fitToWidth="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" BorderPane.alignment="CENTER">
<ScrollPane fitToWidth="true" hbarPolicy="NEVER" BorderPane.alignment="CENTER">
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="25.0">
<VBox prefHeight="800.0" spacing="25.0">
<children>
<VBox prefHeight="200.0" prefWidth="100.0" spacing="10.0">
<children>
Expand Down Expand Up @@ -85,14 +82,14 @@
<FlowPane fx:id="savedOrgsPane" prefHeight="200.0" prefWidth="200.0" />
</children>
</VBox>
<Button mnemonicParsing="false" styleClass="page-button" text="Log out">
<Button mnemonicParsing="false" onAction="#handleSignOut" styleClass="page-button" text="Log out">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
</Button>
</children>
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" />
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
</VBox>
</content>
Expand Down