Handle case where user selects random skin with no matching skins

This commit is contained in:
Jordan Eldredge 2020-11-08 13:25:47 -08:00
parent 2e4946ac79
commit 1a8394c2db
2 changed files with 29 additions and 11 deletions

View file

@ -12,10 +12,6 @@ export function requestUnloadedSkin(index) {
}
export function selectedSkin(hash, position) {
if (hash == null) {
// trying to narrow down: https://sentry.io/share/issue/04b1bc5c2a764addac4e62dea201096a/
throw new Error("Tried to select a null skin");
}
return { type: "SELECTED_SKIN", hash, position };
}
@ -148,3 +144,7 @@ export function toggleFileExplorer() {
export function closeFileExlporer() {
return { type: "CLOSE_FILE_EXPLORER" };
}
export function alert(message) {
return { type: "ALERT", message };
}

View file

@ -147,7 +147,20 @@ const searchEpic = (actions) =>
const randomSkinEpic = (actions, states) =>
actions.pipe(
filter((action) => action.type === "REQUESTED_RANDOM_SKIN"),
map(() => Actions.selectedSkin(Selectors.getRandomSkinHash(states.value)))
map(() => Selectors.getRandomSkinHash(states.value)),
map((md5) => {
if (md5 == null) {
return Actions.alert("No skins found.");
}
return Actions.selectedSkin(md5);
})
);
const alertEpic = (actions) =>
actions.pipe(
filter((action) => action.type === "ALERT"),
tap(({ message }) => alert(message)),
ignoreElements()
);
const chunkState = {};
@ -440,17 +453,21 @@ const markNsfwEpic = (actions) => {
filter((action) => action.type === "MARK_NSFW"),
mergeMap(async ({ hash }) => {
try {
await fetch(`${API_URL}/skins/${hash}/report`, {
const response = await fetch(`${API_URL}/skins/${hash}/report`, {
method: "POST",
mode: "cors",
});
if (!response.ok) {
throw new Error("Failed to report skin.");
}
} catch (e) {
alert("Oops. Something went wrong. Please try again later.");
return;
return Actions.alert(
"Oops. Something went wrong. Please try again later."
);
}
alert("Thanks for reporting. We'll review this skin.");
return Actions.alert("Thanks for reporting. We'll review this skin.");
}),
ignoreElements()
filter(Boolean)
);
};
@ -473,5 +490,6 @@ export default combineEpics(
urlEpic,
loggingEpic,
skinDataEpic,
markNsfwEpic
markNsfwEpic,
alertEpic
);