From fc41573e70ef64c222a8595c7405658e66e7854a Mon Sep 17 00:00:00 2001 From: guarzo Date: Wed, 5 Feb 2025 00:01:46 -0700 Subject: [PATCH] feat: allow filtering of k-space kills (#147) --- .../widgets/SystemKills/SystemKills.tsx | 34 +++++++++++++++---- .../SystemKillsContent/SystemKillsContent.tsx | 2 +- .../components/SystemKillsSettingsDialog.tsx | 26 ++++++++++++-- .../hooks/useKillsWidgetSettings.ts | 2 ++ 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/SystemKills.tsx b/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/SystemKills.tsx index 0f35000b..6543d54b 100644 --- a/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/SystemKills.tsx +++ b/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/SystemKills.tsx @@ -6,6 +6,7 @@ import { KillsHeader } from './components/SystemKillsHeader'; import { useKillsWidgetSettings } from './hooks/useKillsWidgetSettings'; import { useSystemKills } from './hooks/useSystemKills'; import { KillsSettingsDialog } from './components/SystemKillsSettingsDialog'; +import { isWormholeSpace } from '@/hooks/Mapper/components/map/helpers/isWormholeSpace'; export const SystemKills: React.FC = () => { const { @@ -37,10 +38,26 @@ export const SystemKills: React.FC = () => { const isNothingSelected = !systemId && !visible; const showLoading = isLoading && kills.length === 0; + const filteredKills = useMemo(() => { + if (!settings.whOnly) return kills; + return kills.filter(kill => { + const system = systems.find(sys => sys.system_static_info.solar_system_id === kill.solar_system_id); + if (!system) { + console.warn(`System with id ${kill.solar_system_id} not found.`); + return false; + } + return isWormholeSpace(system.system_static_info.system_class); + }); + }, [kills, settings.whOnly, systems]); + return (
- setSettingsDialogVisible(true)} />}> + setSettingsDialogVisible(true)} /> + } + > {!isSubscriptionActive && (
Kills available with 'Active' map subscription only (contact map administrators) @@ -66,17 +83,20 @@ export const SystemKills: React.FC = () => {
)} - {!isNothingSelected && !showLoading && !error && (!kills || kills.length === 0) && ( -
- No kills found -
- )} + {!isNothingSelected && + !showLoading && + !error && + (!filteredKills || filteredKills.length === 0) && ( +
+ No kills found +
+ )} {!isNothingSelected && !showLoading && !error && (
= ({
{sortedKills.map(kill => { diff --git a/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/components/SystemKillsSettingsDialog.tsx b/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/components/SystemKillsSettingsDialog.tsx index 7898be95..a2a384af 100644 --- a/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/components/SystemKillsSettingsDialog.tsx +++ b/assets/js/hooks/Mapper/components/mapInterface/widgets/SystemKills/components/SystemKillsSettingsDialog.tsx @@ -19,6 +19,7 @@ export const KillsSettingsDialog: React.FC = ({ visibl const localRef = useRef({ compact: globalSettings.compact, showAll: globalSettings.showAll, + whOnly: globalSettings.whOnly, excludedSystems: globalSettings.excludedSystems || [], }); @@ -31,6 +32,7 @@ export const KillsSettingsDialog: React.FC = ({ visibl localRef.current = { compact: globalSettings.compact, showAll: globalSettings.showAll, + whOnly: globalSettings.whOnly, excludedSystems: globalSettings.excludedSystems || [], }; forceRender(n => n + 1); @@ -45,6 +47,14 @@ export const KillsSettingsDialog: React.FC = ({ visibl forceRender(n => n + 1); }, []); + const handleWHChange = useCallback((checked: boolean) => { + localRef.current = { + ...localRef.current, + whOnly: checked, + }; + forceRender(n => n + 1); + }, []); + const handleRemoveSystem = useCallback((sysId: number) => { localRef.current = { ...localRef.current, @@ -94,6 +104,18 @@ export const KillsSettingsDialog: React.FC = ({ visibl
+
+ handleWHChange(e.target.checked)} + /> + +
+
@@ -106,7 +128,7 @@ export const KillsSettingsDialog: React.FC = ({ visibl {excluded.length === 0 &&
No systems excluded.
} {excluded.map(sysId => (
- + = ({ visibl ))}
- {/* Apply + Close button row */}
- {/* AddSystemDialog for picking new systems to exclude */}