chore: if emoji info is cached, show first emoji in vocab analytics if user hasn't assigned an emoji (#3805)

This commit is contained in:
ggurdin 2025-08-25 17:04:35 -04:00 committed by GitHub
parent be771abff1
commit b5650b1bca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 32 deletions

View file

@ -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<VocabAnalyticsListTile> {
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,

View file

@ -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,
);
},
),

View file

@ -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<LemmaInfoResponse> getLemmaInfo([
Future<LemmaInfoResponse> 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 =>

View file

@ -24,7 +24,7 @@ class LemmaInfoRepo {
_lemmaStorage.write(request.storageKey, response.toJson());
}
static Future<LemmaInfoResponse> _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<LemmaInfoResponse> _fetch(LemmaInfoRequest request) async {
final cached = getCached(request);
if (cached != null) return cached;
final Requests req = Requests(
choreoApiKey: Environment.choreoApiKey,