miamihotline commented on a change in pull request #16910:
URL: https://github.com/apache/beam/pull/16910#discussion_r813854966



##########
File path: playground/frontend/lib/pages/playground/states/examples_state.dart
##########
@@ -82,31 +87,41 @@ class ExampleState with ChangeNotifier {
     return example;
   }
 
-  _loadCategories() async {
-    sdkCategories = await _exampleRepository.getListOfExamples(
-      GetListOfExamplesRequestWrapper(sdk: null, category: null),
-    );
-    await _loadDefaultExamples(sdkCategories);
-    notifyListeners();
+  _loadCategories() {
+    _exampleRepository
+        .getListOfExamples(
+          GetListOfExamplesRequestWrapper(sdk: null, category: null),
+        )
+        .then((map) => setSdkCategories(map));
   }
 
   changeSelectorVisibility() {
     isSelectorOpened = !isSelectorOpened;
     notifyListeners();
   }
 
-  _loadDefaultExamples(sdkCategories) async {
+  loadDefaultExamples() async {
+    if (defaultExamplesMap != null) {
+      return;
+    }
     defaultExamplesMap = {};
-    List<MapEntry<SDK, ExampleModel>> entries = [];
-    for (SDK sdk in SDK.values) {
-      ExampleModel? defaultExample = sdkCategories![sdk]?.first.examples.first;
-      if (defaultExample != null) {
-        // load source and output async
-        loadExampleInfo(defaultExample, sdk);
-        entries.add(MapEntry(sdk, defaultExample));
-      }
+    List<MapEntry<SDK, ExampleModel>> defaultExamples = [];
+
+    for (var value in SDK.values) {
+      defaultExamples.add(
+        MapEntry(
+            value,
+            await _exampleRepository.getDefaultExample(
+              GetExampleRequestWrapper('', value),
+            )),
+      );
+    }
+
+    defaultExamplesMap!.addEntries(defaultExamples);
+    for (var entry in defaultExamplesMap!.entries) {

Review comment:
       I'll remove it, thank you!

##########
File path: playground/frontend/lib/pages/playground/states/examples_state.dart
##########
@@ -82,31 +87,41 @@ class ExampleState with ChangeNotifier {
     return example;
   }
 
-  _loadCategories() async {
-    sdkCategories = await _exampleRepository.getListOfExamples(
-      GetListOfExamplesRequestWrapper(sdk: null, category: null),
-    );
-    await _loadDefaultExamples(sdkCategories);
-    notifyListeners();
+  _loadCategories() {
+    _exampleRepository
+        .getListOfExamples(
+          GetListOfExamplesRequestWrapper(sdk: null, category: null),
+        )
+        .then((map) => setSdkCategories(map));
   }
 
   changeSelectorVisibility() {
     isSelectorOpened = !isSelectorOpened;
     notifyListeners();
   }
 
-  _loadDefaultExamples(sdkCategories) async {
+  loadDefaultExamples() async {
+    if (defaultExamplesMap != null) {
+      return;
+    }
     defaultExamplesMap = {};
-    List<MapEntry<SDK, ExampleModel>> entries = [];
-    for (SDK sdk in SDK.values) {
-      ExampleModel? defaultExample = sdkCategories![sdk]?.first.examples.first;
-      if (defaultExample != null) {
-        // load source and output async
-        loadExampleInfo(defaultExample, sdk);
-        entries.add(MapEntry(sdk, defaultExample));
-      }
+    List<MapEntry<SDK, ExampleModel>> defaultExamples = [];
+
+    for (var value in SDK.values) {
+      defaultExamples.add(
+        MapEntry(
+            value,
+            await _exampleRepository.getDefaultExample(
+              GetExampleRequestWrapper('', value),
+            )),
+      );
+    }
+
+    defaultExamplesMap!.addEntries(defaultExamples);
+    for (var entry in defaultExamplesMap!.entries) {
+      loadExampleInfo(entry.value, entry.key)
+          .then((value) => defaultExamplesMap![entry.key] = value);

Review comment:
       I'll remove it, thank you!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to