Skip to content

Commit

Permalink
feat: add tuihub-rss special support
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Sep 25, 2024
1 parent eed602f commit ba481d4
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 13 deletions.
12 changes: 4 additions & 8 deletions lib/view/pages/settings/porter/porter_manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,15 @@ class PorterEditPanel extends StatelessWidget {
labelText: '全局名称',
),
),
TextFormField(
initialValue: porter.featureSummary.toString(),
readOnly: true,
decoration: const InputDecoration(
border: OutlineInputBorder(),
label: Text('支持功能'),
),
),
SwitchFormField(
initialValue: enabled,
onSaved: (newValue) => enabled = newValue!,
title: const Text('启用'),
),
TextFormMessage(
title: '支持功能',
message: porter.featureSummary.toString(),
),
],
errorMsg: state is TipherethEditPorterState && state.failed
? state.msg
Expand Down
25 changes: 25 additions & 0 deletions lib/view/pages/yesod/manage_notify_target_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ class NotifyTargetEditPanel extends StatelessWidget {
FramePage.of(context)?.closeDrawer();
}

List<Widget> specSectionTuiHubRSS(NotifyTarget target, FeatureFlag flag) {
debugPrint('specSectionTuiHubRSS ${flag.id}');
if (flag.id != 'rss') {
return [];
}
var url = '未知';
if (flag.extra['URLPrefix'] != null) {
url = '${flag.extra['URLPrefix']}/${target.id.id}';
}
return [
const FormSectionDivider(
title: 'TuiHub RSS',
),
TextReadOnlyFormField(
label: '订阅链接',
value: url,
)
];
}

@override
Widget build(BuildContext context) {
final notifyDestinations = context
Expand Down Expand Up @@ -234,6 +254,11 @@ class NotifyTargetEditPanel extends StatelessWidget {
onSaved: (newValue) => enabled = newValue!,
title: const Text('启用'),
),
...specSectionTuiHubRSS(
target,
notifyDestinations.firstWhere(
(element) => element.id == destination.id,
orElse: FeatureFlag.new)),
],
errorMsg: state is NetzachTargetEditState && state.failed
? state.msg
Expand Down
69 changes: 65 additions & 4 deletions lib/view/specialized/right_panel_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,65 @@ class _RightPanelFormState extends State<RightPanelForm> {
}
}

class FormSectionDivider extends StatelessWidget {
const FormSectionDivider({
super.key,
required this.title,
});

final String title;

@override
Widget build(BuildContext context) {
return Column(
children: [
Divider(
height: 10,
indent: 10,
endIndent: 10,
thickness: 2,
color: Theme.of(context).brightness == Brightness.dark
? Theme.of(context).colorScheme.outline
: Theme.of(context).colorScheme.outlineVariant,
),
Text(
title,
style: Theme.of(context).textTheme.bodySmall,
),
],
);
}
}

class TextFormMessage extends StatelessWidget {
const TextFormMessage({
super.key,
required this.title,
this.message,
});

final String title;
final String? message;

@override
Widget build(BuildContext context) {
return ExpansionTile(
title: Text(
title,
),
children: [
if (message != null)
Container(
padding: const EdgeInsets.all(16),
child: Text(
message!,
),
)
],
);
}
}

class TextFormErrorMessage extends StatelessWidget {
const TextFormErrorMessage({
super.key,
Expand Down Expand Up @@ -242,7 +301,7 @@ class _FeatureRequestFormFieldState extends State<FeatureRequestFormField> {
selectedFlag = widget.initialValue != null
? featureFlags.firstWhere(
(e) => e.id == widget.initialValue!.id,
orElse: () => featureFlags.first,
orElse: FeatureFlag.new,
)
: featureFlags.first;
config = widget.initialValue?.configJson ?? config;
Expand Down Expand Up @@ -274,8 +333,9 @@ class _FeatureRequestFormFieldState extends State<FeatureRequestFormField> {
children: [
if (featureFlags.isEmpty)
const TextFormErrorMessage(message: '服务器无可用类型')
else if (!featureFlags.any((e) => e.requireContext))
TextFormErrorMessage(message: '服务器未启用${selectedFlag?.id ?? ''}'),
else if (!featureFlags.any((e) => e.id == selectedFlag?.id))
TextFormErrorMessage(
message: '服务器未启用 ${widget.initialValue?.id ?? '功能'}'),
if (widget.flagReadOnly)
TextReadOnlyFormField(
label: '类型',
Expand Down Expand Up @@ -376,7 +436,8 @@ class _FeatureRequestFormFieldState extends State<FeatureRequestFormField> {
return null;
},
),
if (selectedFlag != null)
if (selectedFlag != null &&
featureFlags.any((e) => e.id == selectedFlag!.id))
JsonForm(
key: ValueKey(buildCounter++),
controller: jsonFormController,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dependencies:
tuihub_protos:
git:
url: https://github.com/tuihub/protos.git
ref: v0.4.22
ref: v0.4.23
fixnum: ^1.1.0

# theme
Expand Down

0 comments on commit ba481d4

Please sign in to comment.