Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc alampy 1001 #70

Merged
merged 7 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Controller/View/DetailPage.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "app.h"

Check failure on line 1 in src/Controller/View/DetailPage.cc

View workflow job for this annotation

GitHub Actions / review

'app.h' file not found [clang-diagnostic-error]
#include <Controller/AsyncExecutor.hh>
#include <Controller/Convert.h>
#include <Controller/UiBridge.h>
Expand Down Expand Up @@ -117,15 +117,16 @@
auto message = std::format("{}{}",
subscribe ? "报名" : "取消报名",
success ? "成功" : "失败,请重试");
auto message_type = success ? MessageType::Success
: MessageType::Error;

if (success) {
auto model = self->get_event_model();
model.is_subscribed = subscribe;
self->set_event_model(model);
}

self.bridge.getMessageManager().showMessage(message,
MessageType::Error);
self.bridge.getMessageManager().showMessage(message, message_type);
});
}

Expand Down
31 changes: 20 additions & 11 deletions src/Infrastructure/Network/NetworkClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ static EventQueryRes eventEntityListV1ToV2(std::vector<EventEntityV1> const& lis
case StateV1::Before:
case StateV1::Registration:
state = State::SigningUp;
break;
case StateV1::Ongoing:
state = State::Active;
break;
case StateV1::Cancelled:
state = State::Cancelled;
break;
case StateV1::Over:
state = State::Completed;
break;
}

listV2.emplace_back(EventEntity{
Expand Down Expand Up @@ -282,12 +286,16 @@ 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
// The default logic is to get events in the current week,
// here we hardcode the time to 1970-01-01 to get events after 1970-01-01,
// which means all events for our project.

auto result = co_await this->request<api::Evento>(
http::verb::post,
endpoint("/event/list",
{{"departmentId", std::to_string(departmentIdMap[larkDepartment])},
{"typeId", ""},
{"time", ""}}));
{"time", "1970-01-01"}}));
if (result.isErr())
co_return Err(result.unwrapErr());

Expand Down Expand Up @@ -334,17 +342,17 @@ Task<Result<EventQueryRes>> NetworkClient::getEventById(int eventId) {
if (result.isErr())
co_return Err(result.unwrapErr());

std::vector<EventEntityV1> list;
auto json = result.unwrap();
if (json.is_null())
co_return Err(Error(Error::Data, "No Event"));

EventEntityV1 entityV1;
try {
nlohmann::from_json(result.unwrap(), list);
nlohmann::from_json(json, entityV1);
} catch (const nlohmann::json::exception& e) {
co_return Err(Error(Error::JsonDes, e.what()));
}

auto res = eventEntityListV1ToV2(list);
if (res.total == 0) {
co_return Err(Error(Error::Data, "No Event"));
}
auto res = eventEntityListV1ToV2({entityV1});

auto& event = res.elements.front();
auto statusResult = co_await getEventParticipate(event.id);
Expand Down Expand Up @@ -527,9 +535,10 @@ Task<Result<bool>> NetworkClient::subscribeEvent(int eventId, bool subscribe) {
std::string subscribeStr = subscribe ? "true" : "false";
#ifdef EVENTO_API_V1
auto result = co_await this->request<api::Evento>(http::verb::get,
endpoint("/user/subscribe"),
{{"eventId", std::to_string(eventId)},
{"isSubscribe", subscribeStr}});
endpoint("/user/subscribe",
{{"eventId", std::to_string(eventId)},
{"isSubscribe", subscribeStr}}),
{});
if (result.isErr())
co_return Err(result.unwrapErr());
co_return Ok(true);
Expand Down
144 changes: 60 additions & 84 deletions ui/components/event_card.slint
Original file line number Diff line number Diff line change
Expand Up @@ -11,119 +11,95 @@ export component EventCard inherits Card {
description: "活动内容",
id: 0
};
header := HorizontalLayout {
// width: 100%;
height: abbr-circle.height;
alignment: LayoutAlignment.space-between;
spacing: self.width - abbr-circle.width - pentagon.width;
abbr-circle := Rectangle {
width: 28px;
height: self.width;
border-radius: self.width / 2;
background: root.on-surface;
abbr-text := Text {
color: root.inverse-on-surface;
text: event.summary-abbr;
font-size: Token.font.label.large.size;
font-weight: Token.font.label.large.weight;
}
}

VerticalLayout {
width: 10px;
height: abbr-circle.width;
Rectangle {
width: pentagon.width;
height: (abbr-circle.height - pentagon.height) / 2;
VerticalLayout {
header := HorizontalLayout {
height: abbr-circle.height;
alignment: LayoutAlignment.space-between;
abbr-circle := Rectangle {
width: 28px;
height: self.width;
border-radius: self.width / 2;
background: root.on-surface;
abbr-text := Text {
color: root.inverse-on-surface;
text: event.summary-abbr;
font-size: Token.font.label.large.size;
font-weight: Token.font.label.large.weight;
}
}

pentagon := Image {
width: 10px;
height: self.width;
vertical-alignment: center;
colorize: root.on-surface;
source: Token.image.icon.pentagon;
}

Rectangle {
width: pentagon.width;
height: (abbr-circle.height - pentagon.height) / 2;
}
}
}

title := VerticalLayout {
height: root.height - root.padding * 2 - abbr-circle.height - info.height;
alignment: center;
event-title := Text {
min-height: 0;
preferred-height: 0;
vertical-stretch: 1;
vertical-alignment: center;
color: root.inverse-surface;
text: event.summary;
wrap: word-wrap;
overflow: elide;
font-size: Token.font.title.large.size;
font-weight: Token.font.title.large.weight;
}
}

info := VerticalLayout {
height: time-label.height * 3 + self.spacing * 2;
alignment: center;
spacing: 2px;
time-label := Rectangle {
time-label := HorizontalLayout {
height: 20px;
HorizontalLayout {
spacing: 6px;
time-icon := Image {
width: 16px;
height: self.width;
source: Token.image.icon.time;
colorize: time-text.color;
}
spacing: 6px;
time-icon := Image {
width: 16px;
vertical-alignment: center;
source: Token.image.icon.time;
colorize: time-text.color;
}

time-text := Text {
font-size: Token.font.label.large.size;
text: event.time;
width: parent.width - time-icon.width - parent.spacing;
overflow: elide;
}
time-text := Text {
horizontal-stretch: 1;
font-size: Token.font.label.large.size;
text: event.time;
overflow: elide;
}
}

location-label := Rectangle {
location-label := HorizontalLayout {
height: 20px;
HorizontalLayout {
spacing: 6px;
location-icon := Image {
width: 16px;
height: self.width;
source: Token.image.icon.locate;
colorize: location-text.color;
}
spacing: 6px;
location-icon := Image {
width: 16px;
vertical-alignment: center;
source: Token.image.icon.locate;
colorize: location-text.color;
}

location-text := Text {
font-size: Token.font.label.large.size;
text: event.location;
width: parent.width - location-icon.width - parent.spacing;
overflow: elide;
}
location-text := Text {
horizontal-stretch: 1;
font-size: Token.font.label.large.size;
text: event.location;
overflow: elide;
}
}

description-label := Rectangle {
description-label := HorizontalLayout {
height: 20px;
HorizontalLayout {
spacing: 6px;
description-icon := Image {
width: 16px;
height: self.width;
source: Token.image.icon.topic;
colorize: location-text.color;
}
spacing: 6px;
description-icon := Image {
width: 16px;
vertical-alignment: center;
source: Token.image.icon.topic;
colorize: location-text.color;
}

description-text := Text {
font-size: Token.font.label.large.size;
text: event.description;
width: parent.width - description-icon.width - parent.spacing;
overflow: elide;
}
description-text := Text {
horizontal-stretch: 1;
font-size: Token.font.label.large.size;
text: event.description;
overflow: elide;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions ui/views/page/detail.slint
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export component DetailPage inherits Page {
HorizontalLayout {
spacing: 20px;
Button {
min-width: 0;
preferred-width: 0;
have-icon: DetailPageBridge.subscribe-state == PageState.loading;
type: filled;
content: DetailPageBridge.event-model.is-subscribed ? @tr("取消报名") : @tr("报名");
Expand All @@ -233,6 +235,8 @@ export component DetailPage inherits Page {
}

Button {
min-width: 0;
preferred-width: 0;
type: filled;
content: DetailPageBridge.event-model.is-check-in ? @tr("已签到") : @tr("签到");
disable: DetailPageBridge.event-model.is-check-in || DetailPageBridge.event-model.state == EventState.Completed || DetailPageBridge.event-model.state == EventState.Cancelled;
Expand Down
Loading