-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Updating to Cells #2641
Add Updating to Cells #2641
Conversation
Thanks for this @jtoar! I don't have answers to any of those questions, I just want this merged right away so I can stop issuing |
Oh damn I just added this to my app with patch-package and it seems to be working! Just added |
@cannikin Having to |
IT'S WORKING |
After this PR merges we should just release it as 1.0, this is all we need. THANKS @jtoar!!!!!!! |
I'm so excited this is working I don't mind adding the I'm not too grossed out about just generating cells with |
Here's another catch: does Apollo's refetch function (the one that comes from No, not by default (https://www.apollographql.com/docs/react/data/queries/#inspecting-loading-states):
So we'd have to make our defaults: beforeQuery = (props) => ({
variables: props,
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first',
+ notifyOnNetworkStatusChange: true,
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some feedback here about the code! This is such an awesome feature! Thanks for working on this @jtoar
This is how we do loading state for one of our cells. Sorry it's a long post, but I just wanted to show a loading state that's not just a small loading spinner or a simple overlay. And I hope this is a pattern that we can still support even with the new Showing scoring labels for 1 - 4 Then clicking + to configure the labels for scoring 1 - 5 we show this while it's fetching the labels from the DB And when it's done loading we finally get this The way I've implemented it is to reuse the export const beforeQuery = (props) => {
return { variables: props, fetchPolicy: 'cache-first' }
}
export const QUERY = gql`
query ConfigureScoringLabelsQuery($topScore: Int!, $teamId: Int!) {
defaultLabels: defaultScoreLabelsForTopScore(
topScore: $topScore
teamId: $teamId
) {
id
score
label
}
}
`
export const Loading = ({ topScore, scoreLabels, setScoreLabels }) => (
<Success
topScore={topScore}
scoreLabels={scoreLabels}
setScoreLabels={setScoreLabels}
/>
)
export const Success = ({
topScore,
scoreLabels,
setScoreLabels,
defaultLabels,
}) => {
const labels = scoreLabels[topScore]
const isLoading = labels === undefined
const setLabels = (labels) => {
scoreLabels[topScore] = labels
setScoreLabels({ ...scoreLabels })
} As you can see I use And the inputs are just done like this: <input
type="text"
value={isLoading ? 'Loading...' : labels[topScore - 1 - i].label}
disabled={isLoading}
onChange={(event) => {
labels[topScore - 1 - i].label = event.target.value
setLabels([...labels])
}}
className="w-full"
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, nicely done @jtoar
@peterp I was about to merge this but I realized I'm not typing the |
@jtoar That looks good to me, my only recommendation would be to add comments so that |
As of Apollo Client
v3
, the defaultfetchPolicy
iscache-first
.cache-first
is great, butcache-and-network
is better. Accordingly, it's what we default to. It comes with a hiccup though:cache-and-network
gives you data if it's there (the "cache" part), then makes a GraphQL request to see if there's anything new ("and-network"). This means that the "result" Cells get (and use to figure out what to render) has data (usually an object/array) andloading = true
. And ifloading = true
, that means Loading gets rendered. Because things go in order:redwood/packages/web/src/components/createCell.tsx
Lines 128 to 146 in fbccb88
This is what it looks like: https://s.tape.sh/jf6jLX7u. I'm throttling the network so that you can really see Loading render. Near the end, you can see that the
PostsPage
(which has thePostsCell
) displaysLoading...
even though there's data in the cache. (The other pages also display loading even though they have data too!)Much in the same vein as #1878, this PR fixes this by providing an "Updating" state to Cells: https://s.tape.sh/YHPMztQO. The Loading states are gone. But there's a lot more details to consider:
loading = true
?useAuth
context, which provides an interface (logIn, signOut, etc.) that auth providers adapt themselves to.Any and all feedback is welcome and appreciated!