From 5819a0d579bd073985a27f45b406f3fa7d6b1de6 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Tue, 11 Jul 2023 18:59:05 -0400 Subject: [PATCH] feat: remove quick gym button for poracle --- public/base-locales/de.json | 4 ++-- public/base-locales/en.json | 8 +++++--- public/base-locales/es.json | 2 +- public/base-locales/fr.json | 4 ++-- public/base-locales/it.json | 2 +- public/base-locales/ja.json | 2 +- public/base-locales/ko.json | 2 +- public/base-locales/nl.json | 2 +- public/base-locales/pl.json | 2 +- public/base-locales/pt-br.json | 2 +- public/base-locales/ru.json | 2 +- public/base-locales/sv.json | 2 +- public/base-locales/th.json | 2 +- public/base-locales/zh-tw.json | 2 +- server/src/services/Fetch.js | 8 ++++---- src/components/popups/Gym.jsx | 26 ++++++++++++++++++++++---- src/hooks/useWebhook.js | 22 +++++++++++++++------- 17 files changed, 61 insertions(+), 33 deletions(-) diff --git a/public/base-locales/de.json b/public/base-locales/de.json index 24080891b..64730c59e 100644 --- a/public/base-locales/de.json +++ b/public/base-locales/de.json @@ -339,7 +339,7 @@ "popup": "Popup", "pvp_level": "Level {{level}} PVP Stats", "pvp_mega": "Mega PVP Stats", - "webhook_entry": "Füge {{category}} zu {{name}} hinzu", + "webhook_entry": "Füge zu {{name}} hinzu", "distance": "Distanz", "gym": "Arena", "egg": "Ei", @@ -604,4 +604,4 @@ "denied": "verweigert", "showcase": "Showcase", "unknown_event": "unbekanntes Event" -} +} \ No newline at end of file diff --git a/public/base-locales/en.json b/public/base-locales/en.json index 70a02c889..4a4b3aa7f 100644 --- a/public/base-locales/en.json +++ b/public/base-locales/en.json @@ -328,7 +328,8 @@ "popup": "Popup", "pvp_level": "Level {{level}} PVP Stats", "pvp_mega": "Mega PVP Stats", - "webhook_entry": "Add {{category}} to {{name}}", + "webhook_entry": "Add to {{name}}", + "remove_webhook_entry": "Remove from {{name}}", "distance": "Distance", "gym": "Gym", "egg": "Egg", @@ -603,5 +604,6 @@ "denied": "Denied", "showcase": "Showcase", "unknown_event": "Unknown Event", - "scanner_countdown": "Available in {{time}}s" -} \ No newline at end of file + "scanner_countdown": "Available in {{time}}s", + "success": "Success" +} diff --git a/public/base-locales/es.json b/public/base-locales/es.json index 900d85344..b1ec91215 100644 --- a/public/base-locales/es.json +++ b/public/base-locales/es.json @@ -351,7 +351,7 @@ "galarian": "Galariano", "finish": "Terminar", "submission_cells_subtitle": "Muestra información útil para enviar nuevos PDI.", - "webhook_entry": "Agregar {{category}} a {{name}}", + "webhook_entry": "Agregar a {{name}}", "distance": "Distancia", "gym": "Gimnasio", "egg": "Huevo", diff --git a/public/base-locales/fr.json b/public/base-locales/fr.json index 6dfd68dd0..adaf34210 100644 --- a/public/base-locales/fr.json +++ b/public/base-locales/fr.json @@ -372,7 +372,7 @@ "has_quest_indicator": "Couleur alternative pour afficher les Quêtes", "show_ar_badge": "Afficher les Badges RA", "pvp_mega": "Stats PvP Méga", - "webhook_entry": "Ajouter {{category}} à {{name}}", + "webhook_entry": "Ajouter à {{name}}", "distance": "Distance", "gym": "Arène", "egg": "Œuf", @@ -596,4 +596,4 @@ "denied": "Refusé", "showcase": "Épreuves", "unknown_event": "Inconnu" -} +} \ No newline at end of file diff --git a/public/base-locales/it.json b/public/base-locales/it.json index 69f0ac015..1c13fcad1 100644 --- a/public/base-locales/it.json +++ b/public/base-locales/it.json @@ -365,7 +365,7 @@ "popup": "Apparire", "pvp_level": "Statistiche PVP di livello {{level}}", "pvp_mega": "Mega statistiche PVP", - "webhook_entry": "Aggiungi {{category}} a {{name}}", + "webhook_entry": "Aggiungi a {{name}}", "pokestops": "PokéStop", "spawnpoints": "punti di spawn", "distance": "Distanza", diff --git a/public/base-locales/ja.json b/public/base-locales/ja.json index ba26dcb8a..e0d0a2205 100644 --- a/public/base-locales/ja.json +++ b/public/base-locales/ja.json @@ -329,7 +329,7 @@ "popup": "現れる", "pvp_level": "レベル{{level}} PVP統計", "pvp_mega": "メガPVP統計", - "webhook_entry": "{{category}}を{{name}}に追加します", + "webhook_entry": "を{{name}}に追加します", "distance": "距離", "gym": "ジム", "egg": "卵", diff --git a/public/base-locales/ko.json b/public/base-locales/ko.json index 8c6086906..14467ae13 100644 --- a/public/base-locales/ko.json +++ b/public/base-locales/ko.json @@ -397,7 +397,7 @@ "popup": "팝업", "pvp_level": "레벨 {{level}} PVP 통계", "pvp_mega": "메가 PVP 통계", - "webhook_entry": "{{name}}에 {{category}} 추가", + "webhook_entry": "{{name}}에 추가", "distance": "거리", "gym": "헬스장", "egg": "계란", diff --git a/public/base-locales/nl.json b/public/base-locales/nl.json index aa2858686..c971ad2db 100644 --- a/public/base-locales/nl.json +++ b/public/base-locales/nl.json @@ -304,7 +304,7 @@ "popup": "Popup", "pvp_level": "Level {{level}} PVP Statistieken", "pvp_mega": "Mega PVP Statistieken", - "webhook_entry": "Voeg {{category}} toe aan {{name}}", + "webhook_entry": "Voeg toe aan {{name}}", "distance": "Afstand", "gym": "Gym", "egg": "Egg", diff --git a/public/base-locales/pl.json b/public/base-locales/pl.json index cd1b0c554..b36864ead 100644 --- a/public/base-locales/pl.json +++ b/public/base-locales/pl.json @@ -347,7 +347,7 @@ "alola": "Alola", "galarian": "galarian", "submission_cells_subtitle": "Wyświetla informacje przydatne w dodawaniu nowych POI", - "webhook_entry": "Dodaj {{category}} do {{name}}", + "webhook_entry": "Dodaj do {{name}}", "distance": "Dystans", "gym": "Gym", "egg": "Jajko", diff --git a/public/base-locales/pt-br.json b/public/base-locales/pt-br.json index 69eaca86b..7fc77b96d 100644 --- a/public/base-locales/pt-br.json +++ b/public/base-locales/pt-br.json @@ -303,7 +303,7 @@ "popup": "Aparecer", "pvp_level": "Nível {{level}} Estatísticas PVP", "pvp_mega": "Mega PVP Stats", - "webhook_entry": "Adicione {{category}} a {{name}}", + "webhook_entry": "Adicione a {{name}}", "distance": "Distância", "gym": "Academia", "egg": "Ovo", diff --git a/public/base-locales/ru.json b/public/base-locales/ru.json index a49c7abdb..6eb62a183 100644 --- a/public/base-locales/ru.json +++ b/public/base-locales/ru.json @@ -329,7 +329,7 @@ "popup": "Неожиданно возникнуть", "pvp_level": "Уровень {{level}} PVP Статистика", "pvp_mega": "Мега статистика PVP", - "webhook_entry": "Добавить {{category}} в {{name}}", + "webhook_entry": "Добавить в {{name}}", "distance": "Расстояние", "gym": "Спортзал", "egg": "Яйцо", diff --git a/public/base-locales/sv.json b/public/base-locales/sv.json index df9b1626e..40c38e8e5 100644 --- a/public/base-locales/sv.json +++ b/public/base-locales/sv.json @@ -302,7 +302,7 @@ "popup": "Dyka upp", "pvp_level": "Nivå {{level}} PVP-statistik", "pvp_mega": "Mega PVP-statistik", - "webhook_entry": "Lägg till {{category}} till {{name}}", + "webhook_entry": "Lägg till {{name}}", "distance": "Distans", "gym": "Gym", "egg": "Ägg", diff --git a/public/base-locales/th.json b/public/base-locales/th.json index 9d66c3ba2..64c878a0d 100644 --- a/public/base-locales/th.json +++ b/public/base-locales/th.json @@ -302,7 +302,7 @@ "popup": "ป๊อปอัพ", "pvp_level": "ระดับ {{level}} สถิติ PVP", "pvp_mega": "สถิติเมก้า PVP", - "webhook_entry": "เพิ่ม {{category}} ใน {{name}}", + "webhook_entry": "เพิ่ม ใน {{name}}", "distance": "ระยะทาง", "gym": "โรงยิม", "egg": "ไข่", diff --git a/public/base-locales/zh-tw.json b/public/base-locales/zh-tw.json index b26ca6625..6fdefcef1 100644 --- a/public/base-locales/zh-tw.json +++ b/public/base-locales/zh-tw.json @@ -303,7 +303,7 @@ "popup": "彈出", "pvp_level": "等級 {{level}} PVP 統計", "pvp_mega": "超級 PVP 統計", - "webhook_entry": "將 {{category}} 添加到 {{name}}", + "webhook_entry": "將 添加到 {{name}}", "distance": "距離", "gym": "健身房", "egg": "蛋", diff --git a/server/src/services/Fetch.js b/server/src/services/Fetch.js index c0152e31a..2652d3e85 100644 --- a/server/src/services/Fetch.js +++ b/server/src/services/Fetch.js @@ -22,11 +22,11 @@ module.exports = class Fetch { return fetchNests() } - static async webhookApi(category, discordId, method, name, data) { - return webhookApi(category, discordId, method, name, data) + static async webhookApi(...args) { + return webhookApi(...args) } - static async scannerApi(category, method, data, user) { - return scannerApi(category, method, data, user) + static async scannerApi(...args) { + return scannerApi(...args) } } diff --git a/src/components/popups/Gym.jsx b/src/components/popups/Gym.jsx index 2baf7fb31..bb6d87fd9 100644 --- a/src/components/popups/Gym.jsx +++ b/src/components/popups/Gym.jsx @@ -131,7 +131,7 @@ export default function GymPopup({ ) } -const MenuActions = ({ gym, perms, hasRaid, t, badge, setBadge }) => { +const MenuActions = ({ gym, perms, hasRaid, badge, setBadge }) => { const hideList = useStatic((state) => state.hideList) const setHideList = useStatic((state) => state.setHideList) const excludeList = useStatic((state) => state.excludeList) @@ -141,6 +141,7 @@ const MenuActions = ({ gym, perms, hasRaid, t, badge, setBadge }) => { const { gymValidDataLimit } = useStatic((state) => state.config) const selectedWebhook = useStore((state) => state.selectedWebhook) + const webhookData = useStatic((state) => state.webhookData) const filters = useStore((state) => state.filters) const setFilters = useStore((state) => state.setFilters) @@ -149,6 +150,16 @@ const MenuActions = ({ gym, perms, hasRaid, t, badge, setBadge }) => { const [badgeMenu, setBadgeMenu] = useState(false) const addWebhook = useWebhook({ category: 'quickGym', selectedWebhook }) + const hasGymHook = webhookData?.[selectedWebhook]?.gym?.find( + (x) => x.gym_id === gym.id, + ) + const hasRaidHook = webhookData?.[selectedWebhook]?.raid?.find( + (x) => x.gym_id === gym.id, + ) + const hasEggHook = webhookData?.[selectedWebhook]?.egg?.find( + (x) => x.gym_id === gym.id, + ) + const hasWebhook = !!hasGymHook || !!hasRaidHook || !!hasEggHook const { id, team_id, @@ -248,12 +259,19 @@ const MenuActions = ({ gym, perms, hasRaid, t, badge, setBadge }) => { perms.webhooks.forEach((hook) => { options.push({ name: ( - - {{ category: t('gym') }} + {{ name: hook }} ), - action: () => addWebhook(gym), + action: () => { + if (hasWebhook) { + if (hasGymHook) addWebhook(hasGymHook.uid, 'gym-delete') + if (hasRaidHook) addWebhook(hasRaidHook.uid, 'raid-delete') + if (hasEggHook) addWebhook(hasEggHook.uid, 'egg-delete') + } else { + addWebhook(gym, 'quickGym') + } + }, key: hook, }) }) diff --git a/src/hooks/useWebhook.js b/src/hooks/useWebhook.js index c5a4f4daf..a26b4ee38 100644 --- a/src/hooks/useWebhook.js +++ b/src/hooks/useWebhook.js @@ -18,11 +18,19 @@ export default function useWebhook({ category, selectedWebhook }) { `webhook_success_${category.replace('quick', '').toLowerCase()}`, ) } - setWebhookAlert({ - open: true, - severity: data.webhook.status, - message: data.webhook.message, - }) + if (data.webhook.status === 'ok') { + setWebhookAlert({ + open: true, + severity: 'success', + message: t('success'), + }) + } else { + setWebhookAlert({ + open: true, + severity: data.webhook.status, + message: data.webhook.message, + }) + } if (webhookData?.[selectedWebhook]) { return setWebhookData({ ...webhookData, @@ -35,10 +43,10 @@ export default function useWebhook({ category, selectedWebhook }) { } }, [data]) - const addWebhook = (incomingData) => { + const addWebhook = (incomingData, cat) => { syncWebhook({ variables: { - category, + category: cat, data: incomingData, name: selectedWebhook, status: 'POST',