1
votes

In google app maker, I'm making an API call to a 3rd party vendor and I'm displaying a spinner while the data loads. How can I hide the spinner programatically once the data loads?

Client Script

google.script.run.withSuccessHandler(function(response){
  
  groupRules= JSON.parse(response);
  
}).withFailureHandler(function(err){
    console.error(err);
    setNotificationText('Unable to retrieve group rules. Please try again.');
    app.popups.snackbar.visible = true;
    
}).getGroupRules(groupId);

Server script

function getGroupRules(groupId) {

  var groupRules;

    var options = {
      'method' : 'GET'
    };

    var groupRulesResponse = UrlFetchApp.fetch('http://apihere.com/' + groupId, options);

  return groupRules;

}
1
could you please add the code showing how you call the 3rd party api ? - ValLeNain
Spinner.visible = false per Google App Maker Spinner Widget API - gravity
@ValLeNain I've added the snippets - jorgeAChacon
@gravitymixes I tried spinner1.visible = false, but it did not work. 'spinner1' is the name of the spinner I'm showing. - jorgeAChacon

1 Answers

2
votes

You need to put the Spinner.visible = false; in the success and failure handlers so that App Maker waits for the script to finish.

app.pages.NewPage.descendants.Spinner1.visible = true;

google.script.run.withSuccessHandler(function(response){
  
  groupRules= JSON.parse(response);
  app.pages.NewPage.descendants.Spinner1.visible = false;
  
}).withFailureHandler(function(err){
    console.error(err);
    setNotificationText('Unable to retrieve group rules. Please try again.');
    app.popups.snackbar.visible = true;
    app.pages.NewPage.descendants.Spinner1.visible = false;
    
}).getGroupRules(groupId);