diff --git a/lib/screens/explore.dart b/lib/screens/explore.dart index 2b75f4b..0a496d0 100644 --- a/lib/screens/explore.dart +++ b/lib/screens/explore.dart @@ -12,11 +12,11 @@ import 'package:island/models/webfeed.dart'; import 'package:island/pods/event_calendar.dart'; import 'package:island/pods/userinfo.dart'; import 'package:island/services/responsive.dart'; -import 'package:island/widgets/account/event_calendar.dart'; import 'package:island/widgets/account/fortune_graph.dart'; import 'package:island/widgets/app_scaffold.dart'; import 'package:island/models/post.dart'; import 'package:island/widgets/check_in.dart'; +import 'package:island/widgets/post/post_featured.dart'; import 'package:island/widgets/post/post_item.dart'; import 'package:island/screens/tabs.dart'; import 'package:material_symbols_icons/symbols.dart'; @@ -70,15 +70,6 @@ class ExploreScreen extends HookConsumerWidget { final events = ref.watch(eventCalendarProvider(query.value)); final selectedDay = useState(now); - - void onMonthChanged(int year, int month) { - query.value = EventCalendarQuery( - uname: query.value.uname, - year: year, - month: month, - ); - } - // Function to handle day selection for synchronizing between widgets void onDaySelected(DateTime day) { selectedDay.value = day; @@ -224,20 +215,10 @@ class ExploreScreen extends HookConsumerWidget { ); }, ), - Card( - margin: EdgeInsets.only(left: 8, right: 12, top: 8), - child: Column( - children: [ - // Use the reusable EventCalendarWidget - EventCalendarWidget( - events: events, - initialDate: now, - showEventDetails: true, - onMonthChanged: onMonthChanged, - onDaySelected: onDaySelected, - ), - ], - ), + PostFeaturedList().padding( + left: 8, + right: 12, + top: 8, ), FortuneGraphWidget( margin: EdgeInsets.only(left: 8, right: 12, top: 8), @@ -408,6 +389,10 @@ class _ActivityListView extends HookConsumerWidget { margin: EdgeInsets.only(left: 8, right: 8, bottom: 4), ), ), + if (!contentOnly) + SliverToBoxAdapter( + child: PostFeaturedList().padding(horizontal: 8, bottom: 4, top: 4), + ), SliverList.builder( itemCount: widgetCount, itemBuilder: (context, index) { diff --git a/lib/widgets/post/post_featured.dart b/lib/widgets/post/post_featured.dart new file mode 100644 index 0000000..152715e --- /dev/null +++ b/lib/widgets/post/post_featured.dart @@ -0,0 +1,66 @@ +import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:island/models/post.dart'; +import 'package:island/pods/network.dart'; +import 'package:material_symbols_icons/symbols.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:island/widgets/post/post_item.dart'; +import 'package:styled_widget/styled_widget.dart'; + +part 'post_featured.g.dart'; + +@riverpod +Future> featuredPosts(Ref ref) async { + final apiClient = ref.watch(apiClientProvider); + final resp = await apiClient.get('/sphere/posts/featured'); + return resp.data.map((e) => SnPost.fromJson(e)).cast().toList(); +} + +class PostFeaturedList extends HookConsumerWidget { + const PostFeaturedList({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final featuredPostsAsync = ref.watch(featuredPostsProvider); + + return ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(8)), + child: Card( + color: Theme.of(context).colorScheme.surfaceContainerHigh, + margin: EdgeInsets.zero, + child: Column( + children: [ + Row( + spacing: 8, + children: [ + const Icon(Symbols.highlight), + Text('Highlight Posts'), + ], + ).padding(horizontal: 16, vertical: 8), + featuredPostsAsync.when( + loading: () => const Center(child: CircularProgressIndicator()), + error: (error, stack) => Center(child: Text('Error: $error')), + data: (posts) { + return SizedBox( + height: 320, + child: PageView.builder( + scrollDirection: Axis.horizontal, + itemCount: posts.length, + itemBuilder: (context, index) { + return SingleChildScrollView( + child: PostActionableItem( + item: posts[index], + borderRadius: 8, + ), + ); + }, + ), + ); + }, + ), + ], + ), + ), + ); + } +} diff --git a/lib/widgets/post/post_featured.g.dart b/lib/widgets/post/post_featured.g.dart new file mode 100644 index 0000000..febbdab --- /dev/null +++ b/lib/widgets/post/post_featured.g.dart @@ -0,0 +1,28 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'post_featured.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$featuredPostsHash() => r'4b7fffb02eac72f5861b02af1b1e5da36b571698'; + +/// See also [featuredPosts]. +@ProviderFor(featuredPosts) +final featuredPostsProvider = AutoDisposeFutureProvider>.internal( + featuredPosts, + name: r'featuredPostsProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$featuredPostsHash, + dependencies: null, + allTransitiveDependencies: null, +); + +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +typedef FeaturedPostsRef = AutoDisposeFutureProviderRef>; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package