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>
|
||||
<Button
|
||||
contained={true}
|
||||
onClick={props.cancelAction}
|
||||
onClick={props.primaryAction}
|
||||
text={props.primaryActionText}
|
||||
/>
|
||||
</AlertDialog.Action>
|
||||
|
|
|
|||
|
|
@ -171,6 +171,15 @@ const CharacterGrid = (props: Props) => {
|
|||
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
|
||||
const saveJob = async function (job?: Job) {
|
||||
const payload = {
|
||||
|
|
@ -371,6 +380,7 @@ const CharacterGrid = (props: Props) => {
|
|||
position={i}
|
||||
updateObject={receiveCharacterFromSearch}
|
||||
updateUncap={initiateUncapUpdate}
|
||||
removeCharacter={removeCharacter}
|
||||
/>
|
||||
</li>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,18 +7,18 @@ import { useTranslation } from 'next-i18next'
|
|||
import { AxiosResponse } from 'axios'
|
||||
import debounce from 'lodash.debounce'
|
||||
|
||||
import Alert from '~components/Alert'
|
||||
import WeaponUnit from '~components/WeaponUnit'
|
||||
import ExtraWeapons from '~components/ExtraWeapons'
|
||||
import WeaponConflictModal from '~components/WeaponConflictModal'
|
||||
|
||||
import api from '~utils/api'
|
||||
import { appState } from '~utils/appState'
|
||||
import { accountState } from '~utils/accountState'
|
||||
|
||||
import type { DetailsObject, SearchableObject } from '~types'
|
||||
|
||||
import './index.scss'
|
||||
import WeaponConflictModal from '~components/WeaponConflictModal'
|
||||
import Alert from '~components/Alert'
|
||||
import { accountState } from '~utils/accountState'
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
|
|
@ -198,6 +198,21 @@ const WeaponGrid = (props: Props) => {
|
|||
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
|
||||
// Note: Saves, but debouncing is not working properly
|
||||
async function saveUncap(id: string, position: number, uncapLevel: number) {
|
||||
|
|
@ -254,7 +269,7 @@ const WeaponGrid = (props: Props) => {
|
|||
)
|
||||
|
||||
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)
|
||||
appState.grid.weapons.mainWeapon.uncap_level = uncapLevel
|
||||
else {
|
||||
|
|
@ -292,6 +307,7 @@ const WeaponGrid = (props: Props) => {
|
|||
key="grid_mainhand"
|
||||
position={-1}
|
||||
unitType={0}
|
||||
removeWeapon={removeWeapon}
|
||||
updateObject={receiveWeaponFromSearch}
|
||||
updateUncap={initiateUncapUpdate}
|
||||
/>
|
||||
|
|
@ -305,6 +321,7 @@ const WeaponGrid = (props: Props) => {
|
|||
editable={party.editable}
|
||||
position={i}
|
||||
unitType={1}
|
||||
removeWeapon={removeWeapon}
|
||||
updateObject={receiveWeaponFromSearch}
|
||||
updateUncap={initiateUncapUpdate}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -480,11 +480,11 @@ const WeaponUnit = ({
|
|||
<Alert
|
||||
open={alertOpen}
|
||||
primaryAction={removeWeapon}
|
||||
primaryActionText={t('modals.weapons.buttons.remove')}
|
||||
primaryActionText={t('modals.weapon.buttons.remove')}
|
||||
cancelAction={() => setAlertOpen(false)}
|
||||
cancelActionText={t('buttons.cancel')}
|
||||
message={
|
||||
<Trans i18nKey="modals.characters.messages.remove">
|
||||
<Trans i18nKey="modals.weapons.messages.remove">
|
||||
Are you sure you want to remove{' '}
|
||||
<strong>{{ weapon: gridWeapon?.object.name[locale] }}</strong> from
|
||||
your team?
|
||||
|
|
|
|||
|
|
@ -253,7 +253,8 @@
|
|||
"weapon": {
|
||||
"title": "Modify Weapon",
|
||||
"buttons": {
|
||||
"confirm": "Save weapon"
|
||||
"confirm": "Save weapon",
|
||||
"remove": "Remove weapon"
|
||||
},
|
||||
"subtitles": {
|
||||
"element": "Element",
|
||||
|
|
|
|||
|
|
@ -254,7 +254,8 @@
|
|||
"weapon": {
|
||||
"title": "武器変更",
|
||||
"buttons": {
|
||||
"confirm": "武器を変更する"
|
||||
"confirm": "武器を変更する",
|
||||
"remove": "武器を削除する"
|
||||
},
|
||||
"subtitles": {
|
||||
"element": "属性",
|
||||
|
|
|
|||
Loading…
Reference in a new issue