Skip to content

Commit

Permalink
chore: add no-redeclare lint flag
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaRamirez committed Mar 5, 2023
1 parent f9551ab commit de1520e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export * from './updateEditorHistory';
export * from './triggerDownload';
export * from './toggleDialog';
export * from './setEditorHistoryEnabled';
export * from './updateExcludedAreas';
13 changes: 13 additions & 0 deletions src/actions/updateExcludedAreas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/no-redeclare */
import { Action } from 'actions';

export type UPDATE_EXCLUDED_AREAS = 'UPDATE_EXCLUDED_AREAS';
export const UPDATE_EXCLUDED_AREAS: UPDATE_EXCLUDED_AREAS = 'UPDATE_EXCLUDED_AREAS';

export type updateExcludedAreas = (excludedAreas: string[]) => Action<UPDATE_EXCLUDED_AREAS>;
export const updateExcludedAreas = (excludedAreas: string[]): Action<UPDATE_EXCLUDED_AREAS> => {
return {
type: UPDATE_EXCLUDED_AREAS,
excludedAreas,
};
};
17 changes: 10 additions & 7 deletions src/components/PokemonEditor/PokemonLocationChecklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { State } from 'state';
import { PokemonIcon } from 'components/PokemonIcon';
import { Callout, Classes, Icon, Intent, TextArea, Tooltip } from '@blueprintjs/core';
import { cx } from 'emotion';
import { useDispatch, useSelector } from 'react-redux';
import { updateExcludedAreas } from 'actions';


const LocationIcon = ({ area, currentGame, excludeGifts, pokemon }) => {
Expand Down Expand Up @@ -65,16 +67,17 @@ export const PokemonLocationChecklist = ({

const [excludeGifts, setExcludeGifts] = React.useState(false);
const [currentGame, setCurrentGame] = React.useState<GameName>('None');
const [excludedAreas, setExcludedAreas] = React.useState<string[]>([]);
const excludedAreas = useSelector<State, State['excludedAreas']>(state => state.excludedAreas);
const dispatch = useDispatch();
const encounterMap = React.useMemo(() => getEncounterMap(game.name).filter(area => !excludedAreas.includes(area)), [game.name, excludedAreas]);
const totals = React.useMemo(() => calcTotals(boxes, pokemon, encounterMap, currentGame), [boxes, JSON.stringify(pokemon), encounterMap, currentGame]);

const hideArea = (area: string) => () => setExcludedAreas(areas => [...areas, area]);
const hideArea = (area: string) => () => dispatch(updateExcludedAreas([...excludedAreas, area]));

const updateExcludedAreas = (event) => {
const updateExcludedAreasFromText = (event) => {
const value = event.currentTarget.value;
const areas = value.split('\n');
setExcludedAreas(areas);
updateExcludedAreas(areas);
};

const colors = ['#0e1d6b', '#468189', '#77ACA2', '#9DBEBB', '#F4E9CD', '#0DAB76', '#139A43', '#D4AFB9', '#9CADCE'];
Expand All @@ -83,7 +86,7 @@ export const PokemonLocationChecklist = ({
return <Tooltip content={
<>
{percentages.map((percentage, idx) => <div>
<div style={{ display: 'inline-block', width: '0.5rem', height: '0.5rem', borderRadius: '50%', background: colors[idx], marginRight: '0.25rem' }}></div>
<div key={percentage.key} style={{ display: 'inline-block', width: '0.5rem', height: '0.5rem', borderRadius: '50%', background: colors[idx], marginRight: '0.25rem' }}></div>
{percentage.key}: {percentage.percentage}
</div>)}
</>
Expand Down Expand Up @@ -153,8 +156,8 @@ export const PokemonLocationChecklist = ({
</label>
<TextArea
name='excludedAreas'
onChange={updateExcludedAreas}
value={excludedAreas.join('\n')}
onChange={updateExcludedAreasFromText}
defaultValue={excludedAreas.join('\n')}
/>
</div>
<Callout intent={Intent.WARNING} style={{ fontSize: '80%', marginTop: '0.5rem' }}>
Expand Down
15 changes: 15 additions & 0 deletions src/reducers/excludedAreas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Action, UPDATE_EXCLUDED_AREAS, REPLACE_STATE } from '../actions';

export function excludedAreas(
state: string[] = [],
action: Action<UPDATE_EXCLUDED_AREAS | REPLACE_STATE>,
) {
switch (action.type) {
case UPDATE_EXCLUDED_AREAS:
return action.excludedAreas;
case REPLACE_STATE:
return action.replaceWith.excludedAreas;
default:
return state;
}
}
2 changes: 2 additions & 0 deletions src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { customMoveMap } from './customMoveMap';
import { stats } from './stats';
import { customTypes } from './customTypes';
import { editorHistory } from './editorHistory';
import { excludedAreas } from './excludedAreas';
import { view } from './view';

export const reducers = {
Expand All @@ -26,6 +27,7 @@ export const reducers = {
customMoveMap,
customTypes,
editorHistory,
excludedAreas,
game,
nuzlockes,
pokemon,
Expand Down
1 change: 1 addition & 0 deletions src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface State {
confirmation: boolean;
checkpoints: Checkpoints;
editor: Editor;
excludedAreas: string[];
game: Game;
pokemon: Pokemon[];
rules: string[];
Expand Down

0 comments on commit de1520e

Please sign in to comment.