feat(home/*): add poll-to-refresh to each page

This commit is contained in:
2026-08-16 00:15:44 +02:00
parent bffd1d66d9
commit 39651c2ab7
7 changed files with 151 additions and 55 deletions

View File

@@ -199,6 +199,49 @@ class KretaClient {
}
}
/// Runs [action] without the fetching toast. Sets the error toast on failure.
Future<void> pullRefresh(Future Function() action) async {
try {
await action();
} catch (e) {
if (!isTokenExpired(e)) {
_toastCubit.setActiveToast(.error, e);
}
}
}
/// Refetches everything shown on the home feed (not the full school-year cache).
Future<void> refreshHomeFeed() async {
await pullRefresh(() async {
final weekFrom = timeNow().getMonday();
final weekTo = weekFrom.add(const Duration(days: 7));
await Future.wait([
getStudent(),
getTests(),
getHomework(),
renewMessages(),
getGrades(),
getLessons(weekFrom, weekTo),
]);
// manual link
await getOmissions();
cache.resolveTeachers();
});
}
/// Fetches lessons in 14-day chunks so [from]..[to] stays under the API range limit.
Future<void> getLessonsCovering(DateTime from, DateTime to) async {
DateTime date = from;
final requests = <Future>[];
while (date.isBefore(to)) {
final tmpTo = date.add(const Duration(days: 14));
final end = tmpTo.isAfter(to) ? to : tmpTo;
requests.add(getLessons(date, end));
date = tmpTo;
}
await Future.wait(requests);
}
Future<void> _setReauthFlag() async {
if (Platform.isIOS) {
try {

View File

@@ -93,8 +93,13 @@ class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
GradeSummaryBar(grades: allGrades, l10n: widget.data.l10n),
SizedBox(height: 20),
Expanded(
child: ListView(
children: [
child: RefreshIndicator(
onRefresh: () => widget.data.client!.pullRefresh(
() => widget.data.client!.getGrades(),
),
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [
Text(
widget.data.l10n.your_subjects,
style: appStyle.fonts.H_14px.apply(
@@ -241,6 +246,7 @@ class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
],
),
),
),
],
),
);

View File

@@ -126,13 +126,13 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: RefreshIndicator(
onRefresh: () => Future.value(),
onRefresh: () => widget.data.client!.refreshHomeFeed(),
notificationPredicate: (ScrollNotification notification) {
return notification.depth == 0;
},
triggerMode: RefreshIndicatorTriggerMode.onEdge,
displacement: 0,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
clipBehavior: Clip.none,
children: [
SizedBox(height: 24),

View File

@@ -177,10 +177,15 @@ class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
OmissionBar(),
SizedBox(height: 20),
Expanded(
child: ListView(
children: [
Text(
initData.l10n.subjects,
child: RefreshIndicator(
onRefresh: () => widget.data.client!.pullRefresh(
() => widget.data.client!.getOmissions(),
),
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [
Text(
initData.l10n.subjects,
style: appStyle.fonts.B_16SB.copyWith(
color: appStyle.colors.textPrimary,
),
@@ -293,6 +298,7 @@ class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
],
),
),
),
],
),
);

View File

@@ -186,6 +186,7 @@ class _HomeTimetableScreen extends FirkaState<HomeTimetableScreen>
listenWhen: (previous, current) =>
current.refreshTrigger != previous.refreshTrigger,
listener: (context, state) {
_lessonsCache.clear();
setState(() {});
},
child: _buildContent(context),
@@ -243,7 +244,16 @@ class _HomeTimetableScreen extends FirkaState<HomeTimetableScreen>
)..removeWhere(isEvent);
final events = List<LessonCacheModel>.from(_lessonsFor(day))
..retainWhere(isEvent);
return TimeTableDayWidget(lessons, events);
return TimeTableDayWidget(
lessons,
events,
onRefresh: () => widget.data.client!.pullRefresh(
() => widget.data.client!.getLessonsCovering(
_currentTabWeekMonday,
_currentTabWeekMonday.add(const Duration(days: 7)),
),
),
);
},
),
),

View File

@@ -373,11 +373,20 @@ class _HomeTimetableMonthlyScreen
left: 20,
right: 20,
),
child: GridView.count(
crossAxisCount: 7,
mainAxisSpacing: 16,
mainAxisExtent: 62,
children: ttDays,
child: RefreshIndicator(
onRefresh: () => widget.data.client!.pullRefresh(
() => widget.data.client!.getLessonsCovering(
currentMonthStart,
currentMonthEnd,
),
),
child: GridView.count(
physics: const AlwaysScrollableScrollPhysics(),
crossAxisCount: 7,
mainAxisSpacing: 16,
mainAxisExtent: 62,
children: ttDays,
),
),
),
),

View File

@@ -14,8 +14,14 @@ import 'lesson.dart';
class TimeTableDayWidget extends StatelessWidget {
final List<LessonCacheModel> lessons;
final List<LessonCacheModel> events;
final Future<void> Function()? onRefresh;
const TimeTableDayWidget(this.lessons, this.events, {super.key});
const TimeTableDayWidget(
this.lessons,
this.events, {
this.onRefresh,
super.key,
});
static String simplifyEventName(String e) {
return e
@@ -58,40 +64,52 @@ class TimeTableDayWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (lessons.isEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SvgPicture.asset(
"assets/images/logos/dave.svg",
width: 48,
height: 48,
),
SizedBox(height: 12),
Text(
initData.l10n.tt_no_classes_l1,
style: appStyle.fonts.B_16R.apply(
color: appStyle.colors.textSecondary,
),
),
Text(
initData.l10n.tt_no_classes_l2,
style: appStyle.fonts.B_16R.apply(
color: appStyle.colors.textSecondary,
),
),
if (events.isNotEmpty)
...events.map(
(event) => Center(
child: Text(
simplifyEventName(event.name),
style: appStyle.fonts.B_16R.apply(
color: appStyle.colors.textSecondary,
return RefreshIndicator(
onRefresh: onRefresh ?? () async {},
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.only(top: 70 + 16 + 20, left: 20, right: 20),
children: [
SizedBox(
height: MediaQuery.sizeOf(context).height * 0.45,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SvgPicture.asset(
"assets/images/logos/dave.svg",
width: 48,
height: 48,
),
),
SizedBox(height: 12),
Text(
initData.l10n.tt_no_classes_l1,
style: appStyle.fonts.B_16R.apply(
color: appStyle.colors.textSecondary,
),
),
Text(
initData.l10n.tt_no_classes_l2,
style: appStyle.fonts.B_16R.apply(
color: appStyle.colors.textSecondary,
),
),
if (events.isNotEmpty)
...events.map(
(event) => Center(
child: Text(
simplifyEventName(event.name),
style: appStyle.fonts.B_16R.apply(
color: appStyle.colors.textSecondary,
),
),
),
),
],
),
),
],
],
),
);
}
@@ -164,15 +182,19 @@ class TimeTableDayWidget extends StatelessWidget {
return Padding(
padding: const EdgeInsets.only(top: 70 + 16 + 20, left: 20, right: 20),
child: ListView.separated(
separatorBuilder: (context, index) => SizedBox(height: 16),
itemBuilder: (context, index) {
if (ttLessons.length == index) {
return SizedBox(height: 55);
}
return ttLessons[index];
},
itemCount: ttLessons.length + 1,
child: RefreshIndicator(
onRefresh: onRefresh ?? () async {},
child: ListView.separated(
physics: const AlwaysScrollableScrollPhysics(),
separatorBuilder: (context, index) => SizedBox(height: 16),
itemBuilder: (context, index) {
if (ttLessons.length == index) {
return SizedBox(height: 55);
}
return ttLessons[index];
},
itemCount: ttLessons.length + 1,
),
),
);
}