diff --git a/quick-pokemon-type-matchup/src/App.jsx b/quick-pokemon-type-matchup/src/App.jsx
index aa825c7..1fca5f8 100644
--- a/quick-pokemon-type-matchup/src/App.jsx
+++ b/quick-pokemon-type-matchup/src/App.jsx
@@ -1,20 +1,22 @@
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useCallback } from 'react';
import { css } from '@emotion/react';
+import TypeChartSelector from './components/TypeChartSelector';
import TypeSelectList from './components/TypeSelectList';
import Information from './components/Information';
+import TypesMainLatest from './data/types_main_latest.json';
import './App.css';
function App() {
- const [types, setTypes] = useState([]);
+ const [types, setTypes] = useState(TypesMainLatest);
const [selectedTypes, setSelectedTypes] = useState([]);
- useEffect(() => {
- async function fetchData() {
- const response = await fetch('./types.json');
- setTypes(await response.json());
- }
- fetchData();
+ const updateTypes = useCallback((newTypes) => {
+ setTypes(newTypes);
+ }, []);
+
+ const updateSelectedTypes = useCallback((newSelectedTypes) => {
+ setSelectedTypes(newSelectedTypes);
}, []);
return (
@@ -29,13 +31,31 @@ function App() {
css={css`
width: 14rem;
height: 100dvh;
- overflow-y: scroll;
@media (max-width: 1000px) {
width: 7rem;
}
+ display: flex;
+ flex-direction: column;
`}
>
-
+
+
+
+
{
`}
>
{theirTypes.map((type, i) => (
- <>
-
+
+
{i < theirTypes.length - 1 ? ', ' : ''}
- >
+
))}
diff --git a/quick-pokemon-type-matchup/src/components/TypeChartSelector.jsx b/quick-pokemon-type-matchup/src/components/TypeChartSelector.jsx
new file mode 100644
index 0000000..5cc4f98
--- /dev/null
+++ b/quick-pokemon-type-matchup/src/components/TypeChartSelector.jsx
@@ -0,0 +1,69 @@
+import { useState } from 'react';
+import { css } from '@emotion/react';
+
+import TypesMainGen1 from '../data/types_main_gen1.json';
+import TypesMainGen2 from '../data/types_main_gen2_5.json';
+import TypesMainLatest from '../data/types_main_latest.json';
+
+const TYPE_OPTIONS = ['main_gen1', 'main_gen2_5', 'main_latest'];
+
+const DEFAULT_OPTION = 'main_latest';
+
+const TYPE_DATA_MAP = {
+ main_gen1: TypesMainGen1,
+ main_gen2_5: TypesMainGen2,
+ main_latest: TypesMainLatest,
+};
+
+const TYPE_OPTION_LABEL_MAP = {
+ main_gen1: 'Gen 1',
+ main_gen2_5: 'Gen 2 - 5',
+ main_latest: 'Gen 6+',
+};
+
+const TypeChartSelector = ({ setTypesCallback, className }) => {
+ const [selectedOption, setSelectedOption] = useState(DEFAULT_OPTION);
+
+ const updateOption = (newOption) => {
+ setSelectedOption(newOption);
+ setTypesCallback(TYPE_DATA_MAP[newOption]);
+ };
+
+ return (
+
+
+ Type set:
+
+
+
+ );
+};
+
+export default TypeChartSelector;
diff --git a/quick-pokemon-type-matchup/src/components/TypeSelectList.jsx b/quick-pokemon-type-matchup/src/components/TypeSelectList.jsx
index a0b7b26..1bd786c 100644
--- a/quick-pokemon-type-matchup/src/components/TypeSelectList.jsx
+++ b/quick-pokemon-type-matchup/src/components/TypeSelectList.jsx
@@ -1,32 +1,42 @@
-import { useState, useEffect, useCallback } from 'react';
+import { useState, useEffect, useRef, useCallback } from 'react';
import { css } from '@emotion/react';
import { MAXIMUM_TYPES_SELECTED } from '../constants';
import TypeViewButton from './TypeViewButton';
const TypeSelectList = ({ types, updateSelectedTypes }) => {
+ const typeReferenceTracker = useRef(null);
const [selected, setSelected] = useState([]);
- const toggleSelected = useCallback((type) => {
- setSelected((previous) => {
- let newSelected = [];
-
- if (previous.includes(type)) {
- newSelected = previous.filter((x) => x.name != type.name);
+ const toggleSelected = useCallback(
+ (type) => {
+ let newSelected;
+ if (selected.includes(type)) {
+ newSelected = selected.filter((x) => x.name != type.name);
} else {
- newSelected = [...previous, type];
+ newSelected = [...selected, type];
}
if (newSelected.length > MAXIMUM_TYPES_SELECTED) {
newSelected = newSelected.slice(1);
}
- return newSelected;
- });
- }, []);
+ setSelected(newSelected);
+ updateSelectedTypes(newSelected);
+ },
+ [selected]
+ );
useEffect(() => {
- updateSelectedTypes(selected);
- }, [selected]);
+ if (typeReferenceTracker.current != types) {
+ typeReferenceTracker.current = types;
+ const selectedNames = selected.map((y) => y.name);
+ const newSelected = types.filter((x) => selectedNames.includes(x.name));
+ setSelected(newSelected);
+ updateSelectedTypes(newSelected);
+ }
+ }, [types, selected]);
+
+ const selectedNames = selected.map((x) => x.name);
return (
{
-
diff --git a/quick-pokemon-type-matchup/src/components/YourTypeReadout.jsx b/quick-pokemon-type-matchup/src/components/YourTypeReadout.jsx
index f6b6e7b..e0a122d 100644
--- a/quick-pokemon-type-matchup/src/components/YourTypeReadout.jsx
+++ b/quick-pokemon-type-matchup/src/components/YourTypeReadout.jsx
@@ -1,3 +1,4 @@
+import React from 'react';
import TypeViewText from './TypeViewText';
const YourTypeReadout = ({ selectedTypes }) => {
@@ -5,9 +6,9 @@ const YourTypeReadout = ({ selectedTypes }) => {
You are a{'aeiou'.includes(selectedTypes[0].name[0]) ? 'n' : ''}{' '}
{selectedTypes.map((x) => (
- <>
- {' '}
- >
+
+ {' '}
+
))}
Pokémon!
diff --git a/quick-pokemon-type-matchup/src/data/types_main_gen1.json b/quick-pokemon-type-matchup/src/data/types_main_gen1.json
new file mode 100644
index 0000000..9785f45
--- /dev/null
+++ b/quick-pokemon-type-matchup/src/data/types_main_gen1.json
@@ -0,0 +1,107 @@
+[
+ {
+ "name": "normal",
+ "color": "#A0A0A0",
+ "superEffective": [],
+ "notVeryEffective": ["rock"],
+ "noEffect": ["ghost"]
+ },
+ {
+ "name": "fire",
+ "color": "#FFAA66",
+ "superEffective": ["grass", "ice", "bug"],
+ "notVeryEffective": ["fire", "water", "rock", "dragon"],
+ "noEffect": []
+ },
+ {
+ "name": "water",
+ "color": "#66AAFF",
+ "superEffective": ["fire", "ground", "rock"],
+ "notVeryEffective": ["water", "grass", "dragon"],
+ "noEffect": []
+ },
+ {
+ "name": "electric",
+ "color": "#FFDC60",
+ "superEffective": ["water", "flying"],
+ "notVeryEffective": ["electric", "grass", "dragon"],
+ "noEffect": ["ground"]
+ },
+ {
+ "name": "grass",
+ "color": "#6AD854",
+ "superEffective": ["water", "ground", "rock"],
+ "notVeryEffective": ["fire", "grass", "poison", "flying", "bug", "dragon"],
+ "noEffect": []
+ },
+ {
+ "name": "ice",
+ "color": "#B6EAE4",
+ "superEffective": ["grass", "ground", "flying", "dragon"],
+ "notVeryEffective": ["water", "ice"],
+ "noEffect": []
+ },
+ {
+ "name": "fighting",
+ "color": "#E85564",
+ "superEffective": ["normal", "ice", "rock"],
+ "notVeryEffective": ["poison", "flying", "psychic", "bug"],
+ "noEffect": ["ghost"]
+ },
+ {
+ "name": "poison",
+ "color": "#BC74B1",
+ "superEffective": ["grass", "bug"],
+ "notVeryEffective": ["poison", "ground", "rock", "ghost"],
+ "noEffect": []
+ },
+ {
+ "name": "ground",
+ "color": "#BA7A5D",
+ "superEffective": ["fire", "electric", "poison", "rock"],
+ "notVeryEffective": ["grass", "bug"],
+ "noEffect": ["flying"]
+ },
+ {
+ "name": "flying",
+ "color": "#AABFE2",
+ "superEffective": ["grass", "fighting", "bug"],
+ "notVeryEffective": ["electric", "rock"],
+ "noEffect": []
+ },
+ {
+ "name": "psychic",
+ "color": "#E07277",
+ "superEffective": ["fighting", "poison"],
+ "notVeryEffective": ["psychic"],
+ "noEffect": []
+ },
+ {
+ "name": "bug",
+ "color": "#ADDD82",
+ "superEffective": ["grass", "psychic", "poison"],
+ "notVeryEffective": ["fire", "fighting", "flying", "ghost"],
+ "noEffect": []
+ },
+ {
+ "name": "rock",
+ "color": "#DBD0B3",
+ "superEffective": ["fire", "ice", "flying", "bug"],
+ "notVeryEffective": ["fighting", "ground"],
+ "noEffect": []
+ },
+ {
+ "name": "ghost",
+ "color": "#7488BC",
+ "superEffective": ["ghost"],
+ "notVeryEffective": [],
+ "noEffect": ["normal", "psychic"]
+ },
+ {
+ "name": "dragon",
+ "color": "#3276B5",
+ "superEffective": ["dragon"],
+ "notVeryEffective": [],
+ "noEffect": []
+ }
+]
diff --git a/quick-pokemon-type-matchup/src/data/types_main_gen2_5.json b/quick-pokemon-type-matchup/src/data/types_main_gen2_5.json
new file mode 100644
index 0000000..edf5646
--- /dev/null
+++ b/quick-pokemon-type-matchup/src/data/types_main_gen2_5.json
@@ -0,0 +1,136 @@
+[
+ {
+ "name": "normal",
+ "color": "#A0A0A0",
+ "superEffective": [],
+ "notVeryEffective": ["rock", "steel"],
+ "noEffect": ["ghost"]
+ },
+ {
+ "name": "fire",
+ "color": "#FFAA66",
+ "superEffective": ["grass", "ice", "bug", "steel"],
+ "notVeryEffective": ["fire", "water", "rock", "dragon"],
+ "noEffect": []
+ },
+ {
+ "name": "water",
+ "color": "#66AAFF",
+ "superEffective": ["fire", "ground", "rock"],
+ "notVeryEffective": ["water", "grass", "dragon"],
+ "noEffect": []
+ },
+ {
+ "name": "electric",
+ "color": "#FFDC60",
+ "superEffective": ["water", "flying"],
+ "notVeryEffective": ["electric", "grass", "dragon"],
+ "noEffect": ["ground"]
+ },
+ {
+ "name": "grass",
+ "color": "#6AD854",
+ "superEffective": ["water", "ground", "rock"],
+ "notVeryEffective": [
+ "fire",
+ "grass",
+ "poison",
+ "flying",
+ "bug",
+ "dragon",
+ "steel"
+ ],
+ "noEffect": []
+ },
+ {
+ "name": "ice",
+ "color": "#B6EAE4",
+ "superEffective": ["grass", "ground", "flying", "dragon"],
+ "notVeryEffective": ["fire", "water", "ice", "steel"],
+ "noEffect": []
+ },
+ {
+ "name": "fighting",
+ "color": "#E85564",
+ "superEffective": ["normal", "ice", "rock", "dark", "steel"],
+ "notVeryEffective": ["poison", "flying", "psychic", "bug"],
+ "noEffect": ["ghost"]
+ },
+ {
+ "name": "poison",
+ "color": "#BC74B1",
+ "superEffective": ["grass"],
+ "notVeryEffective": ["poison", "ground", "rock", "ghost"],
+ "noEffect": ["steel"]
+ },
+ {
+ "name": "ground",
+ "color": "#BA7A5D",
+ "superEffective": ["fire", "electric", "poison", "rock", "steel"],
+ "notVeryEffective": ["grass", "bug"],
+ "noEffect": ["flying"]
+ },
+ {
+ "name": "flying",
+ "color": "#AABFE2",
+ "superEffective": ["grass", "fighting", "bug"],
+ "notVeryEffective": ["electric", "rock", "steel"],
+ "noEffect": []
+ },
+ {
+ "name": "psychic",
+ "color": "#E07277",
+ "superEffective": ["fighting", "poison"],
+ "notVeryEffective": ["psychic", "steel"],
+ "noEffect": ["dark"]
+ },
+ {
+ "name": "bug",
+ "color": "#ADDD82",
+ "superEffective": ["grass", "psychic", "dark"],
+ "notVeryEffective": [
+ "fire",
+ "fighting",
+ "poison",
+ "flying",
+ "ghost",
+ "steel"
+ ],
+ "noEffect": []
+ },
+ {
+ "name": "rock",
+ "color": "#DBD0B3",
+ "superEffective": ["fire", "ice", "flying", "bug"],
+ "notVeryEffective": ["fighting", "ground", "steel"],
+ "noEffect": []
+ },
+ {
+ "name": "ghost",
+ "color": "#7488BC",
+ "superEffective": ["psychic", "ghost"],
+ "notVeryEffective": ["dark", "steel"],
+ "noEffect": ["normal"]
+ },
+ {
+ "name": "dragon",
+ "color": "#3276B5",
+ "superEffective": ["dragon"],
+ "notVeryEffective": ["steel"],
+ "noEffect": []
+ },
+ {
+ "name": "dark",
+ "color": "#5C5460",
+ "superEffective": ["psychic", "ghost"],
+ "notVeryEffective": ["fighting", "dark", "steel"],
+ "noEffect": []
+ },
+ {
+ "name": "steel",
+ "color": "#8BABB7",
+ "superEffective": ["ice", "rock"],
+ "notVeryEffective": ["fire", "water", "electric", "steel"],
+ "noEffect": []
+ }
+]
diff --git a/quick-pokemon-type-matchup/public/types.json b/quick-pokemon-type-matchup/src/data/types_main_latest.json
similarity index 91%
rename from quick-pokemon-type-matchup/public/types.json
rename to quick-pokemon-type-matchup/src/data/types_main_latest.json
index 8915fd8..cb677c0 100644
--- a/quick-pokemon-type-matchup/public/types.json
+++ b/quick-pokemon-type-matchup/src/data/types_main_latest.json
@@ -31,7 +31,15 @@
"name": "grass",
"color": "#6AD854",
"superEffective": ["water", "ground", "rock"],
- "notVeryEffective": ["fire", "grass", "poison", "flying", "bug", "dragon", "steel"],
+ "notVeryEffective": [
+ "fire",
+ "grass",
+ "poison",
+ "flying",
+ "bug",
+ "dragon",
+ "steel"
+ ],
"noEffect": []
},
{
@@ -80,7 +88,15 @@
"name": "bug",
"color": "#ADDD82",
"superEffective": ["grass", "psychic", "dark"],
- "notVeryEffective": ["fire", "fighting", "poison", "flying", "ghost", "steel", "fairy"],
+ "notVeryEffective": [
+ "fire",
+ "fighting",
+ "poison",
+ "flying",
+ "ghost",
+ "steel",
+ "fairy"
+ ],
"noEffect": []
},
{
@@ -125,4 +141,4 @@
"notVeryEffective": ["fire", "poison", "steel"],
"noEffect": []
}
-]
\ No newline at end of file
+]