Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Mar 6, 2024
1 parent 202ba8f commit 5917b93
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/TrackerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import Settings from './permalink/Settings';
import Logic from './logic/Logic';
import Tracker from './Tracker';
import { parseError } from './utils/Error';

export default function TrackerContainer() {
const dispatch = useDispatch();
Expand All @@ -30,7 +31,7 @@ export default function TrackerContainer() {
loadLogic({ logic, options: settings.allOptions, source }),
);
} catch (e) {
dispatch(setLoadingError({ error: e && typeof e === 'object' && 'message' in e ? e.message as string : JSON.stringify(e) }));
dispatch(setLoadingError({ error: parseError(e) }));
} finally {
setLoadingSource(undefined);
}
Expand Down
20 changes: 15 additions & 5 deletions src/selectors/Dungeons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,24 @@ export const dungeonCompletedSelector = currySelector(
settingsSelector,
(_state: RootState, dungeon: string) => dungeon,
],
(checkedChecks, inventory, settings, dungeon: string) =>
dungeon !== 'Sky Keep'
? Boolean(
(checkedChecks, inventory, settings, dungeon: string) => {
if (dungeon === 'Sky Keep') {
// Sky Keep is shown as "completed" if it contains the Triforces
// and you found them all.
return (
settings.getOption('Triforce Shuffle') !== 'Anywhere' &&
inventory['Triforce'] === 3
);
} else {
// Otherwise you need to have the specific completion requirement,
// e.g. "Strike Crest"
return Boolean(
checkedChecks.some(
(check) =>
check === dungeonCompletionRequirements[dungeon],
),
)
: settings.getOption('Triforce Shuffle') !== 'Anywhere' && inventory['Triforce'] === 3,
);
}
}
),
);
4 changes: 2 additions & 2 deletions src/state/Logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface LogicState {
/** The ssrando branch/tag we have loaded our files from. */
source: string | undefined;
/** The error that occured in loading, if any. */
error: unknown | undefined;
error: string | undefined;
}

const initialState: LogicState = {
Expand All @@ -37,7 +37,7 @@ const logicSlice = createSlice({
state.source = source;
state.error = undefined;
},
setLoadingError: (state, action: PayloadAction<{ error: unknown }>) => {
setLoadingError: (state, action: PayloadAction<{ error: string }>) => {
const { error } = action.payload;
if (!state.logic) {
state.error = error;
Expand Down
7 changes: 3 additions & 4 deletions src/state/Tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ const trackerSlice = createSlice({
action: PayloadAction<{ checkId: string; markChecked?: boolean }>,
) => {
const { checkId, markChecked } = action.payload;
const add =
markChecked !== undefined
? markChecked
: !state.checkedChecks.some((check) => checkId === check);
const add = markChecked !== undefined
? markChecked
: !state.checkedChecks.includes(checkId);
if (add) {
state.checkedChecks.push(checkId);
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/Error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function parseError(error: unknown): string {
return error instanceof Error
? error.message
: JSON.stringify(error);
}

0 comments on commit 5917b93

Please sign in to comment.