From ba52ba4fb09c1352a53e3cad6e6be2fc15988bde Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 19 Apr 2023 00:25:41 -0700 Subject: [PATCH] Move ExtraWeapons to ExtraWeaponsGrid And put it in ExtraContainer --- components/extra/ExtraWeaponsGrid/index.scss | 47 ++++++++++ components/extra/ExtraWeaponsGrid/index.tsx | 95 ++++++++++++++++++++ components/weapon/ExtraWeapons/index.scss | 59 ------------ components/weapon/ExtraWeapons/index.tsx | 48 ---------- components/weapon/WeaponGrid/index.tsx | 24 ++--- 5 files changed, 156 insertions(+), 117 deletions(-) create mode 100644 components/extra/ExtraWeaponsGrid/index.scss create mode 100644 components/extra/ExtraWeaponsGrid/index.tsx delete mode 100644 components/weapon/ExtraWeapons/index.scss delete mode 100644 components/weapon/ExtraWeapons/index.tsx diff --git a/components/extra/ExtraWeaponsGrid/index.scss b/components/extra/ExtraWeaponsGrid/index.scss new file mode 100644 index 00000000..e688f89f --- /dev/null +++ b/components/extra/ExtraWeaponsGrid/index.scss @@ -0,0 +1,47 @@ +.ExtraWeapons { + #ExtraWeaponGrid { + display: grid; + gap: $unit-3x; + grid-template-columns: repeat(3, minmax(0, 1fr)); + + @include breakpoint(tablet) { + gap: $unit-2x; + } + + @include breakpoint(phone) { + gap: $unit; + } + + .WeaponUnit { + .WeaponImage { + background: var(--extra-purple-card-bg); + + .icon svg { + fill: var(--extra-purple-secondary); + } + } + } + } + + .ExtraGrid.Weapons { + background: var(--extra-purple-bg); + border-radius: $card-corner; + box-sizing: border-box; + display: grid; + grid-template-columns: 1.42fr 3fr; + justify-content: center; + + @include breakpoint(tablet) { + left: auto; + max-width: auto; + width: 100%; + } + + @include breakpoint(phone) { + display: flex; + gap: $unit-2x; + padding: $unit-2x; + flex-direction: column; + } + } +} diff --git a/components/extra/ExtraWeaponsGrid/index.tsx b/components/extra/ExtraWeaponsGrid/index.tsx new file mode 100644 index 00000000..6dc39c6d --- /dev/null +++ b/components/extra/ExtraWeaponsGrid/index.tsx @@ -0,0 +1,95 @@ +import React, { useState } from 'react' +import { useTranslation } from 'next-i18next' +import Switch from '~components/common/Switch' +import WeaponUnit from '~components/weapon/WeaponUnit' + +import type { SearchableObject } from '~types' + +import './index.scss' +import classNames from 'classnames' + +// Props +interface Props { + grid: GridArray + enabled: boolean + editable: boolean + found?: boolean + offset: number + removeWeapon: (id: string) => void + updateExtra: (enabled: boolean) => void + updateObject: (object: SearchableObject, position: number) => void + updateUncap: (id: string, position: number, uncap: number) => void +} + +// Constants +const EXTRA_WEAPONS_COUNT = 3 + +const ExtraWeaponsGrid = ({ + grid, + enabled, + editable, + found, + offset, + removeWeapon, + updateExtra, + updateObject, + updateUncap, +}: Props) => { + const { t } = useTranslation('common') + + const classes = classNames({ + ExtraWeapons: true, + ContainerItem: true, + Disabled: !enabled, + }) + + function onCheckedChange(checked: boolean) { + updateExtra(checked) + } + + const disabledElement = <> + + const enabledElement = ( + + ) + + return ( +
+
+

{t('extra_weapons')}

+ {editable ? ( + + ) : ( + '' + )} +
+ {enabled ? enabledElement : ''} +
+ ) +} + +export default ExtraWeaponsGrid diff --git a/components/weapon/ExtraWeapons/index.scss b/components/weapon/ExtraWeapons/index.scss deleted file mode 100644 index d4cc6d5b..00000000 --- a/components/weapon/ExtraWeapons/index.scss +++ /dev/null @@ -1,59 +0,0 @@ -.ExtraGrid.Weapons { - background: var(--extra-purple-bg); - border-radius: $card-corner; - box-sizing: border-box; - display: grid; - grid-template-columns: 1.42fr 3fr; - justify-content: center; - margin: 20px auto; - max-width: calc($grid-width + 20px); - padding: $unit-2x $unit-2x $unit-2x 0; - position: relative; - left: $unit; - - @include breakpoint(tablet) { - left: auto; - max-width: auto; - width: 100%; - } - - @include breakpoint(phone) { - display: flex; - gap: $unit-2x; - padding: $unit-2x; - flex-direction: column; - } - - & > span { - color: var(--extra-purple-text); - display: flex; - align-items: center; - flex-grow: 1; - justify-content: center; - line-height: 1.2; - font-weight: 500; - text-align: center; - } - - #ExtraWeapons { - display: grid; - gap: $unit-3x; - grid-template-columns: repeat(3, minmax(0, 1fr)); - - @include breakpoint(tablet) { - gap: $unit-2x; - } - - @include breakpoint(phone) { - gap: $unit; - } - } - - .WeaponUnit .WeaponImage { - background: var(--extra-purple-card-bg); - } - - .WeaponUnit .WeaponImage .icon svg { - fill: var(--extra-purple-secondary); - } -} diff --git a/components/weapon/ExtraWeapons/index.tsx b/components/weapon/ExtraWeapons/index.tsx deleted file mode 100644 index 6c1ec552..00000000 --- a/components/weapon/ExtraWeapons/index.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import React from 'react' -import { useTranslation } from 'next-i18next' -import WeaponUnit from '~components/weapon/WeaponUnit' - -import type { SearchableObject } from '~types' - -import './index.scss' - -// Props -interface Props { - grid: GridArray - editable: boolean - found?: boolean - offset: number - removeWeapon: (id: string) => void - updateObject: (object: SearchableObject, position: number) => void - updateUncap: (id: string, position: number, uncap: number) => void -} - -const ExtraWeapons = (props: Props) => { - const numWeapons: number = 3 - const { t } = useTranslation('common') - - return ( -
- {t('extra_weapons')} -
    - {Array.from(Array(numWeapons)).map((x, i) => { - return ( -
  • - -
  • - ) - })} -
-
- ) -} - -export default ExtraWeapons diff --git a/components/weapon/WeaponGrid/index.tsx b/components/weapon/WeaponGrid/index.tsx index 36ba8843..4fd7419b 100644 --- a/components/weapon/WeaponGrid/index.tsx +++ b/components/weapon/WeaponGrid/index.tsx @@ -9,7 +9,7 @@ import debounce from 'lodash.debounce' import Alert from '~components/common/Alert' import WeaponUnit from '~components/weapon/WeaponUnit' -import ExtraWeapons from '~components/weapon/ExtraWeapons' +import ExtraWeaponsGrid from '~components/extra/ExtraWeaponsGrid' import WeaponConflictModal from '~components/weapon/WeaponConflictModal' import api from '~utils/api' @@ -348,15 +348,19 @@ const WeaponGrid = (props: Props) => { ) }) - const extraGridElement = ( - + const extraElement = ( + + + ) const conflictModal = () => {