Skip to content

Commit

Permalink
feat: add post form menu (#460)
Browse files Browse the repository at this point in the history
* feat: add post form menu

* feat: add reset button to post form menu

* feat: add swap cw button to post form menu
  • Loading branch information
poppingmoon authored Oct 29, 2024
1 parent 1dfc491 commit 9573968
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 46 deletions.
2 changes: 2 additions & 0 deletions lib/i18n/aria/aria.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ recentlyUsedEmojis: "Recently used emojis"
renoteConfirm: "Are you sure you want to renote this note?"
renoteToChannel: "Renote to a channel"
renotedBy(rich): "Renoted by {user}"
reset: "Reset"
rotate: "Rotate"
scale: "Scale"
selectIcon: "Select an icon"
Expand Down Expand Up @@ -139,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: 54622 (1762 per locale)
/// Strings: 54624 (1762 per locale)
// coverage:ignore-file
// ignore_for_file: type=lint, unused_import
Expand Down
2 changes: 2 additions & 0 deletions lib/i18n/strings_en_US.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class TranslationsAriaEnUs {
const TextSpan(text: 'Renoted by '),
user,
]);
String get reset => 'Reset';
String get rotate => 'Rotate';
String get scale => 'Scale';
String get selectIcon => 'Select an icon';
Expand Down Expand Up @@ -228,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.

146 changes: 106 additions & 40 deletions lib/view/widget/post_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import '../../provider/post_notifier_provider.dart';
import '../../provider/timeline_tab_settings_provider.dart';
import '../../util/extract_mentions.dart';
import '../../util/future_with_dialog.dart';
import '../dialog/confirmation_dialog.dart';
import '../dialog/post_confirmation_dialog.dart';
import '../dialog/user_select_dialog.dart';
import '../page/channel/channels_page.dart';
Expand Down Expand Up @@ -271,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 @@ -462,50 +473,105 @@ class PostForm extends HookConsumerWidget {
? const Icon(Icons.rocket_outlined)
: const Icon(Icons.rocket),
),
IconButton(
onPressed: noteId == null
? () async {
final result = await showModalBottomSheet<
(ReactionAcceptance?,)>(
context: context,
builder: (context) => ListView(
shrinkWrap: true,
children: [
ListTile(
title: Text(
t.misskey.reactionAcceptance,
),
),
const Divider(height: 0.0),
...[
null,
...ReactionAcceptance.values,
].map(
(acceptance) => ListTile(
leading: ReactionAcceptanceIcon(
acceptance: acceptance,
PopupMenuButton<void>(
itemBuilder: (context) => [
PopupMenuItem(
onTap: noteId == null
? () async {
final result = await showModalBottomSheet<
(ReactionAcceptance?,)>(
context: context,
builder: (context) => ListView(
shrinkWrap: true,
children: [
ListTile(
title: Text(
t.misskey.reactionAcceptance,
),
),
title: ReactionAcceptanceWidget(
acceptance: acceptance,
const Divider(height: 0.0),
...[
null,
...ReactionAcceptance.values,
].map(
(acceptance) => ListTile(
leading: ReactionAcceptanceIcon(
acceptance: acceptance,
),
title: ReactionAcceptanceWidget(
acceptance: acceptance,
),
onTap: () =>
context.pop((acceptance,)),
),
),
onTap: () => context.pop((acceptance,)),
),
],
),
],
),
);
if (result != null) {
ref
.read(
postNotifierProvider(account.value)
.notifier,
)
.setReactionAcceptance(result.$1);
}
);
if (result != null) {
ref
.read(
postNotifierProvider(account.value)
.notifier,
)
.setReactionAcceptance(result.$1);
}
}
: null,
child: ListTile(
leading: ReactionAcceptanceIcon(
acceptance: request.reactionAcceptance,
),
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(
context,
message: t.misskey.resetAreYouSure,
);
if (!context.mounted) return;
if (confirmed) {
ref
.read(
postNotifierProvider(account.value).notifier,
)
.reset();
}
: null,
icon: ReactionAcceptanceIcon(
acceptance: request.reactionAcceptance,
},
child: ListTile(
leading: const Icon(Icons.delete),
title: Text(t.aria.reset),
iconColor: colors.error,
textColor: colors.error,
),
),
],
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(Icons.more_horiz),
),
),
if (showPostButton) ...[
Expand Down

0 comments on commit 9573968

Please sign in to comment.