Skip to content

Commit

Permalink
Updating DAO->Governance menu to indicate vote possible
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzmaker123 committed Aug 15, 2022
1 parent 423d57a commit e3ccb3c
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;

import javafx.beans.value.ChangeListener;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

import java.util.Arrays;
import java.util.List;
Expand All @@ -67,7 +68,7 @@ public class GovernanceView extends ActivatableView<AnchorPane, Void> implements
private AnchorPane content;

private Class<? extends View> selectedViewClass;
private ChangeListener<DaoPhase.Phase> phaseChangeListener;
private Subscription phaseChangeSubscription;
private ToggleGroup toggleGroup;

@Inject
Expand All @@ -89,13 +90,6 @@ public void initialize() {
loadView(selectedViewClass);
};

phaseChangeListener = (observable, oldValue, newValue) -> {
if (newValue == DaoPhase.Phase.BLIND_VOTE)
open.setLabelText(Res.get("dao.proposal.menuItem.vote"));
else
open.setLabelText(Res.get("dao.proposal.menuItem.browse"));
};

toggleGroup = new ToggleGroup();
List<Class<? extends View>> baseNavPath = Arrays.asList(MainView.class, DaoView.class, GovernanceView.class);
dashboard = new MenuItem(navigation, toggleGroup, Res.get("shared.dashboard"),
Expand All @@ -113,7 +107,7 @@ public void initialize() {
@Override
protected void activate() {
if (daoStateService.isParseBlockChainComplete()) {
daoFacade.phaseProperty().addListener(phaseChangeListener);
phaseChangeSubscription = EasyBind.subscribe(daoFacade.phaseProperty(), this::setupOpenMenuButtonText);
} else {
daoStateService.addDaoStateListener(this);
}
Expand Down Expand Up @@ -142,7 +136,10 @@ protected void activate() {
@SuppressWarnings("Duplicates")
@Override
protected void deactivate() {
daoFacade.phaseProperty().removeListener(phaseChangeListener);
if (phaseChangeSubscription != null) {
phaseChangeSubscription.unsubscribe();
}

daoStateService.removeDaoStateListener(this);

navigation.removeListener(navigationListener);
Expand All @@ -160,7 +157,7 @@ protected void deactivate() {

@Override
public void onParseBlockChainComplete() {
daoFacade.phaseProperty().addListener(phaseChangeListener);
phaseChangeSubscription = EasyBind.subscribe(daoFacade.phaseProperty(), this::setupOpenMenuButtonText);
}


Expand All @@ -177,6 +174,14 @@ private void loadView(Class<? extends View> viewClass) {
else if (view instanceof ProposalsView) toggleGroup.selectToggle(open);
else if (view instanceof VoteResultView) toggleGroup.selectToggle(result);
}

private void setupOpenMenuButtonText(DaoPhase.Phase phase) {
if (phase == DaoPhase.Phase.BLIND_VOTE) {
open.setLabelText(Res.get("dao.proposal.menuItem.vote"));
} else {
open.setLabelText(Res.get("dao.proposal.menuItem.browse"));
}
}
}


0 comments on commit e3ccb3c

Please sign in to comment.