✨ Featured post
This commit is contained in:
@@ -12,11 +12,11 @@ import 'package:island/models/webfeed.dart';
|
|||||||
import 'package:island/pods/event_calendar.dart';
|
import 'package:island/pods/event_calendar.dart';
|
||||||
import 'package:island/pods/userinfo.dart';
|
import 'package:island/pods/userinfo.dart';
|
||||||
import 'package:island/services/responsive.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/account/fortune_graph.dart';
|
||||||
import 'package:island/widgets/app_scaffold.dart';
|
import 'package:island/widgets/app_scaffold.dart';
|
||||||
import 'package:island/models/post.dart';
|
import 'package:island/models/post.dart';
|
||||||
import 'package:island/widgets/check_in.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/widgets/post/post_item.dart';
|
||||||
import 'package:island/screens/tabs.dart';
|
import 'package:island/screens/tabs.dart';
|
||||||
import 'package:material_symbols_icons/symbols.dart';
|
import 'package:material_symbols_icons/symbols.dart';
|
||||||
@@ -70,15 +70,6 @@ class ExploreScreen extends HookConsumerWidget {
|
|||||||
final events = ref.watch(eventCalendarProvider(query.value));
|
final events = ref.watch(eventCalendarProvider(query.value));
|
||||||
|
|
||||||
final selectedDay = useState(now);
|
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
|
// Function to handle day selection for synchronizing between widgets
|
||||||
void onDaySelected(DateTime day) {
|
void onDaySelected(DateTime day) {
|
||||||
selectedDay.value = day;
|
selectedDay.value = day;
|
||||||
@@ -224,20 +215,10 @@ class ExploreScreen extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Card(
|
PostFeaturedList().padding(
|
||||||
margin: EdgeInsets.only(left: 8, right: 12, top: 8),
|
left: 8,
|
||||||
child: Column(
|
right: 12,
|
||||||
children: [
|
top: 8,
|
||||||
// Use the reusable EventCalendarWidget
|
|
||||||
EventCalendarWidget(
|
|
||||||
events: events,
|
|
||||||
initialDate: now,
|
|
||||||
showEventDetails: true,
|
|
||||||
onMonthChanged: onMonthChanged,
|
|
||||||
onDaySelected: onDaySelected,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
FortuneGraphWidget(
|
FortuneGraphWidget(
|
||||||
margin: EdgeInsets.only(left: 8, right: 12, top: 8),
|
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),
|
margin: EdgeInsets.only(left: 8, right: 8, bottom: 4),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (!contentOnly)
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: PostFeaturedList().padding(horizontal: 8, bottom: 4, top: 4),
|
||||||
|
),
|
||||||
SliverList.builder(
|
SliverList.builder(
|
||||||
itemCount: widgetCount,
|
itemCount: widgetCount,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
66
lib/widgets/post/post_featured.dart
Normal file
66
lib/widgets/post/post_featured.dart
Normal file
@@ -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<List<SnPost>> 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<SnPost>().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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
28
lib/widgets/post/post_featured.g.dart
Normal file
28
lib/widgets/post/post_featured.g.dart
Normal file
@@ -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<List<SnPost>>.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<List<SnPost>>;
|
||||||
|
// 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
|
Reference in New Issue
Block a user