Skip to content

Commit

Permalink
feat: rebuild notify manage pages
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Sep 20, 2024
1 parent c20ee1d commit 2bfd3c3
Show file tree
Hide file tree
Showing 32 changed files with 1,982 additions and 1,934 deletions.
10 changes: 9 additions & 1 deletion l10n_arb/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,18 @@
"feedConfigManage": "订阅管理",
"feedConfigAdd": "添加订阅",
"feedConfigEdit": "编辑订阅",
"automation": "自动化",
"feedActionSetManage": "规则集管理",
"feedActionSetAdd": "添加规则集",
"feedActionSetEdit": "编辑规则集",
"allArticles": "全部文章",
"filteredArticles": "筛选文章",
"notifyFlowManage": "推送管理",
"notifyFlowAdd": "添加推送",
"notifyFlowEdit": "编辑推送",
"notifyTargetManage": "推送目标管理",
"notifyTargetAdd": "添加推送目标",
"notifyTargetEdit": "编辑推送目标",

"settings": "设置",
"currentDevice": "当前设备",
Expand Down Expand Up @@ -160,11 +167,12 @@
"PORTER_CONNECTION_STATUS_DISCONNECTED": "连接断开",
"PORTER_CONNECTION_STATUS_ACTIVE": "工作中",
"PORTER_CONNECTION_STATUS_ACTIVATION_FAILED": "启用失败",
"PORTER_CONNECTION_STATUS_DOWNGRADED": "降级",
"PORTER_CONTEXT_HANDLE_STATUS_UNSPECIFIED": "未知",
"PORTER_CONTEXT_HANDLE_STATUS_QUEUEING": "排队中",
"PORTER_CONTEXT_HANDLE_STATUS_DOWNGRADED": "降级",
"PORTER_CONTEXT_HANDLE_STATUS_ACTIVE": "工作中",
"PORTER_CONTEXT_HANDLE_STATUS_BLOCKED": "已停用",
"PORTER_CONTEXT_HANDLE_STATUS_BLOCKED": "未安排",
"SYSTEM_NOTIFICATION_LEVEL_UNSPECIFIED": "未知",
"SYSTEM_NOTIFICATION_LEVEL_ERROR": "错误",
"SYSTEM_NOTIFICATION_LEVEL_WARNING": "警告",
Expand Down
26 changes: 26 additions & 0 deletions lib/bloc/main_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,32 @@ class MainBloc extends Bloc<MainEvent, MainState> {
}
}, transformer: droppable());

on<MainRefreshServerInfoEvent>((event, emit) async {
if (state.currentServer == null) {
return;
}
if (state.lastRefreshServerInfo != null &&
DateTime.now().difference(state.lastRefreshServerInfo!) <
const Duration(minutes: 1)) {
return;
}
final resp = await _api.doRequest((client) => client.getServerInformation,
GetServerInformationRequest());
if (resp.status == ApiStatus.success) {
final info = resp.getData();
emit(state.copyWith(
serverInfo: ServerInformation(
sourceCodeAddress: info.serverBinarySummary.sourceCodeAddress,
buildVersion: info.serverBinarySummary.buildVersion,
buildDate: info.serverBinarySummary.buildDate,
protocolVersion: info.protocolSummary.version,
),
serverFeatureSummary: info.featureSummary,
lastRefreshServerInfo: DateTime.now(),
));
}
}, transformer: droppable());

on<MainLogoutEvent>((event, emit) async {
_pruneChild();
emit(MainState());
Expand Down
2 changes: 2 additions & 0 deletions lib/bloc/main_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class MainManualLoginEvent extends MainEvent {
MainManualLoginEvent(this.username, this.password);
}

class MainRefreshServerInfoEvent extends MainEvent {}

class MainLogoutEvent extends MainEvent {}

class MainRegisterEvent extends MainEvent {
Expand Down
6 changes: 6 additions & 0 deletions lib/bloc/main_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MainState {
late ClientDeviceInfo? deviceInfo;
late List<ServerConfig>? knownServers;
late Map<String, ServerInstanceSummary>? knownServerInstanceSummary;
late DateTime? lastRefreshServerInfo;

MainState({
this.currentServer,
Expand All @@ -21,6 +22,7 @@ class MainState {
this.deviceInfo,
this.knownServers,
this.knownServerInstanceSummary,
this.lastRefreshServerInfo,
});

MainState copyWith({
Expand All @@ -34,6 +36,7 @@ class MainState {
ClientDeviceInfo? deviceInfo,
List<ServerConfig>? knownServers,
Map<String, ServerInstanceSummary>? knownServerInstanceSummary,
DateTime? lastRefreshServerInfo,
}) {
return MainState(
currentServer: currentServer ?? this.currentServer,
Expand All @@ -46,6 +49,8 @@ class MainState {
knownServers: knownServers ?? this.knownServers,
knownServerInstanceSummary:
knownServerInstanceSummary ?? this.knownServerInstanceSummary,
lastRefreshServerInfo:
lastRefreshServerInfo ?? this.lastRefreshServerInfo,
);
}

Expand All @@ -59,6 +64,7 @@ class MainState {
deviceInfo = other.deviceInfo;
knownServers = other.knownServers;
knownServerInstanceSummary = other.knownServerInstanceSummary;
lastRefreshServerInfo = other.lastRefreshServerInfo;
}
}

Expand Down
9 changes: 2 additions & 7 deletions lib/bloc/netzach/netzach_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ class NetzachBloc extends Bloc<NetzachEvent, NetzachState> {
));
});

on<NetzachSetTargetEditIndexEvent>((event, emit) async {
emit(state.copyWith(notifyTargetEditIndex: event.index));
});

on<NetzachTargetEditEvent>((event, emit) async {
emit(NetzachTargetEditState(state, EventStatus.processing));
final resp = await _api.doRequest(
Expand All @@ -102,10 +98,9 @@ class NetzachBloc extends Bloc<NetzachEvent, NetzachState> {
return;
}

final targets = state.notifyTargets ?? [];
targets[state.notifyTargetEditIndex!] = event.target;
add(NetzachTargetLoadEvent());
emit(NetzachTargetEditState(
state.copyWith(notifyTargets: targets),
state,
EventStatus.success,
));
});
Expand Down
6 changes: 0 additions & 6 deletions lib/bloc/netzach/netzach_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ final class NetzachTargetAddEvent extends NetzachEvent {
NetzachTargetAddEvent(this.target);
}

final class NetzachSetTargetEditIndexEvent extends NetzachEvent {
final int index;

NetzachSetTargetEditIndexEvent(this.index);
}

final class NetzachTargetEditEvent extends NetzachEvent {
final NotifyTarget target;

Expand Down
6 changes: 0 additions & 6 deletions lib/bloc/netzach/netzach_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ class NetzachState {
late List<NotifyTarget>? notifyTargets;
late List<NotifyFlow>? notifyFlows;

late int? notifyTargetEditIndex;
late int? notifyFlowEditIndex;

late List<SystemNotification>? systemNotifications;
late SystemNotificationFilter? systemNotificationFilter;

NetzachState({
this.notifyTargets,
this.notifyTargetEditIndex,
this.notifyFlows,
this.notifyFlowEditIndex,
this.systemNotifications,
Expand All @@ -21,16 +19,13 @@ class NetzachState {

NetzachState copyWith({
List<NotifyTarget>? notifyTargets,
int? notifyTargetEditIndex,
List<NotifyFlow>? notifyFlows,
int? notifyFlowEditIndex,
List<SystemNotification>? systemNotifications,
SystemNotificationFilter? systemNotificationFilter,
}) {
return NetzachState(
notifyTargets: notifyTargets ?? this.notifyTargets,
notifyTargetEditIndex:
notifyTargetEditIndex ?? this.notifyTargetEditIndex,
notifyFlows: notifyFlows ?? this.notifyFlows,
notifyFlowEditIndex: notifyFlowEditIndex ?? this.notifyFlowEditIndex,
systemNotifications: systemNotifications ?? this.systemNotifications,
Expand All @@ -41,7 +36,6 @@ class NetzachState {

void _from(NetzachState other) {
notifyTargets = other.notifyTargets;
notifyTargetEditIndex = other.notifyTargetEditIndex;
notifyFlows = other.notifyFlows;
notifyFlowEditIndex = other.notifyFlowEditIndex;
systemNotifications = other.systemNotifications;
Expand Down
6 changes: 1 addition & 5 deletions lib/bloc/yesod/yesod_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ class YesodBloc extends Bloc<YesodEvent, YesodState> {
on<YesodFeedConfigLoadEvent>((event, emit) async {
final List<ListFeedConfigsResponse_FeedWithConfig> configs =
await _repo.getFeedConfigs();
emit(YesodFeedConfigLoadState(
state.copyWith(
feedConfigs: configs,
),
EventStatus.processing));
emit(YesodFeedConfigLoadState(state, EventStatus.processing));

final resp = await _api.doRequest(
(client) => client.listFeedConfigs,
Expand Down
Loading

0 comments on commit 2bfd3c3

Please sign in to comment.