Skip to content

Commit

Permalink
Fix duplicate transitions when cache is expired
Browse files Browse the repository at this point in the history
  • Loading branch information
lolocomotive committed May 17, 2023
1 parent dd37285 commit 0c51f41
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
15 changes: 11 additions & 4 deletions lib/screens/communication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class _CommunicationPageState extends State<CommunicationPage> {
bool _transitionDone = false;
List<Participation>? _participations;

Future<void>? _transition;

@override
void initState() {
super.initState();
Expand All @@ -56,11 +58,17 @@ class _CommunicationPageState extends State<CommunicationPage> {
load() async {
final responses =
ConfigProvider.client!.getCommunicationParticipations(widget.communication.id);
bool isFirst = true;
await for (final response in responses) {
if (!mounted) return;
if (!isFirst) {
await _transition;
} else {
delayTransitionDone();
}
isFirst = false;
setState(() {
_participations = response.data;
delayTransitionDone();
});
}
}
Expand All @@ -69,9 +77,8 @@ class _CommunicationPageState extends State<CommunicationPage> {
setState(() {
_transitionDone = false;
});
Future.delayed(const Duration(milliseconds: 400)).then((_) {
_transitionDone = true;
});
_transition = Future.delayed(const Duration(milliseconds: 400))
..then((_) => _transitionDone = true);
}

@override
Expand Down
10 changes: 1 addition & 9 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,7 @@ class _GradeListState extends State<GradeList> with TickerProviderStateMixin {
),
);
}
print('[Permissions] for: ${ConfigProvider.currentSchool}');
for (final permission in snapshot.data!.permissions!) {
if (permission.schoolId == ConfigProvider.currentSchool) {
print('[Permission] service: ${permission.service}');
print('[Permission] operations: ${permission.permittedOperations}');
} else {
print('not school ${permission.schoolId} != ${ConfigProvider.currentSchool}');
}
}

if (snapshot.data!.permissions!
.where(
(permission) =>
Expand Down
7 changes: 1 addition & 6 deletions lib/screens/lesson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class _LessonPageState extends State<LessonPage> {
void initState() {
ConfigProvider.currentId!.then((id) {
_data = ConfigProvider.client!.getLesson(id, widget._lesson.id);
setState(() {});
});
super.initState();
}
Expand Down Expand Up @@ -86,12 +87,6 @@ class _LessonPageState extends State<LessonPage> {
],
),
),
/* TODO implement lessonContent display
HomeworkList(
_lesson.exercises.where((e) => e.type == ExerciseType.lessonContent).toList(),
'Contenu de la séance',
color,
), */
StreamBuilder<SkolengoResponse<Lesson>>(
stream: _data,
builder: (context, snapshot) {
Expand Down
17 changes: 9 additions & 8 deletions lib/screens/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MessagesPageState extends State<MessagesPage> with TickerProviderStateMixi
int _page = 0;
final int _pageSize = 20;
bool _transitionDone = false;
Future<void>? _transition;

void openConversation(BuildContext context, GlobalKey? parentKey, Communication communication) {
if (_sideBySide) {
Expand All @@ -76,7 +77,7 @@ class MessagesPageState extends State<MessagesPage> with TickerProviderStateMixi
}
}

Future<void> load([transitionned = false]) async {
Future<void> load([bool transitionned = false]) async {
final responses = ConfigProvider.client!.getCommunicationsFromFolder(
_folder!.id,
offset: _pageSize * _page,
Expand All @@ -98,15 +99,16 @@ class MessagesPageState extends State<MessagesPage> with TickerProviderStateMixi
// because there could have been other responses in between
_communications.sort((a, b) =>
b.lastParticipation!.dateTime.date().compareTo(a.lastParticipation!.dateTime.date()));
isFirst = false;
}

_loaded = true;
if (!transitionned) {
// This keeps the animation from being played twice
await _transition;
} else if (!transitionned) {
transitionned = true;
delayTransitionDone();
}
setState(() {});
_loaded = true;
isFirst = false;
}
}

Expand All @@ -124,9 +126,8 @@ class MessagesPageState extends State<MessagesPage> with TickerProviderStateMixi
setState(() {
_transitionDone = false;
});
Future.delayed(const Duration(milliseconds: 400)).then((_) {
_transitionDone = true;
});
_transition = Future.delayed(const Duration(milliseconds: 400))
..then((_) => _transitionDone = true);
}

static MessagesPageState? currentState;
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/timetable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class _TimetablePageState extends State<TimetablePage> with TickerProviderStateM
child: RefreshIndicator(
onRefresh: () async {
KlientApp.cache.forceRefresh = true;
_getCalendar();
await _getCalendar().last;
KlientApp.cache.forceRefresh = false;
loaded = false;
setState(() {});
Expand Down

0 comments on commit 0c51f41

Please sign in to comment.