Moved out creation of button for paging of stats lists to single place.

This commit is contained in:
23rd 2024-08-27 18:24:00 +03:00
parent c82b86cea3
commit 1840da1d68
2 changed files with 38 additions and 36 deletions

View file

@ -1141,13 +1141,9 @@ void AddMembersList(
object_ptr<PeerListContent>(container, &state->controller))); object_ptr<PeerListContent>(container, &state->controller)));
state->controller.setDelegate(&state->delegate); state->controller.setDelegate(&state->delegate);
const auto wrap = container->add( const auto wrap = AddShowMoreButton(
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>( container,
container, tr::lng_stories_show_more());
object_ptr<Ui::SettingsButton>(
container,
tr::lng_stories_show_more())),
{ 0, -st::settingsButton.padding.top(), 0, 0 });
const auto showMore = [=] { const auto showMore = [=] {
state->limit = std::min(int(max), state->limit + kPerPage); state->limit = std::min(int(max), state->limit + kPerPage);
@ -1181,23 +1177,14 @@ void AddBoostsList(
object_ptr<PeerListContent>(container, &state->controller))); object_ptr<PeerListContent>(container, &state->controller)));
state->controller.setDelegate(&state->delegate); state->controller.setDelegate(&state->delegate);
const auto wrap = container->add( const auto wrap = AddShowMoreButton(
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>( container,
container, (firstSlice.token.gifts
object_ptr<Ui::SettingsButton>( ? tr::lng_boosts_show_more_gifts
container, : tr::lng_boosts_show_more_boosts)(
(firstSlice.token.gifts lt_count,
? tr::lng_boosts_show_more_gifts state->controller.totalBoostsValue(
: tr::lng_boosts_show_more_boosts)( ) | rpl::map(max - rpl::mappers::_1) | tr::to_count()));
lt_count,
state->controller.totalBoostsValue(
) | rpl::map(
max - rpl::mappers::_1
) | tr::to_count()),
st::statisticsShowMoreButton)),
{ 0, -st::settingsButton.padding.top(), 0, 0 });
const auto button = wrap->entity();
AddArrow(button);
const auto showMore = [=] { const auto showMore = [=] {
if (!state->controller.skipRequest()) { if (!state->controller.skipRequest()) {
@ -1209,7 +1196,7 @@ void AddBoostsList(
state->controller.totalBoostsValue( state->controller.totalBoostsValue(
) | rpl::map(rpl::mappers::_1 > 0 && rpl::mappers::_1 < max), ) | rpl::map(rpl::mappers::_1 > 0 && rpl::mappers::_1 < max),
anim::type::instant); anim::type::instant);
button->setClickedCallback(showMore); wrap->entity()->setClickedCallback(showMore);
} }
void AddCreditsHistoryList( void AddCreditsHistoryList(
@ -1239,16 +1226,9 @@ void AddCreditsHistoryList(
object_ptr<PeerListContent>(container, &state->controller))); object_ptr<PeerListContent>(container, &state->controller)));
state->controller.setDelegate(&state->delegate); state->controller.setDelegate(&state->delegate);
const auto wrap = container->add( const auto wrap = AddShowMoreButton(
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>( container,
container, tr::lng_stories_show_more());
object_ptr<Ui::SettingsButton>(
container,
tr::lng_stories_show_more(),
st::statisticsShowMoreButton)),
{ 0, -st::settingsButton.padding.top(), 0, 0 });
const auto button = wrap->entity();
AddArrow(button);
const auto showMore = [=] { const auto showMore = [=] {
if (!state->controller.skipRequest()) { if (!state->controller.skipRequest()) {
@ -1259,7 +1239,22 @@ void AddCreditsHistoryList(
wrap->toggleOn( wrap->toggleOn(
state->controller.allLoadedValue() | rpl::map(!rpl::mappers::_1), state->controller.allLoadedValue() | rpl::map(!rpl::mappers::_1),
anim::type::instant); anim::type::instant);
button->setClickedCallback(showMore); wrap->entity()->setClickedCallback(showMore);
}
not_null<Ui::SlideWrap<Ui::SettingsButton>*> AddShowMoreButton(
not_null<Ui::VerticalLayout*> container,
rpl::producer<QString> title) {
const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
container,
object_ptr<Ui::SettingsButton>(
container,
std::move(title),
st::statisticsShowMoreButton)),
{ 0, -st::settingsButton.padding.top(), 0, 0 });
AddArrow(wrap->entity());
return wrap;
} }
} // namespace Info::Statistics } // namespace Info::Statistics

View file

@ -10,6 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class PeerData; class PeerData;
namespace Ui { namespace Ui {
class SettingsButton;
template <typename Widget>
class SlideWrap;
class VerticalLayout; class VerticalLayout;
} // namespace Ui } // namespace Ui
@ -64,4 +67,8 @@ void AddCreditsHistoryList(
bool out, bool out,
bool subscription = false); bool subscription = false);
[[nodiscard]] not_null<Ui::SlideWrap<Ui::SettingsButton>*> AddShowMoreButton(
not_null<Ui::VerticalLayout*> container,
rpl::producer<QString> title);
} // namespace Info::Statistics } // namespace Info::Statistics