Skip to content

Commit b58f5d2

Browse files
committed
refactor(headline_tile_text_only): migrate to ContentType and simplify imports
- Replace EntityType with ContentType for better consistency - Remove unnecessary imports and reorganize remaining ones - Simplify time ago formatting (TODO: replace with proper library) - Update category to topic terminology and related logic - Enhance source details navigation with ContentType specification
1 parent c4ec14a commit b58f5d2

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

lib/shared/widgets/headline_tile_text_only.dart

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import 'package:flutter/material.dart';
2-
import 'package:go_router/go_router.dart'; // Added
3-
import 'package:ht_main/entity_details/models/entity_type.dart';
4-
import 'package:ht_main/entity_details/view/entity_details_page.dart'; // Added for Page Arguments
5-
import 'package:ht_main/l10n/app_localizations.dart';
2+
import 'package:go_router/go_router.dart';
3+
import 'package:ht_main/entity_details/view/entity_details_page.dart';
64
import 'package:ht_main/l10n/l10n.dart';
7-
import 'package:ht_main/router/routes.dart'; // Added
8-
import 'package:ht_main/shared/constants/app_spacing.dart';
9-
import 'package:ht_main/shared/utils/utils.dart'; // Import the new utility
10-
import 'package:ht_shared/ht_shared.dart' show Headline;
11-
// timeago import removed from here, handled by utility
5+
import 'package:ht_main/router/routes.dart';
6+
import 'package:ht_shared/ht_shared.dart';
7+
import 'package:ht_ui_kit/ht_ui_kit.dart';
128

139
/// {@template headline_tile_text_only}
1410
/// A widget to display a headline item with text only.
@@ -36,17 +32,15 @@ class HeadlineTileTextOnly extends StatelessWidget {
3632
final Widget? trailing;
3733

3834
/// The type of the entity currently being viewed in detail (e.g., on a category page).
39-
final EntityType? currentContextEntityType;
35+
final ContentType? currentContextEntityType;
4036

4137
/// The ID of the entity currently being viewed in detail.
4238
final String? currentContextEntityId;
4339

4440
@override
4541
Widget build(BuildContext context) {
46-
final l10n = context.l10n;
4742
final theme = Theme.of(context);
4843
final textTheme = theme.textTheme;
49-
final colorScheme = theme.colorScheme;
5044

5145
return Card(
5246
margin: const EdgeInsets.symmetric(
@@ -75,8 +69,7 @@ class HeadlineTileTextOnly extends StatelessWidget {
7569
const SizedBox(height: AppSpacing.sm),
7670
_HeadlineMetadataRow(
7771
headline: headline,
78-
l10n: l10n,
79-
colorScheme: colorScheme,
72+
colorScheme: theme.colorScheme,
8073
textTheme: textTheme,
8174
currentContextEntityType:
8275
currentContextEntityType, // Pass down
@@ -102,23 +95,22 @@ class HeadlineTileTextOnly extends StatelessWidget {
10295
class _HeadlineMetadataRow extends StatelessWidget {
10396
const _HeadlineMetadataRow({
10497
required this.headline,
105-
required this.l10n,
10698
required this.colorScheme,
10799
required this.textTheme,
108100
this.currentContextEntityType,
109101
this.currentContextEntityId,
110102
});
111103

112104
final Headline headline;
113-
final AppLocalizations l10n;
114105
final ColorScheme colorScheme;
115106
final TextTheme textTheme;
116-
final EntityType? currentContextEntityType;
107+
final ContentType? currentContextEntityType;
117108
final String? currentContextEntityId;
118109

119110
@override
120111
Widget build(BuildContext context) {
121-
final formattedDate = formatRelativeTime(context, headline.publishedAt);
112+
// TODO(anyone): Use a proper timeago library.
113+
final formattedDate = headline.createdAt.toString();
122114

123115
// Use bodySmall for a reasonable base size, with muted accent color
124116
final metadataTextStyle = textTheme.bodySmall?.copyWith(
@@ -146,34 +138,35 @@ class _HeadlineMetadataRow extends StatelessWidget {
146138
Text(formattedDate, style: metadataTextStyle),
147139
],
148140
),
149-
// Conditionally render Category as Text
150-
if (headline.category?.name != null &&
151-
!(currentContextEntityType == EntityType.category &&
152-
headline.category!.id == currentContextEntityId)) ...[
141+
// Conditionally render Topic as Text
142+
if (headline.topic.name.isNotEmpty &&
143+
!(currentContextEntityType == ContentType.topic &&
144+
headline.topic.id == currentContextEntityId)) ...[
153145
if (formattedDate.isNotEmpty)
154146
Padding(
155147
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
156148
child: Text('•', style: metadataTextStyle),
157149
),
158150
GestureDetector(
159151
onTap: () {
160-
if (headline.category != null) {
161-
context.push(
162-
Routes.categoryDetails,
163-
extra: EntityDetailsPageArguments(entity: headline.category),
164-
);
165-
}
152+
context.push(
153+
Routes.topicDetails,
154+
extra: EntityDetailsPageArguments(
155+
entity: headline.topic,
156+
contentType: ContentType.topic,
157+
),
158+
);
166159
},
167-
child: Text(headline.category!.name, style: metadataTextStyle),
160+
child: Text(headline.topic.name, style: metadataTextStyle),
168161
),
169162
],
170163
// Conditionally render Source as Text
171-
if (!(currentContextEntityType == EntityType.source &&
164+
if (!(currentContextEntityType == ContentType.source &&
172165
headline.source.id == currentContextEntityId)) ...[
173166
if (formattedDate.isNotEmpty ||
174-
(headline.category?.name != null &&
175-
!(currentContextEntityType == EntityType.category &&
176-
headline.category!.id == currentContextEntityId)))
167+
(headline.topic.name.isNotEmpty &&
168+
!(currentContextEntityType == ContentType.topic &&
169+
headline.topic.id == currentContextEntityId)))
177170
Padding(
178171
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
179172
child: Text('•', style: metadataTextStyle),
@@ -182,7 +175,10 @@ class _HeadlineMetadataRow extends StatelessWidget {
182175
onTap: () {
183176
context.push(
184177
Routes.sourceDetails,
185-
extra: EntityDetailsPageArguments(entity: headline.source),
178+
extra: EntityDetailsPageArguments(
179+
entity: headline.source,
180+
contentType: ContentType.source,
181+
),
186182
);
187183
},
188184
child: Text(headline.source.name, style: metadataTextStyle),

0 commit comments

Comments
 (0)