Skip to content

Commit

Permalink
feat: add the recent icons and emojis to the selector
Browse files Browse the repository at this point in the history
  • Loading branch information
asjqkkkk committed Dec 20, 2024
1 parent 1909e49 commit 53e52da
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:appflowy/plugins/database/widgets/cell_editor/checklist_cell_edi
import 'package:appflowy/plugins/database/widgets/row/row_detail.dart';
import 'package:appflowy/plugins/document/document_page.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';
import 'package:appflowy/shared/icon_emoji_picker/recent_icons.dart';
import 'package:appflowy/util/field_type_extension.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
Expand All @@ -22,7 +23,7 @@ import '../../shared/util.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

RecentIcons.enable = false;
group('grid row detail page:', () {
testWidgets('opens', (tester) async {
await tester.initializeAppFlowy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart';
import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';
import 'package:appflowy/shared/icon_emoji_picker/recent_icons.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
Expand All @@ -13,7 +14,7 @@ import '../../shared/util.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

RecentIcons.enable = false;
group('cover image:', () {
testWidgets('document cover tests', (tester) async {
await tester.initializeAppFlowy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';
import 'package:appflowy/shared/icon_emoji_picker/icon_picker.dart';
import 'package:appflowy/shared/icon_emoji_picker/recent_icons.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_icon_popup.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -11,7 +12,7 @@ import '../../shared/expectation.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

RecentIcons.enable = false;
final emoji = EmojiIconData.emoji('😁');

Future<EmojiIconData> loadIcon() async {
Expand Down
5 changes: 5 additions & 0 deletions frontend/appflowy_flutter/lib/core/config/kv_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ class KVKeys {
///
/// The value is a boolean string
static const String hasUpgradedSpace = 'hasUpgradedSpace060';

/// The key for saving the rencent icons
///
/// The value is a json string of [RecentIcons]
static const String kRecentIcons = 'kRecentIcons';
}
48 changes: 39 additions & 9 deletions frontend/appflowy_flutter/lib/plugins/base/emoji/emoji_picker.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:math';

import 'package:appflowy/plugins/base/emoji/emoji_picker_header.dart';
import 'package:appflowy/shared/icon_emoji_picker/emoji_search_bar.dart';
import 'package:appflowy/shared/icon_emoji_picker/emoji_skin_tone.dart';
import 'package:appflowy/shared/icon_emoji_picker/recent_icons.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
Expand All @@ -24,28 +27,53 @@ class FlowyEmojiPicker extends StatefulWidget {
}

class _FlowyEmojiPickerState extends State<FlowyEmojiPicker> {
EmojiData? emojiData;
late EmojiData emojiData;
bool loaded = false;

void loadEmojis(EmojiData data) {
RecentIcons.getEmojiIds().then((v) {
if (v.isEmpty) {
emojiData = data;
setState(() {
loaded = true;
});
return;
}
final categories = List.of(data.categories);
categories.insert(
0,
Category(
id: 'Recent',
emojiIds: v.sublist(0, min(widget.emojiPerLine, v.length)),
),
);
emojiData = EmojiData(categories: categories, emojis: data.emojis);
setState(() {
loaded = true;
});
});
}

@override
void initState() {
super.initState();

// load the emoji data from cache if it's available
if (kCachedEmojiData != null) {
emojiData = kCachedEmojiData;
loadEmojis(kCachedEmojiData!);
} else {
EmojiData.builtIn().then(
(value) {
kCachedEmojiData = value;
setState(() => emojiData = value);
loadEmojis(value);
},
);
}
}

@override
Widget build(BuildContext context) {
if (emojiData == null) {
if (!loaded) {
return const Center(
child: SizedBox.square(
dimension: 24.0,
Expand All @@ -57,21 +85,23 @@ class _FlowyEmojiPickerState extends State<FlowyEmojiPicker> {
}

return EmojiPicker(
emojiData: emojiData!,
emojiData: emojiData,
configuration: EmojiPickerConfiguration(
showTabs: false,
defaultSkinTone: lastSelectedEmojiSkinTone ?? EmojiSkinTone.none,
perLine: widget.emojiPerLine,
),
onEmojiSelected: widget.onEmojiSelected,
onEmojiSelected: (id, emoji) {
widget.onEmojiSelected.call(id, emoji);
RecentIcons.putEmoji(id);
},
padding: const EdgeInsets.symmetric(horizontal: 16.0),
headerBuilder: (context, category) {
return FlowyEmojiHeader(
category: category,
);
},
itemBuilder: (context, emojiId, emoji, callback) {
final name = emojiData?.emojis[emojiId]?.name ?? '';
final name = emojiData.emojis[emojiId]?.name ?? '';
return SizedBox.square(
dimension: 36.0,
child: FlowyButton(
Expand All @@ -93,7 +123,7 @@ class _FlowyEmojiPickerState extends State<FlowyEmojiPicker> {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: FlowyEmojiSearchBar(
emojiData: emojiData!,
emojiData: emojiData,
onKeywordChanged: (value) {
keyword.value = value;
},
Expand Down

This file was deleted.

Loading

0 comments on commit 53e52da

Please sign in to comment.