Instead of a click button, the lists for genders and country searches

are hovering now
This commit is contained in:
Torsten Schulz
2024-02-23 15:46:05 +01:00
parent 94d2985334
commit 359f379b18
3 changed files with 55 additions and 36 deletions

View File

@@ -185,3 +185,23 @@ main {
background-color: lightgray; background-color: lightgray;
margin: 0.1em 0.2em; margin: 0.1em 0.2em;
} }
.selectBoxes-drop-down-trigger {
cursor: pointer;
}
.selectBoxes-drop-down-trigger > .selectBoxes-dropdown {
display: none;
position: absolute;
top: 1.2em;
overflow: auto;
background: RGBA(248, 248, 248, 0.8);
max-height: 10em;
z-index: 1;
border: 1px solid #666;
box-shadow: 2px 2px 4px #666;
padding: 2px;
left: 9em;
}
.selectBoxes-drop-down-trigger:hover > .selectBoxes-dropdown {
display: inline-block;
}

View File

@@ -539,7 +539,6 @@ Wt::WContainerWidget* App::createSmileyBar(Wt::WContainerWidget* parent, Wt::WLi
} }
Wt::WPushButton* App::createSendButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEdit* inputLine) { Wt::WPushButton* App::createSendButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEdit* inputLine) {
setActivity();
auto sendButton = inputLayout->addNew<Wt::WPushButton>("Send"); auto sendButton = inputLayout->addNew<Wt::WPushButton>("Send");
auto sendMessageFunction = [=, this]() { auto sendMessageFunction = [=, this]() {
sendMessage(inputLine); sendMessage(inputLine);
@@ -551,6 +550,7 @@ Wt::WPushButton* App::createSendButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEd
} }
void App::sendMessage(Wt::WLineEdit *inputLine) { void App::sendMessage(Wt::WLineEdit *inputLine) {
setActivity();
auto utf8String = inputLine->valueText().trim().toUTF8(); auto utf8String = inputLine->valueText().trim().toUTF8();
if (utf8String == "") { if (utf8String == "") {
return; return;
@@ -939,49 +939,46 @@ std::pair<Wt::WSpinBox*, Wt::WSpinBox*> App::setupSearchFields(Wt::WVBoxLayout *
return {minAgeEdit, maxAgeEdit}; return {minAgeEdit, maxAgeEdit};
} }
std::pair<Wt::WPushButton*, Wt::WContainerWidget*> App::setupCountryDropDown(Wt::WVBoxLayout *contentLayout) { std::pair<Wt::WContainerWidget*, Wt::WContainerWidget*> App::setupCountryDropDown(Wt::WVBoxLayout *contentLayout) {
auto countryDropDown = std::make_unique<Wt::WContainerWidget>(); auto countryOpenList = addSearchItemLine<Wt::WContainerWidget>(contentLayout, "Country");
countryDropDown->setInline(true); countryOpenList->addNew<Wt::WText>("All");
countryDropDown->setStyleClass("countries-drop-down"); countryOpenList->setStyleClass("selectBoxes-drop-down-trigger");
auto countryDropDownContainer = countryDropDown.get(); auto countryDropDown = countryOpenList->addNew<Wt::WContainerWidget>();
auto countryOpenList = addSearchItemLine<Wt::WPushButton>(contentLayout, "Country", std::move(countryDropDown)); countryDropDown->setStyleClass("selectBoxes-dropdown");
countryDropDownContainer->hide(); countryOpenList->setToolTip("Select the countries you'll search for");
countryOpenList->clicked().connect([=]() { if (countryDropDownContainer->isHidden()) { countryDropDownContainer->show();} else { countryDropDownContainer->hide(); } });
countryOpenList->setText("All");
std::map<Wt::WString, Wt::WString> countries = server_.countries(); std::map<Wt::WString, Wt::WString> countries = server_.countries();
addItem("All", countryDropDownContainer, countryOpenList, &searchFields.countries, true); addItem("All", countryDropDown, countryOpenList, &searchFields.countries, true);
addItem(country, countryDropDownContainer, countryOpenList, &searchFields.countries); addItem(country, countryDropDown, countryOpenList, &searchFields.countries);
for (const auto &itemCountry: countries) { for (const auto &itemCountry: countries) {
if (itemCountry.first.toUTF8() != country) { if (itemCountry.first.toUTF8() != country) {
addItem(itemCountry.first.toUTF8(), countryDropDownContainer, countryOpenList, &searchFields.countries); addItem(itemCountry.first.toUTF8(), countryDropDown, countryOpenList, &searchFields.countries);
} }
} }
return {countryOpenList, countryDropDownContainer}; return {countryOpenList, countryDropDown};
} }
std::pair<Wt::WPushButton*, Wt::WContainerWidget*> App::setupGendersDropDown(Wt::WVBoxLayout *contentLayout) { std::pair<Wt::WContainerWidget*, Wt::WContainerWidget*> App::setupGendersDropDown(Wt::WVBoxLayout *contentLayout) {
auto gendersDropDown = std::make_unique<Wt::WContainerWidget>(); auto gendersOpenList = addSearchItemLine<Wt::WContainerWidget>(contentLayout, "Genders");
gendersDropDown->setInline(true); gendersOpenList->addNew<Wt::WText>("All");
gendersDropDown->setStyleClass("countries-drop-down"); gendersOpenList->setStyleClass("selectBoxes-drop-down-trigger");
auto gendersDropDownContainer = gendersDropDown.get(); auto gendersDropDown = gendersOpenList->addNew<Wt::WContainerWidget>();
auto gendersOpenList = addSearchItemLine<Wt::WPushButton>(contentLayout, "Genders", std::move(gendersDropDown)); gendersDropDown->setStyleClass("selectBoxes-dropdown");
gendersDropDownContainer->hide(); gendersOpenList->setToolTip("Select the genders you'll search for");
gendersOpenList->clicked().connect([=]() { if (gendersDropDownContainer->isHidden()) { gendersDropDownContainer->show();} else { gendersDropDownContainer->hide(); } }); addItem("All", gendersDropDown, gendersOpenList, &searchFields.gender, true);
gendersOpenList->setText("All");
addItem("All", gendersDropDownContainer, gendersOpenList, &searchFields.gender, true);
std::map<Wt::WString, Wt::WString> swappedGenders; std::map<Wt::WString, Wt::WString> swappedGenders;
for (const auto& pair : genders_) { for (const auto& pair : genders_) {
swappedGenders[pair.second] = pair.first; swappedGenders[pair.second] = pair.first;
} }
for (const auto &itemGender: swappedGenders) { for (const auto &itemGender: swappedGenders) {
addItem(itemGender.first.toUTF8(), gendersDropDownContainer, gendersOpenList, &searchFields.gender); addItem(itemGender.first.toUTF8(), gendersDropDown, gendersOpenList, &searchFields.gender);
} }
return {gendersOpenList, gendersDropDownContainer}; return {gendersOpenList, gendersDropDown};
} }
void App::addItem(const std::string& country, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openListButton, std::unordered_set<std::string> *saveItems, bool isSelected) {
void App::addItem(const std::string& country, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set<std::string> *saveItems, bool isSelected) {
auto menuItem = dropDownContainer->addNew<Wt::WCheckBox>(country); auto menuItem = dropDownContainer->addNew<Wt::WCheckBox>(country);
menuItem->changed().connect([=, this]() mutable { itemChanged(menuItem, dropDownContainer, openListButton, saveItems); }); menuItem->changed().connect([=, this]() mutable { itemChanged(menuItem, dropDownContainer, container, saveItems); });
menuItem->setInline(false); menuItem->setInline(false);
if (isSelected) { if (isSelected) {
menuItem->setChecked(); menuItem->setChecked();
@@ -1145,7 +1142,7 @@ void App::showPartnerSites() {
} }
} }
void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openButton, std::unordered_set<std::string> *saveItems) { void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set<std::string> *saveItems) {
saveItems->clear(); saveItems->clear();
bool unselect = (item->text() == "All" && item->isChecked()); bool unselect = (item->text() == "All" && item->isChecked());
for (auto &widgetItem: dropDownContainer->children()) { for (auto &widgetItem: dropDownContainer->children()) {
@@ -1168,12 +1165,13 @@ void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContain
for (const auto &selected: *saveItems) { for (const auto &selected: *saveItems) {
result += (result.empty() ? "" : ", ") + selected; result += (result.empty() ? "" : ", ") + selected;
} }
openButton->setText(result); auto outputWidget = (Wt::WText*)container->children().at(0);
outputWidget->setText(result);
} }
void App::restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit, void App::restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit,
Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer, Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer,
Wt::WPushButton *countryOpenList, Wt::WPushButton *gendersOpenList) { Wt::WContainerWidget *countryOpenList, Wt::WContainerWidget *gendersOpenList) {
if (!searchFields.set) { if (!searchFields.set) {
searchFields = Search(searchResultContainer); searchFields = Search(searchResultContainer);
} else { } else {

View File

@@ -129,6 +129,7 @@ private:
void startSearch(); void startSearch();
void showSearch(Wt::Json::Object broadcast); void showSearch(Wt::Json::Object broadcast);
template<class Class> Class *addSearchItemLine(Wt::WVBoxLayout *layout, std::string label, std::unique_ptr<Wt::WContainerWidget> additionalItem = nullptr); template<class Class> Class *addSearchItemLine(Wt::WVBoxLayout *layout, std::string label, std::unique_ptr<Wt::WContainerWidget> additionalItem = nullptr);
Wt::WContainerWidget *addSearchItemContainer(Wt::WVBoxLayout *layout, std::string label);
void openInbox(); void openInbox();
bool isNickAllowed(const std::string &nick); bool isNickAllowed(const std::string &nick);
bool compareJsonObjects(const Wt::Json::Object &obj1, const Wt::Json::Object &obj2); bool compareJsonObjects(const Wt::Json::Object &obj1, const Wt::Json::Object &obj2);
@@ -187,14 +188,14 @@ private:
Wt::WWebWidget *createTextElement(const std::string &writer, const std::string &text, Wt::WContainerWidget *outputContainer, std::string id); Wt::WWebWidget *createTextElement(const std::string &writer, const std::string &text, Wt::WContainerWidget *outputContainer, std::string id);
void createImprintContainer(Wt::WVBoxLayout *containerLayout); void createImprintContainer(Wt::WVBoxLayout *containerLayout);
Wt::WContainerWidget *setupSearchButton(Wt::WVBoxLayout *contentLayout); Wt::WContainerWidget *setupSearchButton(Wt::WVBoxLayout *contentLayout);
void restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit, Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer, Wt::WPushButton *countryOpenList, Wt::WPushButton *gendersOpenList); void restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit, Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer, Wt::WContainerWidget *countryOpenList, Wt::WContainerWidget *gendersOpenList);
Wt::WLineEdit *setupNameSearchField(Wt::WVBoxLayout *contentLayout); Wt::WLineEdit *setupNameSearchField(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WPushButton *, Wt::WContainerWidget *> setupGendersDropDown(Wt::WVBoxLayout *contentLayout); std::pair<Wt::WContainerWidget *, Wt::WContainerWidget *> setupGendersDropDown(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WPushButton *, Wt::WContainerWidget *> setupCountryDropDown(Wt::WVBoxLayout *contentLayout); std::pair<Wt::WContainerWidget *, Wt::WContainerWidget *> setupCountryDropDown(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WSpinBox*, Wt::WSpinBox*> setupSearchFields(Wt::WVBoxLayout *contentLayout); std::pair<Wt::WSpinBox*, Wt::WSpinBox*> setupSearchFields(Wt::WVBoxLayout *contentLayout);
Wt::WVBoxLayout *resetSearchFields(); Wt::WVBoxLayout *resetSearchFields();
void itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openButton, std::unordered_set<std::string> *saveItems); void itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *openButton, std::unordered_set<std::string> *saveItems);
void addItem(const std::string &country, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openListButton, std::unordered_set<std::string> *saveItems, bool isSelected = false); void addItem(const std::string &country, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set<std::string> *saveItems, bool isSelected = false);
void addUserItemToLayout(Wt::WVBoxLayout *layout, Wt::Json::Object userObject); void addUserItemToLayout(Wt::WVBoxLayout *layout, Wt::Json::Object userObject);
std::unordered_set<std::string> gendersListToShortGendersList(std::unordered_set<std::string> gendersList); std::unordered_set<std::string> gendersListToShortGendersList(std::unordered_set<std::string> gendersList);
std::string genderShortOfGender(const std::string incomingGender); std::string genderShortOfGender(const std::string incomingGender);