fix: on load course topics, also load location media to get topic images (#4376)
This commit is contained in:
parent
615c3e9601
commit
b9e0ac6ee4
2 changed files with 16 additions and 7 deletions
|
|
@ -35,7 +35,7 @@ class CourseTopicModel {
|
|||
uuids: locationIds,
|
||||
),
|
||||
);
|
||||
Future<CourseLocationResponse> fetchLocations() => CourseLocationRepo.get(
|
||||
Future<CourseLocationResponse> _fetchLocations() => CourseLocationRepo.get(
|
||||
CourseInfoBatchRequest(
|
||||
batchId: uuid,
|
||||
uuids: locationIds,
|
||||
|
|
@ -65,7 +65,7 @@ class CourseTopicModel {
|
|||
|
||||
Future<List<String>> fetchLocationMedia() async {
|
||||
final allLocationMedia = <String>[];
|
||||
final locationResp = await fetchLocations();
|
||||
final locationResp = await _fetchLocations();
|
||||
for (final location in locationResp.locations) {
|
||||
final mediaResp = await CourseLocationMediaRepo.get(
|
||||
CourseInfoBatchRequest(
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ mixin CoursePlanProvider<T extends StatefulWidget> on State<T> {
|
|||
course!.fetchTopics(),
|
||||
];
|
||||
await Future.wait(courseFutures);
|
||||
await _loadTopicsMedia();
|
||||
} catch (e) {
|
||||
topicError = e;
|
||||
} finally {
|
||||
|
|
@ -76,6 +77,18 @@ mixin CoursePlanProvider<T extends StatefulWidget> on State<T> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _loadTopicsMedia() async {
|
||||
final List<Future> futures = [];
|
||||
if (course == null) return;
|
||||
for (final topicId in course!.topicIds) {
|
||||
final topic = course!.loadedTopics[topicId];
|
||||
if (topic != null) {
|
||||
futures.add(topic.fetchLocationMedia());
|
||||
}
|
||||
}
|
||||
await Future.wait(futures);
|
||||
}
|
||||
|
||||
Future<void> loadActivity(String topicId) async {
|
||||
setState(() {
|
||||
activityErrors[topicId] = null;
|
||||
|
|
@ -86,11 +99,7 @@ mixin CoursePlanProvider<T extends StatefulWidget> on State<T> {
|
|||
if (topic == null) {
|
||||
throw Exception("Topic is null");
|
||||
}
|
||||
|
||||
final topicFutures = <Future>[];
|
||||
topicFutures.add(topic.fetchActivities());
|
||||
topicFutures.add(topic.fetchLocationMedia());
|
||||
await Future.wait(topicFutures);
|
||||
await topic.fetchActivities();
|
||||
} catch (e) {
|
||||
activityErrors[topicId] = e;
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue