ceddlyburge / elm-league-tables-from-google-sheets

A website to show league tables and fixtures, from results stored in Google Sheets
https://se-polo-2019.netlify.com/
MIT License
8 stars 0 forks source link

Cache results from the Google Sheets Api #9

Open ceddlyburge opened 5 years ago

ceddlyburge commented 5 years ago

This will make the app more robust when the network is patchy / slow, but introduces ui and code complications.

Saving the api results to local storage is quick and easy.

Restoring them on app startup and supplying them via ports is also quick and easy.

The ui changes to provide a good user experience are harder though. When results already exist, a temporary, probably animated, message would be useful to let the user know whether a refresh has succeeded or failed. This means that they will know if the data is stale and can choose to refresh again. If there is no existing data, then the message should be permanent, as there is nothing else to display.

The code currently caches the api result once it is loaded, so a mechanism to refresh the cache ocassionally would be useful.

Rough plan as follows (just for League List page)

AnimationTimer
 state : Inactive, SuccessfulFetch, FailedFetch
 percentageElapsed : Int

Add leagueListAnimation : AnimationTimer to model.

The logic is as follows

If Just leagueSummaries then Show loading message if loading (push leagues down below loading message, possibly animate) Show success message for 5 seconds if AfterSuccessfulFetchAndExistingData Show failure message for 5 seconds if AfterFailedFetch Show the leagues else Show loading message if loading Show failure message if failed fetch Show code bug if not asked

Probably want to remove any animations when changing page as well. A navigate away and a navigate back might cause this.

Tests

Update (it now has an additional responsibility to set the AfterFetchAnimationTimer)

View

End to end I don't think it will be possible to set up local storage, which will make things difficult Can have one without a http request so can check the view when there is no pre existing data See if I can pass somthing to init

ceddlyburge commented 5 years ago

I have decided that this is too much work for too little benefit.

I think after moving to elm 0.19 I could use the create-elm-app webpack rewriting mechanism to add the google api calls to the service worker, which would solve the problem.

ceddlyburge commented 4 years ago

Have now moved to elm 0.19, so plan is now to use the create-elm-app webpack rewriting mechanism to add the url of the api endpoints. This is easier now that we are using an aws lamda / netlify function, as the urls will be the same for every deployment