From bf77a4ffc7af785e2272bd9780c8387b0ef6d3fa Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 19 Apr 2023 04:01:22 -0700 Subject: [PATCH] Add support for removing guidebooks --- components/extra/GuidebookUnit/index.tsx | 6 +++--- components/extra/GuidebooksGrid/index.tsx | 2 +- components/party/Party/index.tsx | 8 +++++++- components/weapon/WeaponGrid/index.tsx | 6 +++++- public/locales/en/common.json | 5 +++++ public/locales/ja/common.json | 5 +++++ 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/components/extra/GuidebookUnit/index.tsx b/components/extra/GuidebookUnit/index.tsx index bb1fc38f..5e64f969 100644 --- a/components/extra/GuidebookUnit/index.tsx +++ b/components/extra/GuidebookUnit/index.tsx @@ -23,7 +23,7 @@ interface Props { guidebook: Guidebook | undefined position: number editable: boolean - removeGuidebook: (id: string) => void + removeGuidebook: (position: number) => void updateObject: (object: SearchableObject, position: number) => void } @@ -91,7 +91,7 @@ const GuidebookUnit = ({ // Methods: Mutate data function removeGuidebook() { - if (guidebook) sendGuidebookToRemove(guidebook.id) + if (guidebook) sendGuidebookToRemove(position) setAlertOpen(false) } @@ -136,7 +136,7 @@ const GuidebookUnit = ({ setAlertOpen(false)} cancelActionText={t('buttons.cancel')} message={ diff --git a/components/extra/GuidebooksGrid/index.tsx b/components/extra/GuidebooksGrid/index.tsx index d6a26f2c..25a8e859 100644 --- a/components/extra/GuidebooksGrid/index.tsx +++ b/components/extra/GuidebooksGrid/index.tsx @@ -13,7 +13,7 @@ interface Props { grid: GuidebookList editable: boolean offset: number - removeGuidebook: (id: string) => void + removeGuidebook: (position: number) => void updateObject: (object: SearchableObject, position: number) => void } diff --git a/components/party/Party/index.tsx b/components/party/Party/index.tsx index c7a52a68..d4bbc2ca 100644 --- a/components/party/Party/index.tsx +++ b/components/party/Party/index.tsx @@ -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 = { guidebook1_id: position === 1 ? id : undefined, guidebook2_id: position === 2 ? id : undefined, diff --git a/components/weapon/WeaponGrid/index.tsx b/components/weapon/WeaponGrid/index.tsx index f496b056..44133528 100644 --- a/components/weapon/WeaponGrid/index.tsx +++ b/components/weapon/WeaponGrid/index.tsx @@ -31,7 +31,7 @@ interface Props { createParty: (details: DetailsObject) => Promise pushHistory?: (path: string) => void updateExtra: (enabled: boolean) => void - updateGuidebook: (book: Guidebook, position: number) => void + updateGuidebook: (book: Guidebook | undefined, position: number) => void } 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 // Note: Saves, but debouncing is not working properly async function saveUncap(id: string, position: number, uncapLevel: number) { diff --git a/public/locales/en/common.json b/public/locales/en/common.json index e075f5ed..971e11c4 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -232,6 +232,11 @@ "clear": "Clear filters" } }, + "guidebooks": { + "buttons": { + "remove": "Remove guidebook" + } + }, "login": { "title": "Log in", "buttons": { diff --git a/public/locales/ja/common.json b/public/locales/ja/common.json index 3247423d..fcc725b3 100644 --- a/public/locales/ja/common.json +++ b/public/locales/ja/common.json @@ -232,6 +232,11 @@ "clear": "保存したフィルターをクリア" } }, + "guidebooks": { + "buttons": { + "remove": "導本を削除する" + } + }, "login": { "title": "ログイン", "buttons": {