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
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.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/utils/form_validators.dart';
import 'package:lensai/utils/uri_parser.dart' as uri_parser;
class AddFeedDialog extends HookConsumerWidget {
final Uri? initialUri;
const AddFeedDialog({super.key, required this.initialUri});
@override
Widget build(BuildContext context, WidgetRef ref) {
final formKey = useMemoized(() => GlobalKey<FormState>());
final textController = useTextEditingController(
text: initialUri?.toString(),
);
return AlertDialog(
title: const Text('Add Feed'),
// contentPadding: const EdgeInsets.fromLTRB(24.0, 12.0, 24.0, 16.0),
content: Form(
key: formKey,
child: TextFormField(
decoration: const InputDecoration(
label: Text('URL'),
hintText: 'https://example.com/feed',
floatingLabelBehavior: FloatingLabelBehavior.always,
),
controller: textController,
keyboardType: TextInputType.url,
validator: (value) {
return validateUrl(value, onlyHttpProtocol: true);
},
),
),
actions: [
TextButton(
onPressed: () {
context.pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
if (formKey.currentState?.validate() == true) {
FeedCreateRoute(
feedId: uri_parser.tryParseUrl(textController.text)!,
).pushReplacement(context);
}
},
child: const Text('Add'),
),
],
);
}
}
@@ -2,7 +2,6 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/core/providers/format.dart';
import 'package:lensai/core/routing/routes.dart';
@@ -10,6 +9,7 @@ import 'package:lensai/extensions/nullable.dart';
import 'package:lensai/features/geckoview/domain/repositories/tab.dart';
import 'package:lensai/features/web_feed/data/models/feed_link.dart';
import 'package:lensai/features/web_feed/domain/providers.dart';
import 'package:lensai/features/web_feed/extensions/atom.dart';
import 'package:lensai/features/web_feed/extensions/feed_article.dart';
import 'package:lensai/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
import 'package:lensai/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
@@ -26,13 +26,16 @@ class FeedArticleScreen extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final articleAsync = ref.watch(feedArticleProvider(articleId));
final articleAsync = ref.watch(
feedArticleProvider(articleId, updateReadDate: true),
);
return Scaffold(
body: articleAsync.when(
skipLoadingOnReload: true,
data: (article) {
if (article == null) {
return SizedBox.shrink();
return const SizedBox.shrink();
}
return HookBuilder(
@@ -55,9 +58,7 @@ class FeedArticleScreen extends HookConsumerWidget {
);
final articleLink = useMemoized(
() => article.links?.firstWhereOrNull(
(link) => link.relation == FeedLinkRelation.alternate,
),
() => article.links?.getRelation(FeedLinkRelation.alternate),
);
final articleImages = useMemoized(
@@ -176,7 +177,7 @@ class FeedArticleScreen extends HookConsumerWidget {
.addTab(url: articleLink.uri);
if (context.mounted) {
context.go(BrowserRoute().location);
BrowserRoute().go(context);
}
},
icon: const Icon(Icons.open_in_browser),
@@ -218,7 +219,7 @@ class FeedArticleScreen extends HookConsumerWidget {
context,
tabName: title.whenNotEmpty,
onShow: () {
context.go(BrowserRoute().location);
BrowserRoute().go(context);
},
);
}
@@ -1,14 +1,15 @@
import 'package:fast_equatable/fast_equatable.dart';
import 'package:fading_scroll/fading_scroll.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/extensions/nullable.dart';
import 'package:lensai/features/web_feed/data/models/feed_filter.dart';
import 'package:lensai/features/web_feed/domain/providers.dart';
import 'package:lensai/features/web_feed/domain/providers/article_filter.dart';
import 'package:lensai/features/web_feed/presentation/controllers/fetch_articles.dart';
import 'package:lensai/features/web_feed/presentation/widgets/feed_article_card.dart';
import 'package:lensai/presentation/hooks/listenable_callback.dart';
import 'package:lensai/presentation/widgets/failure_widget.dart';
import 'package:lensai/presentation/widgets/speech_to_text_button.dart';
class FeedArticleListScreen extends HookConsumerWidget {
final Uri? feedId;
@@ -17,82 +18,170 @@ class FeedArticleListScreen extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final articlesAsync = ref.watch(
// ignore: provider_parameters
feedArticleListProvider(FeedFilter(feedId: feedId)),
);
return Scaffold(
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
Consumer(
HookConsumer(
builder: (context, ref, child) {
final tags = ref.watch(articleFilterProvider);
final feedTitle = ref.watch(
feedDataProvider(
feedId,
).select((value) => value.valueOrNull?.title.whenNotEmpty),
);
return SliverAppBar(floating: true, title: Text('Articles'));
final searchTextController = useTextEditingController();
final hasText = useListenableSelector(
searchTextController,
() => searchTextController.text.isNotEmpty,
);
useListenableCallback(searchTextController, () {
ref
.read(filteredArticleListProvider(feedId).notifier)
.search(searchTextController.text);
});
final bottomHeight = useMemoized(() {
var height = 56.0 + 4.0;
if (tags.isNotEmpty) {
height += 48;
}
return height;
}, [tags.isNotEmpty]);
return SliverAppBar(
floating: true,
title: Text(feedTitle ?? 'Articles'),
bottom: PreferredSize(
preferredSize: Size(double.infinity, bottomHeight),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: [
TextField(
controller: searchTextController,
decoration: InputDecoration(
label: const Text('Search'),
suffixIcon:
hasText
? IconButton(
onPressed: () {
searchTextController.clear();
},
icon: const Icon(Icons.clear),
)
: SpeechToTextButton(
onTextReceived: (data) {
searchTextController.text =
data.toString();
},
),
),
),
const SizedBox(height: 4),
if (tags.isNotEmpty)
SizedBox(
width: double.infinity,
height: 48,
child: FadingScroll(
fadingSize: 15,
builder: (context, controller) {
return ListView(
controller: controller,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children:
tags
.map(
(tag) => Padding(
padding: const EdgeInsets.only(
right: 8.0,
),
child: FilterChip(
label: Text(tag),
showCheckmark: false,
selected: true,
onSelected: (value) {},
onDeleted: () {
ref
.read(
articleFilterProvider
.notifier,
)
.removeTag(tag);
},
),
),
)
.toList(),
);
},
),
),
],
),
),
),
);
},
),
];
},
body: articlesAsync.when(
data: (articles) {
return RefreshIndicator(
onRefresh: () async {
if (feedId != null) {
await ref
.read(fetchArticlesControllerProvider.notifier)
.fetchFeedArticles(feedId!);
} else {
await ref
.read(fetchArticlesControllerProvider.notifier)
.fetchAllArticles();
}
body: Consumer(
builder: (context, ref, child) {
final articlesAsync = ref.watch(
// ignore: provider_parameters
filteredArticleListProvider(feedId),
);
return articlesAsync.when(
skipLoadingOnReload: true,
data: (articles) {
return RefreshIndicator(
onRefresh: () async {
if (feedId != null) {
await ref
.read(fetchArticlesControllerProvider.notifier)
.fetchFeedArticles(feedId!);
} else {
await ref
.read(fetchArticlesControllerProvider.notifier)
.fetchAllArticles();
}
},
child: MediaQuery.removePadding(
removeTop: true,
context: context,
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: articles.length,
itemBuilder: (context, i) {
final article = articles[i];
return FeedArticleCard(
key: ValueKey(article.id),
article: article,
);
},
),
),
);
},
child: ListView.builder(
itemCount: articles.length,
itemBuilder: (context, i) {
final article = articles[i];
return Consumer(
key: ValueKey(article.id),
builder: (context, ref, child) {
final tags = ref.watch(
articleFilterProvider.select(
(value) => EquatableValue(value.tags ?? const {}),
),
);
return FeedArticleCard(
selectedTags: tags.value,
onTagSelected: (tagId, value) {
if (value) {
ref
.read(articleFilterProvider.notifier)
.addTag(tagId);
} else {
ref
.read(articleFilterProvider.notifier)
.removeTag(tagId);
}
},
article: article,
);
},
);
},
),
error:
(error, stackTrace) => Center(
child: FailureWidget(
title: 'Failed to load Articles',
exception: error,
),
),
loading: () => const SizedBox.shrink(),
);
},
error:
(error, stackTrace) => Center(
child: FailureWidget(
title: 'Failed to load Articles',
exception: error,
),
),
loading: () => const SizedBox.shrink(),
),
),
);
@@ -1,33 +1,109 @@
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:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/extensions/nullable.dart';
import 'package:lensai/extensions/uri.dart';
import 'package:lensai/features/web_feed/data/database/database.dart';
import 'package:lensai/features/web_feed/data/models/feed_category.dart';
import 'package:lensai/features/web_feed/domain/providers.dart';
import 'package:lensai/features/web_feed/domain/repositories/feed_repository.dart';
import 'package:lensai/features/web_feed/presentation/widgets/tag_field.dart';
import 'package:lensai/presentation/widgets/failure_widget.dart';
import 'package:lensai/presentation/widgets/url_icon.dart';
import 'package:lensai/utils/form_validators.dart';
import 'package:lensai/utils/uri_parser.dart' as uri_parser;
enum _DialogMode { create, edit }
class FeedEditScreen extends HookConsumerWidget {
final _DialogMode _mode;
final FeedData initialFeed;
final Uri feedId;
const FeedEditScreen._({required _DialogMode mode, required this.initialFeed})
const FeedEditScreen._({required _DialogMode mode, required this.feedId})
: _mode = mode;
factory FeedEditScreen.create({required FeedData initialFeed}) {
return FeedEditScreen._(mode: _DialogMode.create, initialFeed: initialFeed);
factory FeedEditScreen.create({required Uri feedId}) {
return FeedEditScreen._(mode: _DialogMode.create, feedId: feedId);
}
factory FeedEditScreen.edit({required FeedData initialFeed}) {
return FeedEditScreen._(mode: _DialogMode.edit, initialFeed: initialFeed);
factory FeedEditScreen.edit({required Uri feedId}) {
return FeedEditScreen._(mode: _DialogMode.edit, feedId: feedId);
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final initialFeedAsync = switch (_mode) {
_DialogMode.create => ref.watch(
fetchWebFeedProvider(
feedId,
).select((value) => value.whenData((result) => result.feedData)),
),
_DialogMode.edit => ref.watch(feedDataProvider(feedId)),
};
return initialFeedAsync.when(
skipLoadingOnReload: true,
data: (initialFeed) {
if (initialFeed == null) {
return Scaffold(
key: const ValueKey('data'),
appBar: AppBar(),
body: const Center(
child: FailureWidget(title: 'Failed to load feed'),
),
);
}
return _FeedEditContent(mode: _mode, initialFeed: initialFeed);
},
error:
(error, stackTrace) => Scaffold(
key: const ValueKey('error'),
appBar: AppBar(),
body: Center(
child: FailureWidget(
title: 'Failed to load feed',
exception: error,
),
),
),
loading:
() => Scaffold(
key: const ValueKey('loading'),
appBar: AppBar(
title: Text(switch (_mode) {
_DialogMode.create => 'New Feed',
_DialogMode.edit => 'Edit Feed',
}),
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
Padding(
padding: EdgeInsets.only(top: 8.0),
child: Text('Fetching feed...'),
),
],
),
),
),
);
}
}
class _FeedEditContent extends HookConsumerWidget {
final _DialogMode _mode;
final FeedData initialFeed;
const _FeedEditContent({required _DialogMode mode, required this.initialFeed})
: _mode = mode;
@override
Widget build(BuildContext context, WidgetRef ref) {
final formKey = useMemoized(() => GlobalKey<FormState>());
@@ -45,6 +121,12 @@ class FeedEditScreen extends HookConsumerWidget {
final urlTextController = useTextEditingController(
text: initialFeed.url.toString(),
);
final iconUrlTextController = useTextEditingController(
text: initialFeed.icon?.toString(),
);
final siteLinkTextController = useTextEditingController(
text: initialFeed.siteLink?.toString(),
);
return Scaffold(
appBar: AppBar(
@@ -57,9 +139,21 @@ class FeedEditScreen extends HookConsumerWidget {
onPressed: () async {
if (formKey.currentState?.validate() ?? false) {
final feedData = FeedData(
url: Uri.parse(urlTextController.text),
url:
uri_parser.tryParseUrl(
urlTextController.text,
eagerParsing: true,
)!,
authors: initialFeed.authors,
description: descriptionTextController.text.whenNotEmpty,
icon: uri_parser.tryParseUrl(
iconUrlTextController.text,
eagerParsing: true,
),
siteLink: uri_parser.tryParseUrl(
siteLinkTextController.text,
eagerParsing: true,
),
tags: tags.value.map((tag) => FeedCategory(id: tag)).toList(),
title: titleTextController.text.whenNotEmpty,
);
@@ -91,10 +185,11 @@ class FeedEditScreen extends HookConsumerWidget {
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.all(10.0),
child: UrlIcon(
initialFeed.url.base,
iconSize: 24.0,
),
child: UrlIcon([
initialFeed.icon ??
initialFeed.siteLink ??
initialFeed.url.base,
], iconSize: 24.0),
),
label: const Text('Title'),
),
@@ -103,40 +198,63 @@ class FeedEditScreen extends HookConsumerWidget {
TextFormField(
decoration: const InputDecoration(
label: Text('Description'),
prefixIcon: Icon(Icons.short_text),
),
minLines: 1,
maxLines: 3,
controller: descriptionTextController,
),
const SizedBox(height: 16),
const SizedBox(height: 32),
TextFormField(
decoration: const InputDecoration(
label: Text('Icon URL'),
prefixIcon: Icon(Icons.image),
),
keyboardType: TextInputType.url,
controller: iconUrlTextController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
required: false,
);
},
),
TextFormField(
decoration: const InputDecoration(
label: Text('Site Link'),
prefixIcon: Icon(Icons.link),
),
keyboardType: TextInputType.url,
controller: siteLinkTextController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
required: false,
);
},
),
const SizedBox(height: 32),
TagField(
initialTags: tags.value,
onTagsUpdate: (newTags) {
tags.value = newTags;
},
),
const SizedBox(height: 16),
const SizedBox(height: 32),
TextFormField(
decoration: const InputDecoration(
label: Text('Address'),
label: Text('Feed URL'),
prefixIcon: Icon(MdiIcons.rss),
),
keyboardType: TextInputType.url,
controller: urlTextController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value.isEmpty) {
return 'Address must be provided';
}
if (Uri.tryParse(value!) case final Uri url) {
if (url.isScheme('https') ||
url.isScheme('http') &&
url.authority.isNotEmpty) {
return null;
}
}
return 'Inavlid URL';
return validateUrl(value, onlyHttpProtocol: true);
},
),
],
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/core/routing/routes.dart';
import 'package:lensai/features/web_feed/domain/providers.dart';
import 'package:lensai/features/web_feed/presentation/controllers/fetch_articles.dart';
import 'package:lensai/features/web_feed/presentation/widgets/feed_card.dart';
@@ -15,6 +16,7 @@ class FeedListScreen extends HookConsumerWidget {
return Scaffold(
appBar: AppBar(title: const Text('Feeds')),
body: feeds.when(
skipLoadingOnReload: true,
data: (feeds) {
return RefreshIndicator(
onRefresh: () async {
@@ -35,10 +37,21 @@ class FeedListScreen extends HookConsumerWidget {
child: FailureWidget(
title: 'Failed to load Feeds',
exception: error,
onRetry: () {
// ignore: unused_result
ref.refresh(feedListProvider);
},
),
),
loading: () => const SizedBox.shrink(),
),
floatingActionButton: FloatingActionButton.extended(
label: const Text('Feed'),
icon: const Icon(Icons.add),
onPressed: () async {
await const FeedAddRoute().push(context);
},
),
);
}
}
@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:lensai/core/routing/routes.dart';
import 'package:lensai/extensions/nullable.dart';
import 'package:lensai/features/web_feed/domain/providers.dart';
import 'package:lensai/presentation/widgets/failure_widget.dart';
import 'package:skeletonizer/skeletonizer.dart';
class SelectFeedDialog extends HookConsumerWidget {
final Set<Uri> feedUris;
const SelectFeedDialog({required this.feedUris});
@override
Widget build(BuildContext context, WidgetRef ref) {
return SimpleDialog(
title: const Text('Add Feed'),
children:
feedUris
.map(
(uri) => HookConsumer(
builder: (context, ref, child) {
final feedAsync = ref.watch(fetchWebFeedProvider(uri));
return feedAsync.when(
data: (data) {
return ListTile(
title: Text(
data.feedData.title.whenNotEmpty ?? 'Unnamed Feed',
),
subtitle: Text(uri.toString()),
trailing: const Icon(Icons.add),
onTap: () {
FeedCreateRoute(
feedId: uri,
).pushReplacement(context);
},
);
},
error:
(error, stackTrace) => FailureWidget(
title: 'Failed to fetch Feed',
exception: error,
onRetry: () {
// ignore: unused_result
ref.refresh(fetchWebFeedProvider(uri));
},
),
loading:
() => Skeletonizer(
child: ListTile(
title: Text(BoneMock.title),
subtitle: Skeleton.keep(
child: Text(uri.toString()),
),
),
),
);
},
),
)
.toList(),
);
}
}
@@ -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],
);