Skip to content

Commit

Permalink
Handle search errors with a message
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Jan 24, 2025
1 parent 9af4c73 commit 68b8b22
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/skin-museum-client/src/SkinTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const SkinTable = ({
getSkinData,
searchQuery,
loadingSearchQuery,
searchResultsError,
}) => {
function itemKey({ columnIndex, rowIndex }) {
const { requestToken, data: skin } = getSkinData({
Expand Down Expand Up @@ -90,7 +91,7 @@ const SkinTable = ({
paddingTop: 40,
}}
>
No skins matching "{searchQuery}"
{searchResultsError ?? `No skins matching "${searchQuery}"`}
</div>
)}
</div>
Expand All @@ -103,6 +104,7 @@ const mapStateToProps = (state) => ({
getSkinData: Selectors.getSkinDataGetter(state),
searchQuery: Selectors.getSearchQuery(state),
loadingSearchQuery: Selectors.getLoadingSearchQuery(state),
searchResultsError: Selectors.getSearchResultsError(state),
});

const mapDispatchToProps = (dispatch) => ({
Expand Down
4 changes: 4 additions & 0 deletions packages/skin-museum-client/src/redux/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export function gotNewMatchingSkins(skins) {
return { type: "GOT_NEW_MATCHING_SKINS", skins };
}

export function gotSearchError() {
return { type: "GOT_SEARCH_ERROR" };
}

export function gotSkinData(hash, data) {
return { type: "GOT_SKIN_DATA", hash, data };
}
Expand Down
3 changes: 3 additions & 0 deletions packages/skin-museum-client/src/redux/epics.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ const searchEpic = (actions) =>
nsfw: hit.nsfw === true || hit.nsfw === 1,
}));
return Actions.gotNewMatchingSkins(matchingSkins);
}),
catchError((e) => {
return of(Actions.gotSearchError());
})
);
})
Expand Down
12 changes: 12 additions & 0 deletions packages/skin-museum-client/src/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CHUNK_SIZE, UPLOAD_PAGE } from "../constants";
const defaultState = {
searchQuery: null,
loadingSearchResults: false,
searchResultsError: null,
selectedSkinPosition: null,
matchingSkins: null,
defaultSkins: [],
Expand Down Expand Up @@ -216,11 +217,21 @@ export default function reducer(state = defaultState, action) {
return {
...state,
loadingSearchResults: true,
searchResultsError: null,
searchQuery: action.query,
selectedSkinHash: null,
selectedSkinPosition: null,
focusedSkinFile: null,
};
case "GOT_SEARCH_ERROR": {
return {
...state,
loadingSearchResults: false,
searchResultsError:
"Error: We likely exceeded our search quota. Please try again later.",
matchingSkins: [],
};
}
case "GOT_NEW_MATCHING_SKINS":
let newSkins = state.skins;
if (action.skins != null) {
Expand All @@ -235,6 +246,7 @@ export default function reducer(state = defaultState, action) {
return {
...state,
loadingSearchResults: false,
searchResultsError: null,
matchingSkins: action.skins,
skins: newSkins,
};
Expand Down
4 changes: 4 additions & 0 deletions packages/skin-museum-client/src/redux/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export function getLoadingSearchQuery(state) {
return state.loadingSearchResults;
}

export function getSearchResultsError(state) {
return state.searchResultsError;
}

export function getMatchingSkins(state) {
return state.matchingSkins;
}
Expand Down

0 comments on commit 68b8b22

Please sign in to comment.