Skip to content

Commit

Permalink
fix(ui): unexpected crash when click StandardListView on search page (
Browse files Browse the repository at this point in the history
close #69)
  • Loading branch information
Serein207 committed Sep 30, 2024
1 parent 2325031 commit b8872a9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 58 deletions.
44 changes: 21 additions & 23 deletions src/Controller/View/SearchPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ void SearchPage::onCreate() {
});

self->on_load_department_list([&self = *this] { self.loadDepartmentList(); });
self->on_load_department_events([&self = *this](int page) { self.loadDepartmentEvents(page); });
self->on_load_department_events([&self = *this](int page, int departmentIdx) {
self.loadDepartmentEvents(page, departmentIdx);
});
self->on_navigate_to_detail([this](EventStruct eventStruct) {
spdlog::debug("navigate to DetailPage, current event is {}", eventStruct.summary.data());
bridge.getViewManager().navigateTo(ViewName::DetailPage, eventStruct);
Expand Down Expand Up @@ -69,39 +71,35 @@ void SearchPage::loadDepartmentList() {
self->set_department(
std::make_shared<slint::VectorModel<slint::StandardListViewItem>>(model));

if (!model.empty()) {
self->set_current_department_index(0);
}

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

void SearchPage::loadDepartmentEvents(int page) {
void SearchPage::loadDepartmentEvents(int page, int departmentIdx) {
auto& self = *this;

self->set_list_state(PageState::Loading);
self->set_events_state(PageState::Loading);

executor()->asyncExecute(
networkClient()->getDepartmentEventList(std::string(self->get_current_department().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](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();

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

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

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

EVENTO_UI_END
2 changes: 1 addition & 1 deletion src/Controller/View/SearchPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SearchPage : public BasicView, private GlobalAgent<SearchPageBridge> {

void loadDepartmentList();

void loadDepartmentEvents(int page);
void loadDepartmentEvents(int page, int departmentIdx);

void search(std::string const& keyword);

Expand Down
11 changes: 6 additions & 5 deletions src/Infrastructure/Network/NetworkClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,12 @@ Task<Result<EventQueryRes>> NetworkClient::getHistoryEventList(
Task<Result<EventQueryRes>> NetworkClient::getDepartmentEventList(
std::string larkDepartment, int page, int size, std::chrono::steady_clock::duration cacheTtl) {
#ifdef EVENTO_API_V1
auto result = co_await this->request<api::Evento>(http::verb::post,
endpoint("/event/list"),
{{"departmentId",
std::to_string(
departmentIdMap[larkDepartment])}});
auto result = co_await this->request<api::Evento>(
http::verb::post,
endpoint("/event/list",
{{"departmentId", std::to_string(departmentIdMap[larkDepartment])},
{"typeId", ""},
{"time", ""}}));
if (result.isErr())
co_return Err(result.unwrapErr());

Expand Down
59 changes: 30 additions & 29 deletions ui/views/page/search.slint
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export global SearchPageBridge {
in property <PageState> events-state: normal;
in property <int> total: 0;
out property <int> page-size: 12;
in-out property <StandardListViewItem> current-department;
in-out property <int> current-department-index: -1;
callback filter-department(string);
callback load-department-list();
callback load-department-events(int);
callback load-department-events(int, int);
callback navigate-to-detail(EventStruct);
public function select(index: int) {
current-department-index = index;
}
}

export component SearchPage inherits Page {
property <int> current-page-index: 0;
property <int> current-department-index: 0;

changed current-department-index => {
SearchPageBridge.load-department-events(current-page-index, current-department-index);
}

TouchArea {
pointer-event(e) => {
Expand Down Expand Up @@ -76,10 +76,11 @@ export component SearchPage inherits Page {
if SearchPageBridge.list-state == PageState.normal: Rectangle {
StandardListView {
model: SearchPageBridge.department;
current-item: SearchPageBridge.current-department-index;
current-item-changed(idx) => {
SearchPageBridge.current-department = SearchPageBridge.department[idx];
SearchPageBridge.load-department-events(root.current-page-index);
if (idx >= 0) {
root.current-department-index = idx;
}
debug(idx);
}
}
}
Expand Down Expand Up @@ -123,12 +124,12 @@ export component SearchPage inherits Page {
Button {
text: @tr("重新加载");
clicked => {
SearchPageBridge.load-department-events(current-page-index);
SearchPageBridge.load-department-events(current-page-index, root.current-department-index);
}
}
}

if SearchPageBridge.list-state != PageState.normal || SearchPageBridge.event-model.length == 0: Rectangle {
if SearchPageBridge.list-state != PageState.normal || (SearchPageBridge.event-model.length == 0 && SearchPageBridge.events-state == PageState.normal): Rectangle {
Text {
text: @tr("什么都没有呢");
font-size: Token.font.body.large.size;
Expand All @@ -138,25 +139,25 @@ export component SearchPage inherits Page {
}
}

if SearchPageBridge.total > SearchPageBridge.page-size: Rectangle {
height: 30px;
SPagination {
page-size: SearchPageBridge.page-size;
total: SearchPageBridge.total;
theme: Token.surrealism-ui-default-theme;
active <=> root.current-page-index;
// if SearchPageBridge.total > SearchPageBridge.page-size: Rectangle {
// height: 30px;
// SPagination {
// page-size: SearchPageBridge.page-size;
// total: SearchPageBridge.total;
// theme: Token.surrealism-ui-default-theme;
// active <=> root.current-page-index;

pre => {
SearchPageBridge.load-department-events(root.current-page-index);
}
next => {
SearchPageBridge.load-department-events(root.current-page-index);
}
clicked => {
SearchPageBridge.load-department-events(root.current-page-index);
}
}
}
// pre => {
// SearchPageBridge.load-department-events(root.current-page-index);
// }
// next => {
// SearchPageBridge.load-department-events(root.current-page-index);
// }
// clicked => {
// SearchPageBridge.load-department-events(root.current-page-index);
// }
// }
// }
}
}
}

0 comments on commit b8872a9

Please sign in to comment.