From 93f76494068ab10bbb05d9f2f07f72e74da894fb Mon Sep 17 00:00:00 2001 From: ahmedmgamal94 <98055904+ahmedmgamal94@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:54:52 -0700 Subject: [PATCH 1/2] added icon and name two exotic class item combo --- .../armor-optimization/ExoticSelector.tsx | 195 +++++++++++------- 1 file changed, 123 insertions(+), 72 deletions(-) diff --git a/src/features/armor-optimization/ExoticSelector.tsx b/src/features/armor-optimization/ExoticSelector.tsx index 8c2b655..9117da2 100644 --- a/src/features/armor-optimization/ExoticSelector.tsx +++ b/src/features/armor-optimization/ExoticSelector.tsx @@ -94,11 +94,35 @@ const StyledPopper = styled(Popper)({ }, }); +const ComboOption = styled('div')({ + display: 'flex', + flexDirection: 'column', + width: '100%', +}); + +const ComboItem = styled('div')({ + display: 'flex', + alignItems: 'center', + marginBottom: '4px', +}); + +const ComboIcon = styled('img')({ + width: '24px', + height: '24px', + marginRight: '8px', +}); + interface ExoticSelectorProps { selectedCharacter: Character | undefined; selectedExoticItemHash: number | null; } +interface IntrinsicMod { + itemHash: number; + name: string; + icon: string; +} + const ExoticSelector: React.FC = ({ selectedCharacter, selectedExoticItemHash, @@ -109,6 +133,7 @@ const ExoticSelector: React.FC = ({ const [selectedExotic, setSelectedExotic] = useState(null); const [selectedCombo, setSelectedCombo] = useState(null); const [inputValue, setInputValue] = React.useState(''); + const [intrinsicMods, setIntrinsicMods] = useState<{ [key: number]: IntrinsicMod }>({}); const exoticClassCombos = selectedCharacter?.exoticClassCombos; const fetchExoticData = async () => { @@ -121,8 +146,32 @@ const ExoticSelector: React.FC = ({ } }; + const fetchIntrinsicModData = async () => { + if (exoticClassCombos) { + const hashes = new Set( + exoticClassCombos.flatMap((combo) => [combo.firstIntrinsicHash, combo.secondIntrinsicHash]) + ); + const modsData = await db.manifestIntrinsicModDef + .where('itemHash') + .anyOf([...hashes]) + .toArray(); + + const modsMap = modsData.reduce((acc, mod) => { + acc[mod.itemHash] = { + itemHash: mod.itemHash, + name: mod.name, + icon: mod.icon, + }; + return acc; + }, {} as { [key: number]: IntrinsicMod }); + + setIntrinsicMods(modsMap); + } + }; + useEffect(() => { fetchExoticData(); + fetchIntrinsicModData(); }, [selectedCharacter]); useEffect(() => { @@ -231,82 +280,84 @@ const ExoticSelector: React.FC = ({ ) : (
- {selectedExotic && ( - <> - - {selectedExotic.slot === ARMOR.CLASS_ARMOR && ( - - handleExoticClassComboSelect(newValue as ExoticClassCombo | null) - } - inputValue={comboInput} - onInputChange={(event, newInputValue) => { - setComboInput(newInputValue); - }} - options={exoticClassCombos ? exoticClassCombos : []} - getOptionLabel={(option: ExoticClassCombo) => - String(option.firstIntrinsicHash) + ' & ' + String(option.secondIntrinsicHash) - } - sx={{ width: 250 }} - PopperComponent={StyledPopper} - renderOption={(props, option) => { - const { key, ...otherProps } = props; - return ( -
  • -
    - {option.firstIntrinsicHash} - {' & '} - {option.secondIntrinsicHash} -
    -
  • - ); + + {selectedExotic.slot === ARMOR.CLASS_ARMOR && ( + + handleExoticClassComboSelect(newValue as ExoticClassCombo | null) + } + inputValue={comboInput} + onInputChange={(event, newInputValue) => { + setComboInput(newInputValue); + }} + options={exoticClassCombos ? exoticClassCombos : []} + getOptionLabel={(option: ExoticClassCombo) => { + const first = intrinsicMods[option.firstIntrinsicHash]; + const second = intrinsicMods[option.secondIntrinsicHash]; + return `${first?.name || ''} / ${second?.name || ''}`; + }} + sx={{ width: 300 }} + PopperComponent={StyledPopper} + renderOption={(props, option) => { + const { key, ...otherProps } = props; + const first = intrinsicMods[option.firstIntrinsicHash]; + const second = intrinsicMods[option.secondIntrinsicHash]; + return ( +
  • + + + {first && } + {first?.name || ''} + + + {second && } + {second?.name || ''} + + +
  • + ); + }} + renderInput={(params) => ( + ( - - )} /> )} - - - - + /> )} + + +
    )} From 1fca152dfb3d3047975f7549e7603699d8fda9db Mon Sep 17 00:00:00 2001 From: ahmedmgamal94 <98055904+ahmedmgamal94@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:43:21 -0700 Subject: [PATCH 2/2] fixed exotic not clearing bug --- src/app/routes/Dashboard.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/routes/Dashboard.tsx b/src/app/routes/Dashboard.tsx index 63acfab..88d60ab 100644 --- a/src/app/routes/Dashboard.tsx +++ b/src/app/routes/Dashboard.tsx @@ -21,6 +21,10 @@ import LoadoutCustomization from '../../components/LoadoutCustomization'; import greyBackground from '../../assets/grey.png'; import ExoticSelector from '../../features/armor-optimization/ExoticSelector'; import { DAMAGE_TYPE } from '../../lib/bungie_api/constants'; +import { + updateSelectedExoticClassCombo, + updateSelectedExoticItemHash, +} from '../../store/DashboardReducer'; const PageContainer = styled('div')({ display: 'flex', @@ -195,6 +199,8 @@ export const Dashboard: React.FC = () => { const handleCharacterClick = (character: Character) => { dispatch(updateSelectedCharacter(character)); + dispatch(updateSelectedExoticItemHash({ itemHash: null, slot: null })); + dispatch(updateSelectedExoticClassCombo(null)); }; const handleSubclassSelect = (subclass: SubclassConfig) => {