Skip to content

Commit 931a893

Browse files
committed
change fetchPolicy to avoid getting stuck on load bar as per apollographql/react-apollo#2899
1 parent 75a6439 commit 931a893

File tree

8 files changed

+43
-21
lines changed

8 files changed

+43
-21
lines changed

application/src/Pages/Donation/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Donation extends Component {
207207

208208
return (
209209
<Query
210-
fetchPolicy="network-only"
210+
fetchPolicy="no-cache"
211211
query={QUERY}
212212
variables={{ id, self: context.userID }}
213213
>

application/src/Pages/Event/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class Event extends Component {
293293

294294
return (
295295
<Query
296-
fetchPolicy="network-only"
296+
fetchPolicy="no-cache"
297297
query={QUERY}
298298
variables={{ id, self: context.userID }}
299299
>

application/src/Pages/News/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class News extends Component {
192192

193193
return (
194194
<Query
195-
fetchPolicy="network-only"
195+
fetchPolicy="no-cache"
196196
query={QUERY}
197197
variables={{ id, self: context.userID }}
198198
>

application/src/Pages/Nonprofit/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class Nonprofit extends Component {
237237

238238
return (
239239
<Query
240-
fetchPolicy="network-only"
240+
fetchPolicy="no-cache"
241241
query={QUERY}
242242
variables={{ id, self: context.userID }}
243243
>

application/src/Pages/Person/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class Person extends Component {
221221

222222
return (
223223
<Query
224-
fetchPolicy="network-only"
224+
fetchPolicy="no-cache"
225225
query={QUERY}
226226
variables={{ id, self: context.userID }}
227227
>

application/src/Pages/Transaction/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class Transaction extends Component {
208208

209209
return (
210210
<Query
211-
fetchPolicy="network-only"
211+
fetchPolicy="no-cache"
212212
query={QUERY}
213213
variables={{ id, self: context.userID }}
214214
>

application/src/Pages/TransactionList/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class TransactionList extends Component {
106106
<Typography variant="body2" className={classes.label}>
107107
{`${node.user.name}`}
108108
{<ToIcon className={classes.toIcon} />}
109-
{`${node.target.name}`}
109+
{node.target.name}
110110
</Typography>
111111
);
112112
}

application/src/Pages/__Common__/QueryHelper/index.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ const styles = theme => ({
3333
color: theme.palette.tertiary.main,
3434
textAlign: 'center',
3535
},
36+
empty: {
37+
margin: '0 auto',
38+
fontWeight: 'bold',
39+
color: theme.palette.tertiary.main,
40+
textAlign: 'center',
41+
},
3642

3743
})
3844

@@ -72,7 +78,7 @@ class QueryHelper extends Component {
7278
<div>
7379
{dataOld && make(dataOld)}
7480
<Query
75-
fetchPolicy="network-only"
81+
fetchPolicy="no-cache"
7682
query={query}
7783
variables={variables}
7884
partialRefetch={true}
@@ -84,29 +90,45 @@ class QueryHelper extends Component {
8490
let dataCurrent = dataOld.concat(data[Object.keys(data)[0]].edges)
8591

8692
return (
87-
<InfiniteScroll
88-
pageStart={0}
89-
className={classes.infiniteScroll}
90-
loadMore={() => this.paginate(dataCurrent)}
91-
hasMore={(dataCurrent.length > dataOld.length) || data[Object.keys(data)[0]].pageInfo.hasNextPage}
92-
loader={
93-
<Typography type="body2" className={classes.loader}>
94-
Loading more results...
95-
</Typography>
96-
}
97-
/>
93+
<div>
94+
<InfiniteScroll
95+
pageStart={0}
96+
className={classes.infiniteScroll}
97+
loadMore={() => this.paginate(dataCurrent)}
98+
hasMore={(dataCurrent.length > dataOld.length) || data[Object.keys(data)[0]].pageInfo.hasNextPage}
99+
loader={
100+
<Typography type="body2" className={classes.loader}>
101+
Loading more results...
102+
</Typography>
103+
}
104+
/>
105+
{
106+
(dataCurrent.length === 0) &&
107+
<Typography type="body2" className={classes.empty}>
108+
Nothing to see here
109+
</Typography>
110+
}
111+
</div>
98112
)
99113
}}
100114
</Query>
101115
</div>
102116
);
103117
} else {
104118
return (
105-
<Query fetchPolicy="network-only" query={query} variables={variables}>
119+
<Query fetchPolicy="no-cache" query={query} variables={variables}>
106120
{({ loading, error, data }) => {
107121
if (loading) return <LinearProgress className={classes.progress} />;
108122
if (error) return `Error! ${error.message}`;
109-
return make(data[Object.keys(data)[0]].edges)
123+
if (data[Object.keys(data)[0]].edges.length > 0) {
124+
return make(data[Object.keys(data)[0]].edges)
125+
} else {
126+
return (
127+
<Typography type="body2" className={classes.empty}>
128+
Nothing to see here
129+
</Typography>
130+
);
131+
}
110132
}}
111133
</Query>
112134
);

0 commit comments

Comments
 (0)