major update

This commit is contained in:
Fabian Freund
2025-03-03 15:15:05 +01:00
parent 200c82a442
commit 20bdc4df3e
103 changed files with 2664 additions and 783 deletions
@@ -6,18 +6,31 @@ import 'package:lensai/features/web_feed/data/models/feed_author.dart';
class AuthorsHorizontalList extends StatelessWidget {
late final List<Widget> _authors;
AuthorsHorizontalList({required List<FeedAuthor> authors}) {
AuthorsHorizontalList({
required List<FeedAuthor> authors,
Set<String> selectedTags = const {},
void Function(String tagId, bool value)? onTagSelected,
}) {
_authors =
authors
.map(
(author) => Chip(
label: Text(
'${author.name ?? ''} ${author.email.mapNotNull((email) => '($email)') ?? ''}'
.trim(),
authors.map((author) {
final label = Text(
'${author.name ?? ''} ${author.email.mapNotNull((email) => '($email)') ?? ''}'
.trim(),
);
return onTagSelected.mapNotNull(
(onTagSelected) => FilterChip(
label: label,
selected: selectedTags.contains(author.name),
onSelected: (value) {
if (author.name.isNotEmpty) {
onTagSelected(author.name!, value);
}
},
),
),
)
.toList();
) ??
Chip(label: label);
}).toList();
}
@override
@@ -30,7 +43,6 @@ class AuthorsHorizontalList extends StatelessWidget {
return ListView.builder(
itemCount: _authors.length,
controller: controller,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => _authors[index],
);
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/core/routing/routes.dart';
import 'package:lensai/extensions/nullable.dart';
import 'package:lensai/extensions/uri.dart';
import 'package:lensai/features/web_feed/data/models/feed_article.dart';
import 'package:lensai/features/web_feed/data/models/feed_article_query_result.dart';
import 'package:lensai/features/web_feed/domain/providers/article_filter.dart';
import 'package:lensai/features/web_feed/domain/repositories/feed_repository.dart';
import 'package:lensai/features/web_feed/extensions/feed_article.dart';
import 'package:lensai/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
@@ -15,34 +17,31 @@ import 'package:timeago/timeago.dart' as timeago;
class FeedArticleCard extends HookConsumerWidget {
final FeedArticle article;
final Set<String> selectedTags;
final void Function(String tagId, bool value)? onTagSelected;
const FeedArticleCard({
super.key,
required this.article,
this.onTagSelected,
this.selectedTags = const {},
});
const FeedArticleCard({super.key, required this.article});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final tags = ref.watch(articleFilterProvider);
final titleHighlight = switch (article) {
final FeedArticleQueryResult result => result.titleHighlight.whenNotEmpty,
_ => null,
};
final searchSnippet = switch (article) {
final FeedArticleQueryResult result =>
result.summarySnippet.whenNotEmpty ??
result.contentSnippet.whenNotEmpty,
_ => null,
};
return Card(
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
await ref
.read(feedRepositoryProvider.notifier)
.touchArticleRead(article.id);
if (context.mounted) {
await context.push(
FeedArticleRoute(articleId: article.id).location,
extra: article,
);
}
await FeedArticleRoute(articleId: article.id).push(context);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
@@ -52,17 +51,55 @@ class FeedArticleCard extends HookConsumerWidget {
children: [
Row(
children: [
UrlIcon(article.feedId.base, iconSize: 34.0),
UrlIcon([
article.icon ?? article.feedId.base,
], iconSize: 34.0),
const SizedBox(width: 12.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
article.displayTitle,
style: theme.textTheme.titleMedium,
),
if (article.summaryPlain != null)
if (titleHighlight.isNotEmpty)
MarkdownBody(
data: titleHighlight!,
styleSheet: MarkdownStyleSheet(
p: Theme.of(
context,
).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
),
),
if (titleHighlight.isEmpty)
Text(
article.displayTitle,
style: theme.textTheme.titleMedium,
),
if (searchSnippet.isNotEmpty)
MarkdownBody(
data: searchSnippet!,
styleSheet: MarkdownStyleSheet(
p: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(
color:
Theme.of(
context,
).colorScheme.onSurfaceVariant,
),
a: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(
color:
Theme.of(
context,
).colorScheme.onSurfaceVariant,
decoration: TextDecoration.none,
),
),
),
if (searchSnippet.isEmpty &&
article.summaryPlain != null)
Text(
article.summaryPlain!,
style: theme.textTheme.bodySmall,
@@ -86,15 +123,35 @@ class FeedArticleCard extends HookConsumerWidget {
if (article.authors.isNotEmpty || article.tags.isNotEmpty) ...[
const SizedBox(height: 8),
if (article.authors.isNotEmpty)
AuthorsHorizontalList(authors: article.authors!),
AuthorsHorizontalList(
authors: article.authors!,
selectedTags: tags,
onTagSelected: (tagId, value) {
if (value) {
ref.read(articleFilterProvider.notifier).addTag(tagId);
} else {
ref
.read(articleFilterProvider.notifier)
.removeTag(tagId);
}
},
),
if (article.tags.isNotEmpty)
TagsHorizontalList(
tags: article.tags!,
selectedTags: selectedTags,
onTagSelected: onTagSelected,
selectedTags: tags,
onTagSelected: (tagId, value) {
if (value) {
ref.read(articleFilterProvider.notifier).addTag(tagId);
} else {
ref
.read(articleFilterProvider.notifier)
.removeTag(tagId);
}
},
),
const Divider(),
],
const Divider(),
Row(
children: [
Text(
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/core/routing/routes.dart';
import 'package:lensai/extensions/nullable.dart';
@@ -26,7 +25,7 @@ class FeedCard extends HookConsumerWidget {
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
await context.push(FeedArticleListRoute(feedId: feed.url).location);
await FeedArticleListRoute(feedId: feed.url).push(context);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
@@ -36,7 +35,9 @@ class FeedCard extends HookConsumerWidget {
children: [
Row(
children: [
UrlIcon(feed.url.base, iconSize: 34.0),
UrlIcon([
feed.icon ?? feed.siteLink ?? feed.url.base,
], iconSize: 34.0),
const SizedBox(width: 12.0),
Expanded(
child: Column(
@@ -56,6 +57,12 @@ class FeedCard extends HookConsumerWidget {
],
),
),
IconButton(
onPressed: () async {
await FeedEditRoute(feedId: feed.url).push(context);
},
icon: const Icon(Icons.edit),
),
],
),
if (feed.authors.isNotEmpty || feed.tags.isNotEmpty) ...[
@@ -89,6 +96,7 @@ class FeedCard extends HookConsumerWidget {
);
return countAsync.when(
skipLoadingOnReload: true,
data: (count) {
if (count == null) {
return const SizedBox();
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:lensai/presentation/hooks/listenable_callback.dart';
final _tagSplitPatter = RegExp(r'[,\s]+');
@@ -45,9 +46,8 @@ class TagField extends HookWidget {
TextField(
controller: textController,
decoration: const InputDecoration(
label: Text('Add'),
floatingLabelBehavior: FloatingLabelBehavior.always,
hintText: 'tag1, tag2, ...',
prefixIcon: Icon(MdiIcons.tagMultiple),
),
onChanged: (String value) {
if (value.isNotEmpty) {
@@ -12,25 +12,27 @@ class TagsHorizontalList extends StatelessWidget {
void Function(String tagId, bool value)? onTagSelected,
}) {
_tags =
tags
.map(
(tag) => Padding(
padding: const EdgeInsets.only(right: 8.0),
child: FilterChip(
label: Text(
'${tag.id} ${tag.title.mapNotNull((title) => '($title)') ?? ''}'
.trim(),
),
selected: selectedTags.contains(tag.id),
onSelected: onTagSelected.mapNotNull(
(onTagSelected) => (value) {
tags.map((tag) {
final label = Text(
'${tag.id} ${tag.title.mapNotNull((title) => '($title)') ?? ''}'
.trim(),
);
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child:
onTagSelected.mapNotNull(
(onTagSelected) => FilterChip(
label: label,
selected: selectedTags.contains(tag.id),
onSelected: (value) {
onTagSelected(tag.id, value);
},
),
),
),
)
.toList();
) ??
Chip(label: label),
);
}).toList();
}
@override
@@ -43,7 +45,8 @@ class TagsHorizontalList extends StatelessWidget {
return ListView.builder(
itemCount: _tags.length,
controller: controller,
shrinkWrap: true,
//Improve list performance by not rendering outside screen at all
cacheExtent: 0,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => _tags[index],
);