Skip to content

Commit 9a8a540

Browse files
committed
Add cache-and-network and set loading
1 parent 85efc1e commit 9a8a540

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/components/Section.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,39 +233,39 @@ const SectionWithData = ({ location: { state, pathname } }) => {
233233
if (state) {
234234
query = SECTION_BY_ID_QUERY
235235
variables = { id: state.section.id }
236-
createProps = ({ data, loading }) => ({
236+
createProps = ({ data }) => ({
237237
section: {
238238
...state.section,
239239
content: get(data, 'section.content'),
240240
views: get(data, 'section.views'),
241241
scrollY: get(data, 'section.scrollY')
242242
},
243243
chapter: state.chapter,
244-
loading
244+
loading: !data.section
245245
})
246246
} else if (page.chapterTitle) {
247247
query = SECTION_BY_CHAPTER_TITLE_QUERY
248248
variables = { title: page.chapterTitle }
249-
createProps = ({ data, loading }) => ({
249+
createProps = ({ data }) => ({
250250
section: get(data, 'chapterByTitle.section'),
251251
chapter: {
252252
...data.chapterByTitle,
253253
number: null
254254
},
255-
loading
255+
loading: !data.chapterByTitle
256256
})
257257
} else if (page.chapterNumber) {
258258
query = SECTION_BY_NUMBER_QUERY
259259
variables = page
260-
createProps = ({ data, loading }) => ({
260+
createProps = ({ data }) => ({
261261
section: get(data, 'chapterByNumber.section'),
262262
chapter: data.chapterByNumber,
263-
loading
263+
loading: !data.chapterByNumber
264264
})
265265
}
266266

267267
return (
268-
<Query query={query} variables={variables}>
268+
<Query query={query} variables={variables} fetchPolicy="cache-and-network">
269269
{queryInfo => (
270270
<Mutation mutation={VIEWED_SECTION_MUTATION}>
271271
{viewedSection => (

0 commit comments

Comments
 (0)