Add support for removing guidebooks

This commit is contained in:
Justin Edmund 2023-04-19 04:01:22 -07:00
parent 59d264f3c3
commit bf77a4ffc7
6 changed files with 26 additions and 6 deletions

View file

@ -23,7 +23,7 @@ interface Props {
guidebook: Guidebook | undefined guidebook: Guidebook | undefined
position: number position: number
editable: boolean editable: boolean
removeGuidebook: (id: string) => void removeGuidebook: (position: number) => void
updateObject: (object: SearchableObject, position: number) => void updateObject: (object: SearchableObject, position: number) => void
} }
@ -91,7 +91,7 @@ const GuidebookUnit = ({
// Methods: Mutate data // Methods: Mutate data
function removeGuidebook() { function removeGuidebook() {
if (guidebook) sendGuidebookToRemove(guidebook.id) if (guidebook) sendGuidebookToRemove(position)
setAlertOpen(false) setAlertOpen(false)
} }
@ -136,7 +136,7 @@ const GuidebookUnit = ({
<Alert <Alert
open={alertOpen} open={alertOpen}
primaryAction={removeGuidebook} primaryAction={removeGuidebook}
primaryActionText={t('modals.weapon.buttons.remove')} primaryActionText={t('modals.guidebooks.buttons.remove')}
cancelAction={() => setAlertOpen(false)} cancelAction={() => setAlertOpen(false)}
cancelActionText={t('buttons.cancel')} cancelActionText={t('buttons.cancel')}
message={ message={

View file

@ -13,7 +13,7 @@ interface Props {
grid: GuidebookList grid: GuidebookList
editable: boolean editable: boolean
offset: number offset: number
removeGuidebook: (id: string) => void removeGuidebook: (position: number) => void
updateObject: (object: SearchableObject, position: number) => void updateObject: (object: SearchableObject, position: number) => void
} }

View file

@ -164,7 +164,13 @@ const Party = (props: Props) => {
} }
} }
function updateGuidebook(book: Guidebook, position: number) { function updateGuidebook(book: Guidebook | undefined, position: number) {
let id: string | undefined = ''
if (book) id = book.id
else if (!book) id = 'undefined'
else id = undefined
const details: DetailsObject = { const details: DetailsObject = {
guidebook1_id: position === 1 ? id : undefined, guidebook1_id: position === 1 ? id : undefined,
guidebook2_id: position === 2 ? id : undefined, guidebook2_id: position === 2 ? id : undefined,

View file

@ -31,7 +31,7 @@ interface Props {
createParty: (details: DetailsObject) => Promise<Party> createParty: (details: DetailsObject) => Promise<Party>
pushHistory?: (path: string) => void pushHistory?: (path: string) => void
updateExtra: (enabled: boolean) => void updateExtra: (enabled: boolean) => void
updateGuidebook: (book: Guidebook, position: number) => void updateGuidebook: (book: Guidebook | undefined, position: number) => void
} }
const WeaponGrid = (props: Props) => { const WeaponGrid = (props: Props) => {
@ -249,6 +249,10 @@ const WeaponGrid = (props: Props) => {
} }
} }
async function removeGuidebook(position: number) {
props.updateGuidebook(undefined, position)
}
// 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) {

View file

@ -232,6 +232,11 @@
"clear": "Clear filters" "clear": "Clear filters"
} }
}, },
"guidebooks": {
"buttons": {
"remove": "Remove guidebook"
}
},
"login": { "login": {
"title": "Log in", "title": "Log in",
"buttons": { "buttons": {

View file

@ -232,6 +232,11 @@
"clear": "保存したフィルターをクリア" "clear": "保存したフィルターをクリア"
} }
}, },
"guidebooks": {
"buttons": {
"remove": "導本を削除する"
}
},
"login": { "login": {
"title": "ログイン", "title": "ログイン",
"buttons": { "buttons": {