From 549ccc61e8a09c27228aad6851a533e6bbffb849 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Wed, 30 Oct 2024 07:37:10 +0900 Subject: [PATCH] feat: add swap cw button to post form menu --- lib/i18n/aria/aria.i18n.yaml | 1 + lib/i18n/strings.g.dart | 2 +- lib/i18n/strings_en_US.g.dart | 1 + lib/provider/post_notifier_provider.dart | 16 ++++++++--- lib/provider/post_notifier_provider.g.dart | 2 +- lib/view/widget/post_form.dart | 31 ++++++++++++++++++++++ 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/lib/i18n/aria/aria.i18n.yaml b/lib/i18n/aria/aria.i18n.yaml index a189a27f..79205bc6 100644 --- a/lib/i18n/aria/aria.i18n.yaml +++ b/lib/i18n/aria/aria.i18n.yaml @@ -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" diff --git a/lib/i18n/strings.g.dart b/lib/i18n/strings.g.dart index 5fa916dc..4633341a 100644 --- a/lib/i18n/strings.g.dart +++ b/lib/i18n/strings.g.dart @@ -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 diff --git a/lib/i18n/strings_en_US.g.dart b/lib/i18n/strings_en_US.g.dart index 2671a4ff..461d113d 100644 --- a/lib/i18n/strings_en_US.g.dart +++ b/lib/i18n/strings_en_US.g.dart @@ -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'; diff --git a/lib/provider/post_notifier_provider.dart b/lib/provider/post_notifier_provider.dart index 59171798..d17e73c2 100644 --- a/lib/provider/post_notifier_provider.dart +++ b/lib/provider/post_notifier_provider.dart @@ -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 { @@ -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 { diff --git a/lib/provider/post_notifier_provider.g.dart b/lib/provider/post_notifier_provider.g.dart index 25b9fdb5..56c09215 100644 --- a/lib/provider/post_notifier_provider.g.dart +++ b/lib/provider/post_notifier_provider.g.dart @@ -6,7 +6,7 @@ part of 'post_notifier_provider.dart'; // RiverpodGenerator // ************************************************************************** -String _$postNotifierHash() => r'fc224bbd9a943ee7a09a4c5a6bcee70bf4e72895'; +String _$postNotifierHash() => r'd8beee3b314a1ae828444dde84d3fff777bacc52'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/view/widget/post_form.dart b/lib/view/widget/post_form.dart index bb0cef45..711642f2 100644 --- a/lib/view/widget/post_form.dart +++ b/lib/view/widget/post_form.dart @@ -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), @@ -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(