Skip to content

Commit 2edfa72

Browse files
committed
better feed fetching
1 parent 2bfb3fd commit 2edfa72

File tree

3 files changed

+126
-49
lines changed

3 files changed

+126
-49
lines changed

app/lib/presentation/controllers/website_title.dart

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* You should have received a copy of the GNU Affero General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20+
import 'package:fast_equatable/fast_equatable.dart';
2021
import 'package:nullability/nullability.dart';
2122
import 'package:riverpod/riverpod.dart';
2223
import 'package:riverpod_annotation/riverpod_annotation.dart';
@@ -46,34 +47,6 @@ class CompletePageInfo extends _$CompletePageInfo {
4647
return AsyncData(cached);
4748
}
4849

49-
// ref.listen(
50-
// fireImmediately: true,
51-
// pageInfoProvider(cached.url, isImageRequest: false),
52-
// (previous, next) {
53-
// if (next.hasValue) {
54-
// final current = stateOrNull?.value ?? cached;
55-
56-
// state = AsyncData(
57-
// current.copyWith(
58-
// //Cached is preferred as this comes from gecko and is more likely to be correct compared to manual request
59-
// favicon: current.favicon ?? next.value!.favicon,
60-
// feeds: current.feeds ?? next.value!.feeds,
61-
// title: current.title.whenNotEmpty ?? next.value!.title,
62-
// ),
63-
// );
64-
// } else {
65-
// state = next;
66-
// }
67-
// },
68-
// onError: (error, stackTrace) {
69-
// logger.e(
70-
// 'Error listening to pageInfoProvider',
71-
// error: error,
72-
// stackTrace: stackTrace,
73-
// );
74-
// },
75-
// );
76-
7750
ref.listen(
7851
fireImmediately: true,
7952
tabStateProvider(cached.id).select((value) => value?.title),
@@ -150,3 +123,19 @@ Future<WebPageInfo> pageInfo(
150123

151124
return result.value;
152125
}
126+
127+
@Riverpod()
128+
AsyncValue<EquatableValue<Set<Uri>?>> websiteFeedProvider(
129+
Ref ref,
130+
String tabId,
131+
) {
132+
final tabState = ref.watch(tabStateProvider(tabId))!;
133+
final feeds = ref.watch(
134+
pageInfoProvider(
135+
tabState.url,
136+
isImageRequest: false,
137+
).select((value) => value.whenData((data) => EquatableValue(data.feeds))),
138+
);
139+
140+
return feeds;
141+
}

app/lib/presentation/controllers/website_title.g.dart

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lib/presentation/widgets/website_feed_tile.dart renamed to app/lib/presentation/widgets/website_feed_menu_button.dart

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,47 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
2424
import 'package:nullability/nullability.dart';
2525
import 'package:skeletonizer/skeletonizer.dart';
2626
import 'package:weblibre/core/routing/routes.dart';
27-
import 'package:weblibre/features/geckoview/domain/entities/states/tab.dart';
2827
import 'package:weblibre/presentation/controllers/website_title.dart';
2928
import 'package:weblibre/presentation/widgets/rounded_text.dart';
3029

31-
class WebsiteFeedTile extends HookConsumerWidget {
32-
final TabState initialTabState;
30+
class WebsiteFeedMenuButton extends HookConsumerWidget {
31+
final String tabId;
3332

34-
const WebsiteFeedTile(this.initialTabState, {super.key});
33+
const WebsiteFeedMenuButton(this.tabId, {super.key});
3534

3635
@override
3736
Widget build(BuildContext context, WidgetRef ref) {
38-
final pageInfoAsync = ref.watch(completePageInfoProvider(initialTabState));
37+
final feedsAsync = ref.watch(websiteFeedProviderProvider(tabId));
3938

4039
return Skeletonizer(
41-
enabled: pageInfoAsync.isLoading && initialTabState.feeds == null,
42-
child: pageInfoAsync.when(
40+
enabled: feedsAsync.isLoading && feedsAsync.value?.value == null,
41+
child: feedsAsync.when(
4342
skipLoadingOnReload: true,
44-
data: (info) {
45-
if (info.feeds.isEmpty) {
43+
data: (feeds) {
44+
if (feeds.value.isEmpty) {
4645
return const SizedBox.shrink();
4746
}
4847

49-
return ListTile(
50-
leading: const Icon(Icons.rss_feed),
51-
title: const Text('Available Web Feeds'),
52-
trailing: RoundedBackground(
48+
return MenuItemButton(
49+
leadingIcon: const Icon(Icons.rss_feed),
50+
closeOnActivate: false,
51+
trailingIcon: RoundedBackground(
5352
child: Text(
54-
info.feeds!.length.toString(),
53+
feeds.value!.length.toString(),
5554
textAlign: TextAlign.center,
5655
style: TextStyle(
5756
color: Theme.of(context).colorScheme.onPrimary,
5857
),
5958
),
6059
),
61-
onTap: () async {
60+
onPressed: () async {
6261
await SelectFeedDialogRoute(
6362
feedsJson: jsonEncode(
64-
info.feeds!.map((feed) => feed.toString()).toList(),
63+
feeds.value!.map((feed) => feed.toString()).toList(),
6564
),
6665
).push(context);
6766
},
67+
child: const Text('Available Web Feeds'),
6868
);
6969
},
7070
error: (error, stackTrace) {
@@ -77,11 +77,10 @@ class WebsiteFeedTile extends HookConsumerWidget {
7777
// onRetry: () => ref.refresh(pageInfoProvider(url)),
7878
// );
7979
},
80-
loading: () => const ListTile(
81-
leading: Icon(Icons.rss_feed),
82-
contentPadding: EdgeInsets.zero,
83-
title: Text('Available Web Feeds'),
84-
trailing: Bone.icon(),
80+
loading: () => const MenuItemButton(
81+
leadingIcon: Icon(Icons.rss_feed),
82+
trailingIcon: Bone.icon(),
83+
child: Text('Available Web Feeds'),
8584
),
8685
),
8786
);

0 commit comments

Comments
 (0)