Implement removing Characters and Weapons
This commit is contained in:
parent
23c520f549
commit
cc7051fc8f
6 changed files with 38 additions and 9 deletions
|
|
@ -39,7 +39,7 @@ const Alert = (props: Props) => {
|
||||||
<AlertDialog.Action asChild>
|
<AlertDialog.Action asChild>
|
||||||
<Button
|
<Button
|
||||||
contained={true}
|
contained={true}
|
||||||
onClick={props.cancelAction}
|
onClick={props.primaryAction}
|
||||||
text={props.primaryActionText}
|
text={props.primaryActionText}
|
||||||
/>
|
/>
|
||||||
</AlertDialog.Action>
|
</AlertDialog.Action>
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,15 @@ const CharacterGrid = (props: Props) => {
|
||||||
setIncoming(undefined)
|
setIncoming(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function removeCharacter(id: string) {
|
||||||
|
try {
|
||||||
|
const response = await api.endpoints.grid_characters.destroy({ id: id })
|
||||||
|
appState.grid.characters[response.data.position] = undefined
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Methods: Saving job and job skills
|
// Methods: Saving job and job skills
|
||||||
const saveJob = async function (job?: Job) {
|
const saveJob = async function (job?: Job) {
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
@ -371,6 +380,7 @@ const CharacterGrid = (props: Props) => {
|
||||||
position={i}
|
position={i}
|
||||||
updateObject={receiveCharacterFromSearch}
|
updateObject={receiveCharacterFromSearch}
|
||||||
updateUncap={initiateUncapUpdate}
|
updateUncap={initiateUncapUpdate}
|
||||||
|
removeCharacter={removeCharacter}
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,18 @@ import { useTranslation } from 'next-i18next'
|
||||||
import { AxiosResponse } from 'axios'
|
import { AxiosResponse } from 'axios'
|
||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
|
|
||||||
|
import Alert from '~components/Alert'
|
||||||
import WeaponUnit from '~components/WeaponUnit'
|
import WeaponUnit from '~components/WeaponUnit'
|
||||||
import ExtraWeapons from '~components/ExtraWeapons'
|
import ExtraWeapons from '~components/ExtraWeapons'
|
||||||
|
import WeaponConflictModal from '~components/WeaponConflictModal'
|
||||||
|
|
||||||
import api from '~utils/api'
|
import api from '~utils/api'
|
||||||
import { appState } from '~utils/appState'
|
import { appState } from '~utils/appState'
|
||||||
|
import { accountState } from '~utils/accountState'
|
||||||
|
|
||||||
import type { DetailsObject, SearchableObject } from '~types'
|
import type { DetailsObject, SearchableObject } from '~types'
|
||||||
|
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
import WeaponConflictModal from '~components/WeaponConflictModal'
|
|
||||||
import Alert from '~components/Alert'
|
|
||||||
import { accountState } from '~utils/accountState'
|
|
||||||
|
|
||||||
// Props
|
// Props
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -198,6 +198,21 @@ const WeaponGrid = (props: Props) => {
|
||||||
setIncoming(undefined)
|
setIncoming(undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function removeWeapon(id: string) {
|
||||||
|
try {
|
||||||
|
const response = await api.endpoints.grid_weapons.destroy({ id: id })
|
||||||
|
const data = response.data
|
||||||
|
|
||||||
|
if (data.position === -1) {
|
||||||
|
appState.grid.weapons.mainWeapon = undefined
|
||||||
|
} else {
|
||||||
|
appState.grid.weapons.allWeapons[response.data.position] = undefined
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Methods: Updating uncap level
|
// Methods: Updating uncap level
|
||||||
// Note: Saves, but debouncing is not working properly
|
// Note: Saves, but debouncing is not working properly
|
||||||
async function saveUncap(id: string, position: number, uncapLevel: number) {
|
async function saveUncap(id: string, position: number, uncapLevel: number) {
|
||||||
|
|
@ -254,7 +269,7 @@ const WeaponGrid = (props: Props) => {
|
||||||
)
|
)
|
||||||
|
|
||||||
const updateUncapLevel = (position: number, uncapLevel: number) => {
|
const updateUncapLevel = (position: number, uncapLevel: number) => {
|
||||||
console.log(`Updating uncap level at position ${position} to ${uncapLevel}`)
|
// console.log(`Updating uncap level at position ${position} to ${uncapLevel}`)
|
||||||
if (appState.grid.weapons.mainWeapon && position == -1)
|
if (appState.grid.weapons.mainWeapon && position == -1)
|
||||||
appState.grid.weapons.mainWeapon.uncap_level = uncapLevel
|
appState.grid.weapons.mainWeapon.uncap_level = uncapLevel
|
||||||
else {
|
else {
|
||||||
|
|
@ -292,6 +307,7 @@ const WeaponGrid = (props: Props) => {
|
||||||
key="grid_mainhand"
|
key="grid_mainhand"
|
||||||
position={-1}
|
position={-1}
|
||||||
unitType={0}
|
unitType={0}
|
||||||
|
removeWeapon={removeWeapon}
|
||||||
updateObject={receiveWeaponFromSearch}
|
updateObject={receiveWeaponFromSearch}
|
||||||
updateUncap={initiateUncapUpdate}
|
updateUncap={initiateUncapUpdate}
|
||||||
/>
|
/>
|
||||||
|
|
@ -305,6 +321,7 @@ const WeaponGrid = (props: Props) => {
|
||||||
editable={party.editable}
|
editable={party.editable}
|
||||||
position={i}
|
position={i}
|
||||||
unitType={1}
|
unitType={1}
|
||||||
|
removeWeapon={removeWeapon}
|
||||||
updateObject={receiveWeaponFromSearch}
|
updateObject={receiveWeaponFromSearch}
|
||||||
updateUncap={initiateUncapUpdate}
|
updateUncap={initiateUncapUpdate}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -480,11 +480,11 @@ const WeaponUnit = ({
|
||||||
<Alert
|
<Alert
|
||||||
open={alertOpen}
|
open={alertOpen}
|
||||||
primaryAction={removeWeapon}
|
primaryAction={removeWeapon}
|
||||||
primaryActionText={t('modals.weapons.buttons.remove')}
|
primaryActionText={t('modals.weapon.buttons.remove')}
|
||||||
cancelAction={() => setAlertOpen(false)}
|
cancelAction={() => setAlertOpen(false)}
|
||||||
cancelActionText={t('buttons.cancel')}
|
cancelActionText={t('buttons.cancel')}
|
||||||
message={
|
message={
|
||||||
<Trans i18nKey="modals.characters.messages.remove">
|
<Trans i18nKey="modals.weapons.messages.remove">
|
||||||
Are you sure you want to remove{' '}
|
Are you sure you want to remove{' '}
|
||||||
<strong>{{ weapon: gridWeapon?.object.name[locale] }}</strong> from
|
<strong>{{ weapon: gridWeapon?.object.name[locale] }}</strong> from
|
||||||
your team?
|
your team?
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,8 @@
|
||||||
"weapon": {
|
"weapon": {
|
||||||
"title": "Modify Weapon",
|
"title": "Modify Weapon",
|
||||||
"buttons": {
|
"buttons": {
|
||||||
"confirm": "Save weapon"
|
"confirm": "Save weapon",
|
||||||
|
"remove": "Remove weapon"
|
||||||
},
|
},
|
||||||
"subtitles": {
|
"subtitles": {
|
||||||
"element": "Element",
|
"element": "Element",
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,8 @@
|
||||||
"weapon": {
|
"weapon": {
|
||||||
"title": "武器変更",
|
"title": "武器変更",
|
||||||
"buttons": {
|
"buttons": {
|
||||||
"confirm": "武器を変更する"
|
"confirm": "武器を変更する",
|
||||||
|
"remove": "武器を削除する"
|
||||||
},
|
},
|
||||||
"subtitles": {
|
"subtitles": {
|
||||||
"element": "属性",
|
"element": "属性",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue