From d3af77cf6940cc7ffdef37608025692188c585f3 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Mon, 28 Oct 2024 01:06:20 +0900 Subject: [PATCH] feat: reset recently used emojis (#452) --- lib/i18n/aria/aria.i18n.yaml | 1 + lib/i18n/strings.g.dart | 2 +- lib/i18n/strings_en_US.g.dart | 1 + ...ecently_used_emojis_notifier_provider.dart | 2 +- ...ently_used_emojis_notifier_provider.g.dart | 2 +- .../settings/pinned_emojis_editor_page.dart | 79 +++++++++++++++++++ 6 files changed, 84 insertions(+), 3 deletions(-) diff --git a/lib/i18n/aria/aria.i18n.yaml b/lib/i18n/aria/aria.i18n.yaml index 7109c7d2..aa815bb4 100644 --- a/lib/i18n/aria/aria.i18n.yaml +++ b/lib/i18n/aria/aria.i18n.yaml @@ -101,6 +101,7 @@ playVideo: "Play video" pleaseCopyResponse: "Please copy this response" postConfirm: "Are you sure you want to post this note?" reactionConfirm: "Are you sure you want to add a reaction?" +recentlyUsedEmojis: "Recently used emojis" renoteConfirm: "Are you sure you want to renote this note?" renoteToChannel: "Renote to a channel" renotedBy(rich): "Renoted by {user}" diff --git a/lib/i18n/strings.g.dart b/lib/i18n/strings.g.dart index adb1c9f9..967a1fef 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: 54620 (1761 per locale) +/// Strings: 54621 (1761 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 5828650b..a552ed55 100644 --- a/lib/i18n/strings_en_US.g.dart +++ b/lib/i18n/strings_en_US.g.dart @@ -181,6 +181,7 @@ class TranslationsAriaEnUs { String get pleaseCopyResponse => 'Please copy this response'; String get postConfirm => 'Are you sure you want to post this note?'; String get reactionConfirm => 'Are you sure you want to add a reaction?'; + String get recentlyUsedEmojis => 'Recently used emojis'; String get renoteConfirm => 'Are you sure you want to renote this note?'; String get renoteToChannel => 'Renote to a channel'; TextSpan renotedBy({required InlineSpan user}) => TextSpan(children: [ diff --git a/lib/provider/recently_used_emojis_notifier_provider.dart b/lib/provider/recently_used_emojis_notifier_provider.dart index 089e2cdb..8a0766c9 100644 --- a/lib/provider/recently_used_emojis_notifier_provider.dart +++ b/lib/provider/recently_used_emojis_notifier_provider.dart @@ -25,7 +25,7 @@ class RecentlyUsedEmojisNotifier extends _$RecentlyUsedEmojisNotifier { await _save({emoji, ...state}.take(32).toList()); } - Future clear() async { + Future reset() async { await _save([]); } } diff --git a/lib/provider/recently_used_emojis_notifier_provider.g.dart b/lib/provider/recently_used_emojis_notifier_provider.g.dart index 7852ff54..f86f5d07 100644 --- a/lib/provider/recently_used_emojis_notifier_provider.g.dart +++ b/lib/provider/recently_used_emojis_notifier_provider.g.dart @@ -7,7 +7,7 @@ part of 'recently_used_emojis_notifier_provider.dart'; // ************************************************************************** String _$recentlyUsedEmojisNotifierHash() => - r'fd607c6cbcc176accc86de3cb92d678e38ea1803'; + r'7503fbc4429196d128494af9286b2aa5c26c4b90'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/view/page/settings/pinned_emojis_editor_page.dart b/lib/view/page/settings/pinned_emojis_editor_page.dart index 142ec13c..ac4076e8 100644 --- a/lib/view/page/settings/pinned_emojis_editor_page.dart +++ b/lib/view/page/settings/pinned_emojis_editor_page.dart @@ -1,11 +1,15 @@ +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import '../../../i18n/strings.g.dart'; import '../../../model/account.dart'; import '../../../provider/account_settings_notifier_provider.dart'; +import '../../../provider/recently_used_emojis_notifier_provider.dart'; +import '../../dialog/confirmation_dialog.dart'; import '../../widget/account_settings_scaffold.dart'; import '../../widget/emoji_picker.dart'; +import '../../widget/emoji_sheet.dart'; import '../../widget/emoji_widget.dart'; import '../../widget/pinned_emojis_editor.dart'; @@ -25,7 +29,9 @@ class PinnedEmojisEditorPage extends ConsumerWidget { children: [ PinnedEmojisEditor(account: account, reaction: true), PinnedEmojisEditor(account: account), + _RecentlyUsedEmojisEditor(account: account), ListTile( + leading: const Icon(Icons.emoji_symbols), title: Text(t.aria.defaultReaction), subtitle: settings.defaultReaction != null ? Builder( @@ -66,3 +72,76 @@ class PinnedEmojisEditorPage extends ConsumerWidget { ); } } + +class _RecentlyUsedEmojisEditor extends ConsumerWidget { + const _RecentlyUsedEmojisEditor({required this.account}); + + final Account account; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final recentlyUsedEmojis = + ref.watch(recentlyUsedEmojisNotifierProvider(account)); + + return ExpansionTile( + leading: const Icon(Icons.history), + title: Text(t.aria.recentlyUsedEmojis), + children: [ + if (recentlyUsedEmojis.isNotEmpty) ...[ + Card( + margin: const EdgeInsets.all(8.0), + child: Container( + width: double.infinity, + padding: const EdgeInsets.all(8.0), + child: Wrap( + spacing: 4.0, + runSpacing: 4.0, + children: recentlyUsedEmojis + .mapIndexed( + (index, emoji) => EmojiWidget( + account: account, + emoji: emoji, + onTap: () => showModalBottomSheet( + context: context, + builder: (context) => EmojiSheet( + account: account, + emoji: emoji, + ), + ), + style: DefaultTextStyle.of(context) + .style + .apply(fontSizeFactor: 2.0), + disableTooltip: true, + ), + ) + .toList(), + ), + ), + ), + ListTile( + leading: const Icon(Icons.refresh), + title: Text(t.misskey.default_), + onTap: () async { + final confirmed = await confirm( + context, + message: t.misskey.resetAreYouSure, + ); + if (confirmed) { + await ref + .read(recentlyUsedEmojisNotifierProvider(account).notifier) + .reset(); + } + }, + iconColor: Theme.of(context).colorScheme.error, + textColor: Theme.of(context).colorScheme.error, + dense: true, + ), + ] else + Padding( + padding: const EdgeInsets.all(8.0), + child: Text(t.misskey.nothing), + ), + ], + ); + } +}