Skip to content

Commit

Permalink
Merge pull request #3039 from axpoems/add-goToOffer-button-in-userOffers
Browse files Browse the repository at this point in the history
Add go to offer functionality from profile card
  • Loading branch information
axpoems authored Dec 5, 2024
2 parents 05c64f9 + 61faf15 commit e7104e6
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ void processNavigationTarget(NavigationTarget navigationTarget, Optional<Object>
Optional<NavigationTarget> optionalCandidateTarget = Optional.of(navigationTarget);
while (optionalCandidateTarget.isPresent()) {
NavigationTarget candidateTarget = optionalCandidateTarget.get();
// Make sure to run InitData even if already in target location.
Optional<Controller> optionalChildController = findController(candidateTarget, data);
if (model.getResolvedTarget().isPresent() && model.getResolvedTarget().get() == candidateTarget) {
// We as host controller have already selected the child target in question.
// We exit the loop here.
break;
}
Optional<Controller> optionalChildController = findController(candidateTarget, data);
if (optionalChildController.isPresent()) {
// We as host have found the controller and handle that target.
Controller childController = optionalChildController.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.chat.ChatMessage;
import bisq.chat.bisqeasy.offerbook.BisqEasyOfferbookChannel;
import bisq.chat.bisqeasy.offerbook.BisqEasyOfferbookChannelService;
import bisq.chat.bisqeasy.offerbook.BisqEasyOfferbookMessage;
import bisq.chat.bisqeasy.open_trades.BisqEasyOpenTradeChannel;
import bisq.chat.notifications.ChatNotification;
import bisq.chat.notifications.ChatNotificationService;
Expand All @@ -35,7 +36,9 @@
import bisq.common.proto.ProtobufUtils;
import bisq.desktop.ServiceProvider;
import bisq.desktop.common.observable.FxBindings;
import bisq.desktop.common.threading.UIScheduler;
import bisq.desktop.common.threading.UIThread;
import bisq.desktop.common.view.InitWithDataController;
import bisq.desktop.common.view.Navigation;
import bisq.desktop.main.content.bisq_easy.offerbook.offerbook_list.OfferbookListController;
import bisq.desktop.main.content.bisq_easy.trade_wizard.TradeWizardController;
Expand All @@ -48,6 +51,9 @@
import bisq.settings.SettingsService;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;
Expand All @@ -62,7 +68,19 @@
import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
public final class BisqEasyOfferbookController extends ChatController<BisqEasyOfferbookView, BisqEasyOfferbookModel> {
public final class BisqEasyOfferbookController extends ChatController<BisqEasyOfferbookView, BisqEasyOfferbookModel>
implements InitWithDataController<BisqEasyOfferbookController.InitData> {
@Getter
@EqualsAndHashCode
@ToString
public static final class InitData {
private final BisqEasyOfferbookMessage chatMessage;

public InitData(BisqEasyOfferbookMessage chatMessage) {
this.chatMessage = chatMessage;
}
}

private final SettingsService settingsService;
private final MarketPriceService marketPriceService;
private final BisqEasyOfferbookChannelService bisqEasyOfferbookChannelService;
Expand Down Expand Up @@ -99,6 +117,15 @@ public BisqEasyOfferbookController(ServiceProvider serviceProvider) {
favouriteMarketChannelItemsPredicate = item -> item.getIsFavourite().get();
}

@Override
public void initWithData(InitData initData) {
BisqEasyOfferbookMessage chatMessage = initData.getChatMessage();
bisqEasyOfferbookChannelService.findChannel(chatMessage.getChannelId()).ifPresent(channel -> {
maybeUpdateSelectedChannel(channel);
UIScheduler.run(() -> chatMessageContainerController.highlightOfferChatMessage(initData.getChatMessage())).after(110);
});
}

@Override
public BisqEasyOfferbookModel createAndGetModel(ChatChannelDomain chatChannelDomain) {
BisqEasyOfferbookModel model = new BisqEasyOfferbookModel(chatChannelDomain);
Expand Down Expand Up @@ -304,9 +331,15 @@ void onSortMarkets(MarketSortType marketSortType) {
void onSelectMarketChannelItem(MarketChannelItem item) {
if (item == null) {
selectionService.selectChannel(null);
} else if (!item.getChannel().equals(selectionService.getSelectedChannel().get())) {
selectionService.selectChannel(item.getChannel());
chatNotificationService.consume(item.getChannel());
} else {
maybeUpdateSelectedChannel(item.getChannel());
}
}

private void maybeUpdateSelectedChannel(BisqEasyOfferbookChannel channel) {
if (!channel.equals(selectionService.getSelectedChannel().get())) {
selectionService.selectChannel(channel);
chatNotificationService.consume(channel);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@

package bisq.desktop.main.content.user.profile_card.offers;

import bisq.bisq_easy.NavigationTarget;
import bisq.desktop.common.view.Navigation;
import bisq.desktop.common.view.View;
import bisq.desktop.components.controls.BisqMenuItem;
import bisq.desktop.components.controls.BisqTooltip;
import bisq.desktop.components.table.BisqTableColumn;
import bisq.desktop.components.table.BisqTableView;
import bisq.desktop.main.content.bisq_easy.BisqEasyViewUtils;
import bisq.desktop.main.content.bisq_easy.offerbook.BisqEasyOfferbookController;
import bisq.desktop.main.content.bisq_easy.offerbook.offerbook_list.OfferbookListItem;
import bisq.desktop.main.content.components.MarketImageComposition;
import bisq.desktop.overlay.OverlayController;
import bisq.i18n.Res;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand All @@ -49,14 +54,13 @@ public ProfileCardOffersView(ProfileCardOffersModel model,

VBox vBox = new VBox();
vBox.setFillWidth(true);
vBox.getStyleClass().add("header");
vBox.getStyleClass().add("profile-card-table-header");
tableView = new BisqTableView<>(model.getListItems());
tableView.getStyleClass().addAll("reputation-table", "rich-table-view");
tableView.getStyleClass().addAll("profile-card-table", "rich-table-view");
tableView.allowVerticalScrollbar();
configTableView();
root.getChildren().addAll(vBox, tableView);
root.setPadding(new Insets(20, 0, 0, 0));
root.getStyleClass().add("reputation");
}

@Override
Expand Down Expand Up @@ -114,6 +118,12 @@ private void configTableView() {
.isSortable(false)
.setCellFactory(getPaymentMethodsCellFactory())
.build());

tableView.getColumns().add(new BisqTableColumn.Builder<OfferbookListItem>()
.left()
.isSortable(false)
.setCellFactory(getGotToOfferCellFactory())
.build());
}

private Callback<TableColumn<OfferbookListItem, OfferbookListItem>,
Expand Down Expand Up @@ -213,4 +223,39 @@ protected void updateItem(OfferbookListItem item, boolean empty) {
}
};
}

private Callback<TableColumn<OfferbookListItem, OfferbookListItem>,
TableCell<OfferbookListItem, OfferbookListItem>> getGotToOfferCellFactory() {
return column -> new TableCell<>() {
private final BisqMenuItem goToOfferButton = new BisqMenuItem(
Res.get("user.profileCard.offers.table.columns.goToOffer.button"));

{
goToOfferButton.setStyle("-fx-text-fill: -fx-mid-text-color;");
goToOfferButton.getStyleClass().add("go-to-offer-button");
}

@Override
protected void updateItem(OfferbookListItem item, boolean empty) {
super.updateItem(item, empty);

if (item != null && !empty) {
goToOfferButton.setOnAction(e ->
OverlayController.hide(() ->
Navigation.navigateTo(NavigationTarget.BISQ_EASY_OFFERBOOK,
new BisqEasyOfferbookController.InitData(item.getBisqEasyOfferbookMessage()))));
goToOfferButton.setOnMouseEntered(e -> goToOfferButton.setStyle("-fx-text-fill: -fx-light-text-color;"));
goToOfferButton.setOnMouseClicked(e -> goToOfferButton.setStyle("-fx-text-fill: -fx-light-text-color;"));
goToOfferButton.setOnMouseExited(e -> goToOfferButton.setStyle("-fx-text-fill: -fx-mid-text-color;"));
setGraphic(goToOfferButton);
} else {
goToOfferButton.setOnAction(null);
goToOfferButton.setOnMouseEntered(null);
goToOfferButton.setOnMouseClicked(null);
goToOfferButton.setOnMouseExited(null);
setGraphic(null);
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ public ProfileCardReputationView(ProfileCardReputationModel model,

VBox vBox = new VBox();
vBox.setFillWidth(true);
vBox.getStyleClass().add("header");
vBox.getStyleClass().add("profile-card-table-header");
tableView = new BisqTableView<>(model.getListItems());
tableView.getStyleClass().addAll("reputation-table", "rich-table-view");
tableView.getStyleClass().addAll("profile-card-table", "rich-table-view");
tableView.allowVerticalScrollbar();
configTableView();
root.getChildren().addAll(vBox, tableView);
root.setPadding(new Insets(20, 0, 0, 0));
root.getStyleClass().add("reputation");
}

@Override
Expand Down
16 changes: 10 additions & 6 deletions apps/desktop/desktop/src/main/resources/css/user.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,38 @@
-fx-padding: 35 !important;
}

.profile-card .reputation .header {
.profile-card .profile-card-table-header {
-fx-pref-height: 8;
-fx-background-color: -bisq-dark-grey-30;
-fx-background-radius: 8 8 0 0;
}

.profile-card .reputation .reputation-table.table-view {
.profile-card .profile-card-table.table-view {
-fx-pref-height: 300;
-fx-background-radius: 0 0 8 8;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-border-width: 0;
}

.profile-card .reputation .reputation-table.table-view .table-cell .text {
.profile-card .profile-card-table.table-view .table-cell .text {
-fx-font-size: 0.9em;
-fx-padding: 0;
}

.profile-card .reputation .reputation-table.table-view .column-header {
.profile-card .profile-card-table.table-view .column-header {
-fx-pref-height: 25;
}

.profile-card .reputation .reputation-table.table-view .column-header-background {
.profile-card .profile-card-table.table-view .column-header-background {
-fx-background-color: -bisq-dark-grey-30;
-fx-padding: 0 0 3 0;
}

.profile-card .reputation .reputation-table.table-view .table-row-cell {
.profile-card .profile-card-table.table-view .table-row-cell {
-fx-border-width: 0;
}

.profile-card .profile-card-table.table-view .table-row-cell .go-to-offer-button {
-fx-underline: true;
}
1 change: 1 addition & 0 deletions i18n/src/main/resources/user.properties
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ user.profileCard.offers.table.columns.price=Price
user.profileCard.offers.table.columns.paymentMethods=Payment methods
user.profileCard.offers.table.columns.offerAge=Offer age
user.profileCard.offers.table.columns.offerAge.tooltip=Creation date:\n{0}
user.profileCard.offers.table.columns.goToOffer.button=Go to offer

0 comments on commit e7104e6

Please sign in to comment.