fix: show date on memories page (#32245)
fix: show date on memories page (#32206) * fix: show date on memories page * Clean up API * Drop imports --------- (cherry picked from commit 108a3cadbfe3b3e4305c04d8e4217aafb445f626) Co-authored-by: Alex <alex.tran1502@gmail.com> Co-authored-by: Adam Gastineau <adam@agg.im>
This commit is contained in:
co-authored by
Alex
Adam Gastineau
parent
5b2a3a52be
commit
f6fc530734
@@ -79,6 +79,7 @@ class _MemoryListPageState extends ConsumerState<MemoryListPage> {
|
||||
child: MemoryTitle(
|
||||
memory: memories[index],
|
||||
style: const TextStyle(fontWeight: FontWeight.w600, color: Colors.white, fontSize: 15),
|
||||
preferDate: true,
|
||||
),
|
||||
),
|
||||
if (memories[index].isSaved)
|
||||
|
||||
@@ -3,12 +3,17 @@ import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||
import 'package:immich_mobile/domain/models/memory.model.dart';
|
||||
import 'package:immich_mobile/extensions/object_extensions.dart';
|
||||
import 'package:immich_mobile/generated/translations.g.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// [asset] adds the age at that asset to birthday titles
|
||||
String getMemoryTitle(Translations t, Memory memory, {RemoteAsset? asset}) => switch (memory.type) {
|
||||
MemoryTypeEnum.onThisDay => t.years_ago(years: DateTime.now().year - memory.data.year),
|
||||
MemoryTypeEnum.birthday => _getBirthdayTitle(t, memory.data, asset),
|
||||
};
|
||||
String getMemoryTitle(Translations t, Memory memory, {RemoteAsset? asset, bool preferDate = false}) =>
|
||||
switch (memory.type) {
|
||||
MemoryTypeEnum.onThisDay =>
|
||||
preferDate
|
||||
? DateFormat.yMMMMd().format(memory.memoryAt)
|
||||
: t.years_ago(years: DateTime.now().year - memory.data.year),
|
||||
MemoryTypeEnum.birthday => _getBirthdayTitle(t, memory.data, asset),
|
||||
};
|
||||
|
||||
String _getBirthdayTitle(Translations t, MemoryData data, RemoteAsset? asset) {
|
||||
final name = data.personName;
|
||||
@@ -28,11 +33,14 @@ class MemoryTitle extends StatelessWidget {
|
||||
final Memory memory;
|
||||
final TextStyle? style;
|
||||
|
||||
const MemoryTitle({super.key, required this.memory, this.style});
|
||||
/// If true, the title will prefer to display a full date, if that is an option (onThisDay)
|
||||
final bool preferDate;
|
||||
|
||||
const MemoryTitle({super.key, required this.memory, this.style, this.preferDate = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final title = getMemoryTitle(context.t, memory);
|
||||
final title = getMemoryTitle(context.t, memory, preferDate: preferDate);
|
||||
if (memory.type != MemoryTypeEnum.birthday) {
|
||||
return Text(title, style: style);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:immich_mobile/domain/models/memory.model.dart';
|
||||
import 'package:immich_mobile/presentation/pages/memory_list.page.dart';
|
||||
import 'package:immich_mobile/providers/infrastructure/memory.provider.dart';
|
||||
|
||||
import '../factories/remote_asset_factory.dart';
|
||||
import 'presentation_context.dart';
|
||||
|
||||
void main() {
|
||||
late PresentationContext context;
|
||||
|
||||
setUp(() async => context = await PresentationContext.create());
|
||||
tearDown(() async => await context.dispose());
|
||||
|
||||
Memory newMemory({required MemoryTypeEnum type, required DateTime memoryAt, String? personName}) => Memory(
|
||||
id: 'memory-${memoryAt.toIso8601String()}',
|
||||
createdAt: DateTime(2026),
|
||||
updatedAt: DateTime(2026),
|
||||
ownerId: 'user-1',
|
||||
type: type,
|
||||
data: MemoryData(year: memoryAt.year, personName: personName),
|
||||
isSaved: false,
|
||||
memoryAt: memoryAt,
|
||||
assets: [RemoteAssetFactory.create()],
|
||||
);
|
||||
|
||||
Future<void> pumpPage(WidgetTester tester, List<Memory> memories) => tester.pumpTestWidget(
|
||||
context,
|
||||
const MemoryListPage(),
|
||||
overrides: [allMemoriesProvider(false).overrideWith((ref) => memories)],
|
||||
expectSettle: false,
|
||||
);
|
||||
|
||||
group('MemoryListPage', () {
|
||||
testWidgets('shows the date of each on this day memory', (tester) async {
|
||||
await pumpPage(tester, [
|
||||
newMemory(type: MemoryTypeEnum.onThisDay, memoryAt: DateTime(2025, 10, 7)),
|
||||
newMemory(type: MemoryTypeEnum.onThisDay, memoryAt: DateTime(2025, 10, 6)),
|
||||
]);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('October 7, 2025'), findsOneWidget);
|
||||
expect(find.text('October 6, 2025'), findsOneWidget);
|
||||
expect(find.textContaining('ago'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('shows the person name for a birthday memory', (tester) async {
|
||||
await pumpPage(tester, [
|
||||
newMemory(type: MemoryTypeEnum.birthday, memoryAt: DateTime(2025, 10, 7), personName: 'Alice'),
|
||||
]);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text("Alice's birthday"), findsOneWidget);
|
||||
expect(find.text('October 7, 2025'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user