Skip to content

Commit

Permalink
feat: add swap cw button to post form menu
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Oct 29, 2024
1 parent 5fc2ee7 commit 549ccc6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/i18n/aria/aria.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ showTranslateButtonInNoteFooter: "Add \"Translate\" to note action menu"
sinceDate: "Since"
stackTrace: "Stack trace"
streamingChannel: "Streaming channel"
swapCw: "Swap comments with the body"
tabName: "Tab name"
tabType: "Tab type"
tabs: "Tabs"
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 31
/// Strings: 54623 (1762 per locale)
/// Strings: 54624 (1762 per locale)
// coverage:ignore-file
// ignore_for_file: type=lint, unused_import
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/strings_en_US.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class TranslationsAriaEnUs {
String get sinceDate => 'Since';
String get stackTrace => 'Stack trace';
String get streamingChannel => 'Streaming channel';
String get swapCw => 'Swap comments with the body';
String get tabName => 'Tab name';
String get tabType => 'Tab type';
String get tabs => 'Tabs';
Expand Down
16 changes: 12 additions & 4 deletions lib/provider/post_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,12 @@ class PostNotifier extends _$PostNotifier {
}

void setCw(String? cw) {
if ((cw == null || cw.isEmpty) && state.cw != null) {
state = state.copyWith(cw: null);
if (cw == null || cw.isEmpty) {
if (state.cw != null) {
state = state.copyWith(cw: null);
} else {
return;
}
} else if (cw != state.cw) {
state = state.copyWith(cw: cw);
} else {
Expand Down Expand Up @@ -468,8 +472,12 @@ class PostNotifier extends _$PostNotifier {
}

void setText(String? text) {
if ((text == null || text.isEmpty) && state.text != null) {
state = state.copyWith(text: null);
if (text == null || text.isEmpty) {
if (state.text != null) {
state = state.copyWith(text: null);
} else {
return;
}
} else if (text != state.text) {
state = state.copyWith(text: text);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/post_notifier_provider.g.dart

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

31 changes: 31 additions & 0 deletions lib/view/widget/post_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ class PostForm extends HookConsumerWidget {
final focusNode = this.focusNode ?? useFocusNode();
final isCwFocused = useState(false);
final isFocused = useState(false);
ref.listen(
postNotifierProvider(account.value, noteId: noteId)
.select((request) => request.cw),
(_, cw) {
final s = cw ?? '';
if (s != cwController.text) {
cwController.text = s;
}
},
);
ref.listen(
postNotifierProvider(account.value, noteId: noteId)
.select((request) => request.text),
Expand Down Expand Up @@ -515,6 +525,27 @@ class PostForm extends HookConsumerWidget {
title: Text(t.misskey.reactionAcceptance),
),
),
PopupMenuItem(
onTap: () {
final text = request.text;
ref
.read(
postNotifierProvider(account.value).notifier,
)
.setText(request.cw);
ref
.read(
postNotifierProvider(account.value).notifier,
)
.setCw(text?.replaceAll('\n', ' '));
useCw.value = true;
},
enabled: request.text != null || request.cw != null,
child: ListTile(
leading: const Icon(Icons.swap_vert),
title: Text(t.aria.swapCw),
),
),
PopupMenuItem(
onTap: () async {
final confirmed = await confirm(
Expand Down

0 comments on commit 549ccc6

Please sign in to comment.