Skip to content

Commit

Permalink
feat(search page): load more pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mairon1206 committed Oct 29, 2024
1 parent 9af6a0f commit 7e1fdde
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
43 changes: 27 additions & 16 deletions src/Controller/View/SearchPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Infrastructure/Network/NetworkClient.h>
#include <Infrastructure/Network/ResponseStruct.h>
#include <boost/algorithm/string.hpp>
#include <iterator>
#include <ranges>

EVENTO_UI_START
Expand Down Expand Up @@ -90,26 +91,36 @@ void SearchPage::loadDepartmentEvents(int page, int departmentIdx) {

self->set_events_state(PageState::Loading);

executor()->asyncExecute(networkClient()->getDepartmentEventList(
std::string(self->get_department()->row_data(departmentIdx)->text),
page + 1,
self->get_page_size()),
[&self = *this](Result<EventQueryRes> result) {
if (result.isErr()) {
self->set_events_state(PageState::Error);
self.bridge.getMessageManager()
.showMessage(result.unwrapErr().what(), MessageType::Error);
return;
}
executor()->asyncExecute(
networkClient()
->getDepartmentEventList(std::string(
self->get_department()->row_data(departmentIdx)->text),
page + 1,
self->get_page_size()),
[&self = *this, page](Result<EventQueryRes> result) {
if (result.isErr()) {
self->set_events_state(PageState::Error);
self.bridge.getMessageManager().showMessage(result.unwrapErr().what(),
MessageType::Error);
return;
}

auto res = result.unwrap();

auto res = result.unwrap();
if (page == 0) {
self.cntDepartmentEvents = std::move(res.elements);
} else {
self.cntDepartmentEvents.insert(self.cntDepartmentEvents.end(),
std::make_move_iterator(res.elements.begin()),
std::make_move_iterator(res.elements.end()));
}

self->set_total(res.total);
self->set_total(res.total);

self->set_event_model(convert::from(res.elements));
self->set_event_model(convert::from(self.cntDepartmentEvents));

self->set_events_state(PageState::Normal);
});
self->set_events_state(PageState::Normal);
});
}

EVENTO_UI_END
4 changes: 4 additions & 0 deletions src/Controller/View/SearchPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <Controller/Core/BasicView.h>
#include <Controller/Core/GlobalAgent.hh>
#include <Infrastructure/Network/ResponseStruct.h>
#include <vector>

EVENTO_UI_START

Expand All @@ -21,6 +23,8 @@ class SearchPage : public BasicView, private GlobalAgent<SearchPageBridge> {
void search(std::string const& keyword);

std::vector<slint::SharedString> departments;

std::vector<EventEntity> cntDepartmentEvents;
};

EVENTO_UI_END
26 changes: 15 additions & 11 deletions ui/views/page/search.slint
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Token } from "../../global.slint";
import { Page, EventCardGroup, EventStruct, StateLayer, PageState, LoadingAnimation } from "../../components/index.slint";
import { Button, LineEdit, ScrollView, ListView, StandardListView } from "std-widgets.slint";
import { Button } from "../../components/index.slint";
import { LineEdit, ScrollView, ListView, StandardListView } from "std-widgets.slint";

export global SearchPageBridge {
in property <[StandardListViewItem]> department: [];
Expand All @@ -18,7 +19,9 @@ export global SearchPageBridge {
export component SearchPage inherits Page {
property <int> current-page-index: 0;
property <int> current-department-index: -1;
property <int> event-count-per-page: 12;
changed current-department-index => {
current-page-index = 0;
SearchPageBridge.load-department-events(current-page-index, current-department-index);
}
TouchArea {
Expand Down Expand Up @@ -64,7 +67,7 @@ export component SearchPage inherits Page {
}
if SearchPageBridge.list-state == PageState.error: Rectangle {
Button {
text: @tr("重新加载");
content: @tr("重新加载");
clicked => {
SearchPageBridge.load-department-list();
}
Expand Down Expand Up @@ -116,20 +119,21 @@ export component SearchPage inherits Page {
}
if SearchPageBridge.events-state == PageState.error: Rectangle {
Button {
text: @tr("重新加载");
content: @tr("重新加载");
clicked => {
SearchPageBridge.load-department-events(current-page-index, root.current-department-index);
}
}
}
// if SearchPageBridge.list-state != PageState.normal || root.current-department-index == -1: Rectangle {
// Text {
// text: @tr("什么都没有呢");
// font-size: Token.font.body.large.size;
// font-weight: Token.font.body.large.weight;
// color: Token.color.outline;
// }
// }
}

if SearchPageBridge.list-state == PageState.normal && SearchPageBridge.events-state == PageState.normal && SearchPageBridge.event-model.length != 0 && (current-page-index + 1) * root.event-count-per-page < SearchPageBridge.total:
Button {
content: @tr("加载更多");
clicked => {
SearchPageBridge.load-department-events(current-page-index + 1, root.current-department-index);
current-page-index = current-page-index + 1;
}
}
}
}
Expand Down

0 comments on commit 7e1fdde

Please sign in to comment.