Added simple label for loading state to giveaway box.

This commit is contained in:
23rd 2023-11-01 02:32:35 +03:00 committed by John Preston
parent d2d69a7a36
commit d8e38b43d9
2 changed files with 103 additions and 76 deletions

View file

@ -56,15 +56,18 @@ void CreateGiveawayBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Info::Controller*> controller, not_null<Info::Controller*> controller,
not_null<PeerData*> peer) { not_null<PeerData*> peer) {
box->setWidth(st::boxWideWidth);
const auto bar = box->verticalLayout()->add(
object_ptr<Ui::Premium::TopBar>(
box,
st::giveawayGiftCodeCover,
nullptr,
tr::lng_giveaway_new_title(),
tr::lng_giveaway_new_about(Ui::Text::RichLangValue),
true));
{ {
const auto bar = box->verticalLayout()->add( bar->setPaused(true);
object_ptr<Ui::Premium::TopBar>(
box,
st::giveawayGiftCodeCover,
nullptr,
tr::lng_giveaway_new_title(),
tr::lng_giveaway_new_about(Ui::Text::RichLangValue),
true));
bar->setMaximumHeight(st::giveawayGiftCodeTopHeight); bar->setMaximumHeight(st::giveawayGiftCodeTopHeight);
bar->setMinimumHeight(st::infoLayerTopBarHeight); bar->setMinimumHeight(st::infoLayerTopBarHeight);
bar->resize(bar->width(), bar->maximumHeight()); bar->resize(bar->width(), bar->maximumHeight());
@ -109,10 +112,33 @@ void CreateGiveawayBox(
const auto state = box->lifetime().make_state<State>(peer); const auto state = box->lifetime().make_state<State>(peer);
const auto typeGroup = std::make_shared<GiveawayGroup>(); const auto typeGroup = std::make_shared<GiveawayGroup>();
box->setWidth(st::boxWideWidth); const auto loading = box->addRow(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
box,
object_ptr<Ui::VerticalLayout>(box)));
{
loading->toggle(true, anim::type::instant);
const auto container = loading->entity();
Settings::AddSkip(container);
Settings::AddSkip(container);
container->add(
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
box,
object_ptr<Ui::FlatLabel>(
box,
tr::lng_contacts_loading(),
st::giveawayLoadingLabel)));
Settings::AddSkip(container);
Settings::AddSkip(container);
}
const auto contentWrap = box->verticalLayout()->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
box,
object_ptr<Ui::VerticalLayout>(box)));
contentWrap->toggle(false, anim::type::instant);
{ {
const auto row = box->verticalLayout()->add( const auto row = contentWrap->entity()->add(
object_ptr<Giveaway::GiveawayTypeRow>( object_ptr<Giveaway::GiveawayTypeRow>(
box, box,
GiveawayType::Random, GiveawayType::Random,
@ -123,7 +149,7 @@ void CreateGiveawayBox(
}); });
} }
{ {
const auto row = box->verticalLayout()->add( const auto row = contentWrap->entity()->add(
object_ptr<Giveaway::GiveawayTypeRow>( object_ptr<Giveaway::GiveawayTypeRow>(
box, box,
GiveawayType::SpecificUsers, GiveawayType::SpecificUsers,
@ -170,13 +196,13 @@ void CreateGiveawayBox(
}); });
} }
Settings::AddSkip(box->verticalLayout()); Settings::AddSkip(contentWrap->entity());
Settings::AddDivider(box->verticalLayout()); Settings::AddDivider(contentWrap->entity());
Settings::AddSkip(box->verticalLayout()); Settings::AddSkip(contentWrap->entity());
const auto randomWrap = box->verticalLayout()->add( const auto randomWrap = contentWrap->entity()->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>( object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
box, contentWrap,
object_ptr<Ui::VerticalLayout>(box))); object_ptr<Ui::VerticalLayout>(box)));
state->typeValue.value( state->typeValue.value(
) | rpl::start_with_next([=](GiveawayType type) { ) | rpl::start_with_next([=](GiveawayType type) {
@ -186,9 +212,6 @@ void CreateGiveawayBox(
const auto sliderContainer = randomWrap->entity()->add( const auto sliderContainer = randomWrap->entity()->add(
object_ptr<Ui::VerticalLayout>(randomWrap)); object_ptr<Ui::VerticalLayout>(randomWrap));
const auto fillSliderContainer = [=] { const auto fillSliderContainer = [=] {
if (sliderContainer->count()) {
return;
}
const auto availablePresets = state->apiOptions.availablePresets(); const auto availablePresets = state->apiOptions.availablePresets();
if (availablePresets.empty()) { if (availablePresets.empty()) {
return; return;
@ -465,71 +488,56 @@ void CreateGiveawayBox(
} }
const auto durationGroup = std::make_shared<Ui::RadiobuttonGroup>(0); const auto durationGroup = std::make_shared<Ui::RadiobuttonGroup>(0);
const auto listOptions = contentWrap->entity()->add(
object_ptr<Ui::VerticalLayout>(box));
const auto rebuildListOptions = [=](int amountUsers) {
while (listOptions->count()) {
delete listOptions->widgetAt(0);
}
Settings::AddSubsectionTitle(
listOptions,
tr::lng_giveaway_duration_title(
lt_count,
rpl::single(amountUsers) | tr::to_count()));
Ui::Premium::AddGiftOptions(
listOptions,
durationGroup,
state->apiOptions.options(amountUsers),
st::giveawayGiftCodeGiftOption,
true);
auto terms = object_ptr<Ui::FlatLabel>(
listOptions,
tr::lng_premium_gift_terms(
lt_link,
tr::lng_premium_gift_terms_link(
) | rpl::map([](const QString &t) {
return Ui::Text::Link(t, 1);
}),
Ui::Text::WithEntities),
st::boxDividerLabel);
terms->setLink(1, std::make_shared<LambdaClickHandler>([=] {
box->closeBox();
Settings::ShowPremium(&peer->session(), QString());
}));
listOptions->add(object_ptr<Ui::DividerLabel>(
listOptions,
std::move(terms),
st::settingsDividerLabelPadding));
box->verticalLayout()->resizeToWidth(box->width());
};
{ {
const auto listOptions = box->verticalLayout()->add(
object_ptr<Ui::VerticalLayout>(box));
const auto rebuildListOptions = [=](int amountUsers) {
fillSliderContainer();
while (listOptions->count()) {
delete listOptions->widgetAt(0);
}
Settings::AddSubsectionTitle(
listOptions,
tr::lng_giveaway_duration_title(
lt_count,
rpl::single(amountUsers) | tr::to_count()));
Ui::Premium::AddGiftOptions(
listOptions,
durationGroup,
state->apiOptions.options(amountUsers),
st::giveawayGiftCodeGiftOption,
true);
auto terms = object_ptr<Ui::FlatLabel>(
listOptions,
tr::lng_premium_gift_terms(
lt_link,
tr::lng_premium_gift_terms_link(
) | rpl::map([](const QString &t) {
return Ui::Text::Link(t, 1);
}),
Ui::Text::WithEntities),
st::boxDividerLabel);
terms->setLink(1, std::make_shared<LambdaClickHandler>([=] {
box->closeBox();
Settings::ShowPremium(&peer->session(), QString());
}));
listOptions->add(object_ptr<Ui::DividerLabel>(
listOptions,
std::move(terms),
st::settingsDividerLabelPadding));
box->verticalLayout()->resizeToWidth(box->width());
};
rpl::combine( rpl::combine(
state->sliderValue.value(), state->sliderValue.value(),
state->typeValue.value() state->typeValue.value()
) | rpl::start_with_next([=](int users, GiveawayType type) { ) | rpl::start_with_next([=](int users, GiveawayType type) {
typeGroup->setValue(type); typeGroup->setValue(type);
const auto rebuild = [=] { rebuildListOptions((type == GiveawayType::SpecificUsers)
rebuildListOptions((type == GiveawayType::SpecificUsers) ? state->selectedToAward.size()
? state->selectedToAward.size() : users);
: users);
};
if (!listOptions->count()) {
state->lifetimeApi = state->apiOptions.request(
) | rpl::start_with_error_done([=](const QString &error) {
}, rebuild);
} else {
rebuild();
}
}, box->lifetime()); }, box->lifetime());
state->lifetimeApi = state->apiOptions.request(
) | rpl::start_with_error_done([=](const QString &error) {
}, [=] {
rebuildListOptions(1);
});
} }
{ {
// TODO mini-icon. // TODO mini-icon.
@ -603,4 +611,21 @@ void CreateGiveawayBox(
box->addButton(std::move(button)); box->addButton(std::move(button));
} }
state->typeValue.force_assign(GiveawayType::Random); state->typeValue.force_assign(GiveawayType::Random);
box->setShowFinishedCallback([=] {
if (!loading->toggled()) {
return;
}
bar->setPaused(false);
state->lifetimeApi = state->apiOptions.request(
) | rpl::start_with_error_done([=](const QString &error) {
}, [=] {
state->lifetimeApi.destroy();
loading->toggle(false, anim::type::instant);
fillSliderContainer();
rebuildListOptions(1);
contentWrap->toggle(true, anim::type::instant);
contentWrap->resizeToWidth(box->width());
});
});
} }

View file

@ -277,6 +277,8 @@ boostReplaceIconOutline: 2px;
boostReplaceIconAdd: point(4px, 2px); boostReplaceIconAdd: point(4px, 2px);
boostReplaceArrow: icon{{ "mediaview/next", windowSubTextFg }}; boostReplaceArrow: icon{{ "mediaview/next", windowSubTextFg }};
giveawayLoadingLabel: FlatLabel(membersAbout) {
}
giveawayGiftCodeTopHeight: 195px; giveawayGiftCodeTopHeight: 195px;
giveawayGiftCodeLink: FlatLabel(defaultFlatLabel) { giveawayGiftCodeLink: FlatLabel(defaultFlatLabel) {
margin: margins(10px, 12px, 10px, 8px); margin: margins(10px, 12px, 10px, 8px);