Skip to content

Commit 68b8b22

Browse files
committed
Handle search errors with a message
1 parent 9af4c73 commit 68b8b22

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

packages/skin-museum-client/src/SkinTable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const SkinTable = ({
1818
getSkinData,
1919
searchQuery,
2020
loadingSearchQuery,
21+
searchResultsError,
2122
}) => {
2223
function itemKey({ columnIndex, rowIndex }) {
2324
const { requestToken, data: skin } = getSkinData({
@@ -90,7 +91,7 @@ const SkinTable = ({
9091
paddingTop: 40,
9192
}}
9293
>
93-
No skins matching "{searchQuery}"
94+
{searchResultsError ?? `No skins matching "${searchQuery}"`}
9495
</div>
9596
)}
9697
</div>
@@ -103,6 +104,7 @@ const mapStateToProps = (state) => ({
103104
getSkinData: Selectors.getSkinDataGetter(state),
104105
searchQuery: Selectors.getSearchQuery(state),
105106
loadingSearchQuery: Selectors.getLoadingSearchQuery(state),
107+
searchResultsError: Selectors.getSearchResultsError(state),
106108
});
107109

108110
const mapDispatchToProps = (dispatch) => ({

packages/skin-museum-client/src/redux/actionCreators.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export function gotNewMatchingSkins(skins) {
3535
return { type: "GOT_NEW_MATCHING_SKINS", skins };
3636
}
3737

38+
export function gotSearchError() {
39+
return { type: "GOT_SEARCH_ERROR" };
40+
}
41+
3842
export function gotSkinData(hash, data) {
3943
return { type: "GOT_SKIN_DATA", hash, data };
4044
}

packages/skin-museum-client/src/redux/epics.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ const searchEpic = (actions) =>
157157
nsfw: hit.nsfw === true || hit.nsfw === 1,
158158
}));
159159
return Actions.gotNewMatchingSkins(matchingSkins);
160+
}),
161+
catchError((e) => {
162+
return of(Actions.gotSearchError());
160163
})
161164
);
162165
})

packages/skin-museum-client/src/redux/reducer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CHUNK_SIZE, UPLOAD_PAGE } from "../constants";
33
const defaultState = {
44
searchQuery: null,
55
loadingSearchResults: false,
6+
searchResultsError: null,
67
selectedSkinPosition: null,
78
matchingSkins: null,
89
defaultSkins: [],
@@ -216,11 +217,21 @@ export default function reducer(state = defaultState, action) {
216217
return {
217218
...state,
218219
loadingSearchResults: true,
220+
searchResultsError: null,
219221
searchQuery: action.query,
220222
selectedSkinHash: null,
221223
selectedSkinPosition: null,
222224
focusedSkinFile: null,
223225
};
226+
case "GOT_SEARCH_ERROR": {
227+
return {
228+
...state,
229+
loadingSearchResults: false,
230+
searchResultsError:
231+
"Error: We likely exceeded our search quota. Please try again later.",
232+
matchingSkins: [],
233+
};
234+
}
224235
case "GOT_NEW_MATCHING_SKINS":
225236
let newSkins = state.skins;
226237
if (action.skins != null) {
@@ -235,6 +246,7 @@ export default function reducer(state = defaultState, action) {
235246
return {
236247
...state,
237248
loadingSearchResults: false,
249+
searchResultsError: null,
238250
matchingSkins: action.skins,
239251
skins: newSkins,
240252
};

packages/skin-museum-client/src/redux/selectors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export function getLoadingSearchQuery(state) {
3131
return state.loadingSearchResults;
3232
}
3333

34+
export function getSearchResultsError(state) {
35+
return state.searchResultsError;
36+
}
37+
3438
export function getMatchingSkins(state) {
3539
return state.matchingSkins;
3640
}

0 commit comments

Comments
 (0)