diff --git a/lib/pangea/analytics_details_popup/vocab_analytics_list_tile.dart b/lib/pangea/analytics_details_popup/vocab_analytics_list_tile.dart index 957f8e008..6da22a845 100644 --- a/lib/pangea/analytics_details_popup/vocab_analytics_list_tile.dart +++ b/lib/pangea/analytics_details_popup/vocab_analytics_list_tile.dart @@ -8,10 +8,12 @@ import 'package:fluffychat/pangea/toolbar/utils/shrinkable_text.dart'; class VocabAnalyticsListTile extends StatefulWidget { const VocabAnalyticsListTile({ super.key, + required this.emoji, required this.constructUse, required this.onTap, }); + final String? emoji; final void Function() onTap; final ConstructUses constructUse; @@ -51,18 +53,14 @@ class VocabAnalyticsListTileState extends State { Container( alignment: Alignment.center, height: (maxWidth - padding * 2) * 0.6, - child: Opacity( - opacity: - widget.constructUse.id.userSetEmoji.isEmpty ? 0.5 : 1, - child: widget.constructUse.id.userSetEmoji.isNotEmpty - ? Text( - widget.constructUse.id.userSetEmoji.first, - style: const TextStyle( - fontSize: 22, - ), - ) - : widget.constructUse.constructLevel.icon(36.0), - ), + child: widget.emoji != null + ? Text( + widget.emoji!, + style: const TextStyle( + fontSize: 22, + ), + ) + : widget.constructUse.constructLevel.icon(36.0), ), Container( alignment: Alignment.topCenter, diff --git a/lib/pangea/analytics_details_popup/vocab_analytics_list_view.dart b/lib/pangea/analytics_details_popup/vocab_analytics_list_view.dart index 9e44e45e3..1ac4aa672 100644 --- a/lib/pangea/analytics_details_popup/vocab_analytics_list_view.dart +++ b/lib/pangea/analytics_details_popup/vocab_analytics_list_view.dart @@ -145,6 +145,8 @@ class VocabAnalyticsListView extends StatelessWidget { return VocabAnalyticsListTile( onTap: () => controller.setConstructZoom(vocabItem.id), constructUse: vocabItem, + emoji: vocabItem.id.userSetEmoji.firstOrNull ?? + vocabItem.id.getLemmaInfoCached()?.emoji.firstOrNull, ); }, ), diff --git a/lib/pangea/constructs/construct_identifier.dart b/lib/pangea/constructs/construct_identifier.dart index 360aaa9f9..b3c023701 100644 --- a/lib/pangea/constructs/construct_identifier.dart +++ b/lib/pangea/constructs/construct_identifier.dart @@ -209,24 +209,28 @@ class ConstructIdentifier { } } + LemmaInfoRequest get _lemmaInfoRequest => LemmaInfoRequest( + partOfSpeech: category, + lemmaLang: MatrixState + .pangeaController.languageController.userL2?.langCodeShort ?? + LanguageKeys.defaultLanguage, + userL1: MatrixState + .pangeaController.languageController.userL1?.langCodeShort ?? + LanguageKeys.defaultLanguage, + lemma: lemma, + ); + /// [lemmmaLang] if not set, assumed to be userL2 - Future getLemmaInfo([ + Future getLemmaInfo() => LemmaInfoRepo.get( + _lemmaInfoRequest, + ); + + LemmaInfoResponse? getLemmaInfoCached([ String? lemmaLang, String? userl1, ]) => - LemmaInfoRepo.get( - LemmaInfoRequest( - partOfSpeech: category, - lemmaLang: lemmaLang ?? - MatrixState - .pangeaController.languageController.userL2?.langCodeShort ?? - LanguageKeys.defaultLanguage, - userL1: userl1 ?? - MatrixState - .pangeaController.languageController.userL1?.langCodeShort ?? - LanguageKeys.defaultLanguage, - lemma: lemma, - ), + LemmaInfoRepo.getCached( + _lemmaInfoRequest, ); bool get isContentWord => diff --git a/lib/pangea/lemmas/lemma_info_repo.dart b/lib/pangea/lemmas/lemma_info_repo.dart index bd3bb785e..d3acc5144 100644 --- a/lib/pangea/lemmas/lemma_info_repo.dart +++ b/lib/pangea/lemmas/lemma_info_repo.dart @@ -24,7 +24,7 @@ class LemmaInfoRepo { _lemmaStorage.write(request.storageKey, response.toJson()); } - static Future _fetch(LemmaInfoRequest request) async { + static LemmaInfoResponse? getCached(LemmaInfoRequest request) { final cachedJson = _lemmaStorage.read(request.storageKey); final cached = @@ -32,16 +32,17 @@ class LemmaInfoRepo { if (cached != null) { if (DateTime.now().isBefore(cached.expireAt!)) { - // return cache as is if we're using expireAt and it's set but not expired - // debugPrint( - // 'using cached data for ${request.lemma} ${cached.toJson()}', - // ); return cached; } else { - // if it's expired, remove it _lemmaStorage.remove(request.storageKey); } } + return null; + } + + static Future _fetch(LemmaInfoRequest request) async { + final cached = getCached(request); + if (cached != null) return cached; final Requests req = Requests( choreoApiKey: Environment.choreoApiKey,