Skip to content

Commit 2d121b1

Browse files
committed
Add copy-paste and shortcuts support for actions.
1 parent d2d1445 commit 2d121b1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/src/api/models/reaction.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:codelessly_json_annotation/codelessly_json_annotation.dart';
66
import 'package:equatable/equatable.dart';
77

8+
import '../generate_id.dart';
89
import '../mixins.dart';
910
import 'models.dart';
1011

@@ -22,23 +23,28 @@ class Reaction with EquatableMixin, SerializableMixin {
2223
/// Event that will trigger the action.
2324
final TriggerModel trigger;
2425

26+
final String id;
27+
2528
/// Creates a [Reaction] with the given data.
26-
const Reaction({
29+
Reaction({
30+
String? id,
2731
this.name = 'Action',
2832
required this.action,
2933
required this.trigger,
30-
});
34+
}) : id = id ?? generateId();
3135

3236
@override
33-
List<Object?> get props => [name, action, trigger];
37+
List<Object?> get props => [id, name, action, trigger];
3438

3539
/// Duplicate the current [Reaction] with the given data.
3640
Reaction copyWith({
41+
String? id,
3742
String? name,
3843
ActionModel? action,
3944
TriggerModel? trigger,
4045
}) =>
4146
Reaction(
47+
id: id ?? this.id,
4248
name: name ?? this.name,
4349
action: action ?? this.action,
4450
trigger: trigger ?? this.trigger,
@@ -49,4 +55,12 @@ class Reaction with EquatableMixin, SerializableMixin {
4955

5056
@override
5157
Map toJson() => _$ReactionToJson(this);
58+
59+
/// Sanitize the [Reaction] by removing the [id] and replacing it with a
60+
/// new one if [changeIds] is true.
61+
Reaction sanitize({required bool changeIds}) {
62+
return copyWith(
63+
id: changeIds ? generateId() : id,
64+
);
65+
}
5266
}

lib/src/api/models/reaction.g.dart

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)