Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically Hide and Show Loading Spinner
For comparison [see this commit][commit] This commit is a slight divergence from Stimulus. Superglue does not have global callbacks like `turbolinks:request-start`, if you need to do something before a request starts, you must do so explicitly. The behavior of showing a loading indicator requires an optimistic update. We have to change the loading state to `true` before we make a request, and change it to `false` when we're done with the request. To make this feature work, add your customizations to the generated `application_visit.js` and `pagesSlice`. Superglue leans on Redux to give you the option of creating your own action creators, and reducers. The Superglue installer already sets up a place where you can put this logic. For our purposes, we need to set the loading indicator on the current page to `false`. Superglue's state shape is like Turbolink's internal state, a hash where the urls are the keys and the values are the pages's content. We also recieve the current key from the passed in props as `this.props.pageKey`. Once we've created our action creator, we dispatch it with the `pageKey` to toggle the current page's loading state, here's the meat of the functionality in `pagesSlice`: ``` + reducers: { + showLoading: (state, action) => { + const {pageKey} = action.payload; + const { seatingMap } = state[pageKey].data + seatingMap.loading = true + }, + hideLoading: (state, action) => { + const {pageKey} = action.payload; + const { seatingMap } = state[pageKey].data + seatingMap.loading = false + } + } ``` [commit]: seanpdoyle@7169787
- Loading branch information