Skip to content

Commit

Permalink
fix(netzach): add filter config & update list
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Dec 22, 2023
1 parent 8b75a0b commit 9dd08e2
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 89 deletions.
6 changes: 5 additions & 1 deletion l10n_arb/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@
"NOTIFY_TARGET_STATUS_SUSPEND": "停止",
"NOTIFY_TARGET_TYPE": "类型",
"NOTIFY_TARGET_TYPE_UNSPECIFIED": "未知",
"NOTIFY_TARGET_TYPE_TELEGRAM": "Telegram"
"NOTIFY_TARGET_TYPE_TELEGRAM": "Telegram",
"NOTIFY_FLOW_STATUS": "状态",
"NOTIFY_FLOW_STATUS_UNSPECIFIED": "未知",
"NOTIFY_FLOW_STATUS_ACTIVE": "启用",
"NOTIFY_FLOW_STATUS_SUSPEND": "停止"
}
6 changes: 6 additions & 0 deletions lib/l10n/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("停止"),
"FEED_CONFIG_STATUS_UNSPECIFIED":
MessageLookupByLibrary.simpleMessage("未知"),
"NOTIFY_FLOW_STATUS": MessageLookupByLibrary.simpleMessage("状态"),
"NOTIFY_FLOW_STATUS_ACTIVE": MessageLookupByLibrary.simpleMessage("启用"),
"NOTIFY_FLOW_STATUS_SUSPEND":
MessageLookupByLibrary.simpleMessage("停止"),
"NOTIFY_FLOW_STATUS_UNSPECIFIED":
MessageLookupByLibrary.simpleMessage("未知"),
"NOTIFY_TARGET_STATUS": MessageLookupByLibrary.simpleMessage("状态"),
"NOTIFY_TARGET_STATUS_ACTIVE":
MessageLookupByLibrary.simpleMessage("启用"),
Expand Down
40 changes: 40 additions & 0 deletions lib/l10n/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/repo/grpc/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,15 @@ String notifyTargetStatusString(NotifyTargetStatus status) {
}
return '';
}

String notifyFlowStatusString(NotifyFlowStatus status) {
switch (status) {
case NotifyFlowStatus.NOTIFY_FLOW_STATUS_UNSPECIFIED:
return S.current.NOTIFY_FLOW_STATUS_UNSPECIFIED;
case NotifyFlowStatus.NOTIFY_FLOW_STATUS_ACTIVE:
return S.current.NOTIFY_FLOW_STATUS_ACTIVE;
case NotifyFlowStatus.NOTIFY_FLOW_STATUS_SUSPEND:
return S.current.NOTIFY_FLOW_STATUS_SUSPEND;
}
return '';
}
199 changes: 154 additions & 45 deletions lib/view/pages/settings/notify/notify_flow_add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import 'package:tuihub_protos/librarian/sephirah/v1/yesod.pb.dart';

import '../../../../bloc/netzach/netzach_bloc.dart';
import '../../../../bloc/yesod/yesod_bloc.dart';
import '../../../../repo/grpc/l10n.dart';
import '../../../../route.dart';
import '../../../components/expand_rail_tile.dart';
import '../../../components/toast.dart';
import '../../../form/form_field.dart';
import '../../../helper/spacing.dart';
Expand Down Expand Up @@ -42,6 +44,8 @@ class _NotifyFlowAddPageState extends State<NotifyFlowAddPage> {
}
},
builder: (context, state) {
final notifySources = context.read<YesodBloc>().state.feedConfigs ?? [];
final notifyTargets = state.notifyTargets ?? [];
return Scaffold(
appBar: AppBar(
shape: const RoundedRectangleBorder(
Expand Down Expand Up @@ -125,40 +129,97 @@ class _NotifyFlowAddPageState extends State<NotifyFlowAddPage> {
),
Step(
title: const Text('通知源'),
content: MultiSelectDialogField(
title: const Text('订阅源'),
buttonText: const Text('订阅'),
buttonIcon: const Icon(Icons.filter_alt_outlined),
items: [
for (final ListFeedConfigsResponse_FeedWithConfig config
in context
.read<YesodBloc>()
.state
.feedConfigs ??
[])
MultiSelectItem(
config.config.id,
config.feed.title.isNotEmpty
? config.feed.title
: config.config.feedUrl),
],
initialValue:
sources.map((e) => e.sourceId).toList(),
onConfirm: (values) {
sources = values
.map((e) => NotifyFlowSource(sourceId: e))
.toList();
},
decoration: BoxDecoration(
borderRadius: SpacingHelper.defaultBorderRadius,
content: Column(children: [
MultiSelectDialogField(
title: const Text('订阅源'),
buttonText: const Text('订阅'),
buttonIcon: const Icon(Icons.filter_alt_outlined),
items: [
for (final ListFeedConfigsResponse_FeedWithConfig config
in notifySources)
MultiSelectItem(
config.config.id,
config.feed.title.isNotEmpty
? config.feed.title
: config.config.feedUrl),
],
initialValue:
sources.map((e) => e.sourceId).toList(),
onConfirm: (values) {
setState(() {
sources = values
.map((e) => NotifyFlowSource(sourceId: e))
.toList();
});
},
decoration: BoxDecoration(
borderRadius: SpacingHelper.defaultBorderRadius,
),
validator: (value) {
if (value == null || value.isEmpty) {
return '请选择至少一个订阅';
}
return null;
},
),
validator: (value) {
if (value == null || value.isEmpty) {
return '请选择至少一个订阅';
}
return null;
},
),
for (var i = 0; i < sources.length; i++)
Column(children: [
SpacingHelper.defaultDivider,
Align(
alignment: Alignment.centerLeft,
child: Text(notifySources
.firstWhere((e) =>
e.config.id == sources[i].sourceId)
.feed
.title),
),
const SizedBox(
height: 8,
),
ExpandRailTile(
title: const Text('过滤器'),
children: [
const SizedBox(
height: 8,
),
TextFormField(
onChanged: (newValue) {
setState(() {
sources[i].filter = NotifyFilter(
includeKeywords: [newValue],
excludeKeywords: sources[i]
.filter
.excludeKeywords,
);
});
},
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: '排除关键字',
),
),
const SizedBox(
height: 8,
),
TextFormField(
onChanged: (newValue) {
setState(() {
sources[i].filter = NotifyFilter(
includeKeywords: sources[i]
.filter
.includeKeywords,
excludeKeywords: [newValue],
);
});
},
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: '包含关键字',
),
),
]),
]),
]),
),
Step(
title: const Text('通知目标'),
Expand All @@ -168,9 +229,9 @@ class _NotifyFlowAddPageState extends State<NotifyFlowAddPage> {
buttonText: const Text('第三方平台'),
buttonIcon: const Icon(Icons.filter_alt_outlined),
items: [
for (final NotifyTarget config
in state.notifyTargets ?? [])
MultiSelectItem(config.id, config.name),
for (final NotifyTarget config in notifyTargets)
MultiSelectItem(config.id,
'${config.name} (${notifyTargetTypeString(config.type)})'),
],
initialValue:
targets.map((e) => e.targetId).toList(),
Expand All @@ -191,25 +252,73 @@ class _NotifyFlowAddPageState extends State<NotifyFlowAddPage> {
return null;
},
),
for (final NotifyFlowTarget target in targets)
for (var i = 0; i < targets.length; i++)
Column(children: [
SpacingHelper.defaultDivider,
Align(
alignment: Alignment.centerLeft,
child: Text(
'${notifyTargets.firstWhere((e) => e.id == targets[i].targetId).name} (${notifyTargetTypeString(notifyTargets.firstWhere((e) => e.id == targets[i].targetId).type)})'),
),
const SizedBox(
height: 16,
height: 8,
),
TextFormField(
onChanged: (newValue) {
setState(() {
targets[targets.indexWhere((e) =>
e.targetId == target.targetId)]
.channelId = newValue;
targets[i].channelId = newValue;
});
},
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText:
'频道: ${state.notifyTargets?.firstWhere((e) => e.id == target.targetId).name ?? ''}',
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: '频道',
),
),
const SizedBox(
height: 8,
),
ExpandRailTile(
title: const Text('过滤器'),
children: [
const SizedBox(
height: 8,
),
TextFormField(
onChanged: (newValue) {
setState(() {
targets[i].filter = NotifyFilter(
includeKeywords: [newValue],
excludeKeywords: targets[i]
.filter
.excludeKeywords,
);
});
},
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: '排除关键字',
),
),
const SizedBox(
height: 8,
),
TextFormField(
onChanged: (newValue) {
setState(() {
targets[i].filter = NotifyFilter(
includeKeywords: targets[i]
.filter
.includeKeywords,
excludeKeywords: [newValue],
);
});
},
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: '包含关键字',
),
),
]),
]),
]),
),
Expand Down
Loading

0 comments on commit 9dd08e2

Please sign in to comment.