Skip to content

Commit

Permalink
feat: reset recently used emojis (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon authored Oct 27, 2024
1 parent e1b7328 commit d3af77c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 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 @@ -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}"
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: 54620 (1761 per locale)
/// Strings: 54621 (1761 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 @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/recently_used_emojis_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RecentlyUsedEmojisNotifier extends _$RecentlyUsedEmojisNotifier {
await _save({emoji, ...state}.take(32).toList());
}

Future<void> clear() async {
Future<void> reset() async {
await _save([]);
}
}
2 changes: 1 addition & 1 deletion lib/provider/recently_used_emojis_notifier_provider.g.dart

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

79 changes: 79 additions & 0 deletions lib/view/page/settings/pinned_emojis_editor_page.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(
Expand Down Expand Up @@ -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<void>(
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),
),
],
);
}
}

0 comments on commit d3af77c

Please sign in to comment.