major update
This commit is contained in:
@@ -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);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user