parent
f35f715b81
commit
3fc33a5ac9
1 changed files with 1236 additions and 55 deletions
53
lib/widgets/composer/bot_command_form.dart
Normal file
53
lib/widgets/composer/bot_command_form.dart
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/controllers/bot_command_draft.dart";
|
||||
import "package:nexus/models/bot_command_draft.dart";
|
||||
import "package:nexus/widgets/composer/bot_option_pill.dart";
|
||||
|
||||
/// A bot command with its parameters filled in inline, like Discord's slash
|
||||
/// commands.
|
||||
class const BotCommandForm(
|
||||
final BotCommandDraft draft, {
|
||||
required final VoidCallback onSubmit,
|
||||
|
||||
/// Called on backspace in the first parameter while empty.
|
||||
required final VoidCallback onRemove,
|
||||
super.key,
|
||||
}) extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
crossAxisAlignment: .center,
|
||||
children: [
|
||||
Text(
|
||||
draft.command.prefix,
|
||||
style: .new(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: .bold,
|
||||
),
|
||||
),
|
||||
...draft.shown.mapIndexed(
|
||||
(index, parameter) => BotOptionPill(
|
||||
parameter,
|
||||
key: ValueKey(parameter.key),
|
||||
roomId: draft.roomId,
|
||||
onSubmit: onSubmit,
|
||||
onRemove: parameter.optional
|
||||
? () => ref
|
||||
.read(
|
||||
BotCommandDraftController.provider(draft.roomId)
|
||||
.notifier,
|
||||
)
|
||||
.removeOption(parameter.key)
|
||||
: index == 0
|
||||
? onRemove
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue