From b98cbe9975bb8441e2546d1e2f6838efba98f8b3 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 18 Sep 2020 04:44:49 -0700 Subject: [PATCH] Updates to routes * The shortcode will only be pulled from here * Add an editable key to enable/disable editing the grid * Fix type erros with props.match --- src/components/WeaponGrid/WeaponGrid.tsx | 29 ++++++++++++++----- .../WeaponGridMainhand/WeaponGridMainhand.css | 2 +- .../WeaponGridMainhand/WeaponGridMainhand.tsx | 12 ++++++-- .../WeaponGridUnit/WeaponGridUnit.css | 2 +- .../WeaponGridUnit/WeaponGridUnit.tsx | 12 ++++++-- src/routes/New/New.tsx | 2 +- src/routes/Party/Party.tsx | 27 ++++++++++------- src/types/WeaponGridProps.d.ts | 1 + 8 files changed, 63 insertions(+), 24 deletions(-) diff --git a/src/components/WeaponGrid/WeaponGrid.tsx b/src/components/WeaponGrid/WeaponGrid.tsx index 53ea1246..ee8ca6c1 100644 --- a/src/components/WeaponGrid/WeaponGrid.tsx +++ b/src/components/WeaponGrid/WeaponGrid.tsx @@ -14,9 +14,14 @@ interface GridWeapon { weapon: Weapon } +interface Props { + shortcode: string + editable: boolean +} + type GridArray = { [key: number]: Weapon } -const WeaponGrid = (props: {}) => { +const WeaponGrid = (props: Props) => { const [partyId, setPartyId] = useState() const [shortcode, setShortcode] = useState() @@ -26,10 +31,8 @@ const WeaponGrid = (props: {}) => { const numWeapons: number = 9 useEffect(() => { - const shortcode = props.match.params.hash - - if (shortcode) { - fetchGrid(shortcode) + if (props.shortcode) { + fetchGrid(props.shortcode) } else { // There is no need to fetch a weapon } @@ -141,12 +144,24 @@ const WeaponGrid = (props: {}) => { return (
- +
    { Array.from(Array(numWeapons)).map((x, i) => { - return + return }) }
diff --git a/src/components/WeaponGridMainhand/WeaponGridMainhand.css b/src/components/WeaponGridMainhand/WeaponGridMainhand.css index bed958c8..a14187b8 100644 --- a/src/components/WeaponGridMainhand/WeaponGridMainhand.css +++ b/src/components/WeaponGridMainhand/WeaponGridMainhand.css @@ -12,7 +12,7 @@ width: 200px; } -.WeaponGridMainhand:hover { +.WeaponGridMainhand.editable:hover { border: 1px solid rgba(0, 0, 0, 0.1); box-shadow: rgba(0, 0, 0, 0.14) 0px 0px 14px; cursor: pointer; diff --git a/src/components/WeaponGridMainhand/WeaponGridMainhand.tsx b/src/components/WeaponGridMainhand/WeaponGridMainhand.tsx index a5f1c1f4..1f042a90 100644 --- a/src/components/WeaponGridMainhand/WeaponGridMainhand.tsx +++ b/src/components/WeaponGridMainhand/WeaponGridMainhand.tsx @@ -1,4 +1,5 @@ import React, { useEffect } from 'react' +import classnames from 'classnames' import SearchModal from '~components/SearchModal/SearchModal' import { useModal as useModal } from '~utils/useModal' @@ -20,11 +21,18 @@ function WeaponGridMainhand(props: WeaponGridProps) { imgSrc = mainhandImages[weapon.granblue_id] } + const openModalIfEditable = (props.editable) ? openModal : () => {} + + const classes = classnames({ + WeaponGridMainhand: true, + 'editable': props.editable + }) + return (
-
+
- + { (props.editable) ? : '' }
{open ? ( {} + + const classes = classnames({ + WeaponGridUnit: true, + 'editable': props.editable + }) + return (
  • -
    +
    - + { (props.editable) ? : '' }
    {open ? ( ( - + ) export default New \ No newline at end of file diff --git a/src/routes/Party/Party.tsx b/src/routes/Party/Party.tsx index 2c4551a6..2f52be9a 100644 --- a/src/routes/Party/Party.tsx +++ b/src/routes/Party/Party.tsx @@ -1,17 +1,24 @@ import React from 'react' -import { withRouter } from 'react-router' +import { RouteComponentProps, withRouter } from 'react-router' import WeaponGrid from '../../components/WeaponGrid/WeaponGrid' -class Party extends React.Component { - render() { - var hash = this.props.match.params.hash - return ( -
    - -
    - ) - } +interface RouterProps { + hash: string +} + +interface PartyProps extends RouteComponentProps { + +} + +const Party: React.FC = ({ match }) => { + const shortcode = match.params.hash || '' + + return ( +
    + +
    + ) } export default withRouter(Party) \ No newline at end of file diff --git a/src/types/WeaponGridProps.d.ts b/src/types/WeaponGridProps.d.ts index 6c408df6..b38ed193 100644 --- a/src/types/WeaponGridProps.d.ts +++ b/src/types/WeaponGridProps.d.ts @@ -2,4 +2,5 @@ interface WeaponGridProps { onReceiveData: (Weapon, number) => void weapon: Weapon | undefined position: number + editable: boolean } \ No newline at end of file