fix: remove bugs with signature deletion

This commit is contained in:
Guarzo
2025-06-05 10:15:52 -04:00
parent f28affa222
commit 30b90cd4be
4 changed files with 40 additions and 20 deletions

View File

@@ -12,8 +12,7 @@ import {
SIGNATURE_SETTING_STORE_KEY, SIGNATURE_SETTING_STORE_KEY,
SIGNATURE_WINDOW_ID, SIGNATURE_WINDOW_ID,
SignatureSettingsType, SignatureSettingsType,
SIGNATURES_DELETION_TIMING, getDeletionTimeoutMs,
SIGNATURE_DELETION_TIMEOUTS,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts'; } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
import { OutCommand, OutCommandHandler } from '@/hooks/Mapper/types/mapHandlers'; import { OutCommand, OutCommandHandler } from '@/hooks/Mapper/types/mapHandlers';
import { ExtendedSystemSignature } from '@/hooks/Mapper/types'; import { ExtendedSystemSignature } from '@/hooks/Mapper/types';
@@ -69,9 +68,8 @@ function useSignatureUndo(
} }
// determine timeout from settings // determine timeout from settings
const timingKey = Number(settings[SETTINGS_KEYS.DELETION_TIMING] ?? SIGNATURES_DELETION_TIMING.DEFAULT); const timeoutMs = getDeletionTimeoutMs(settings);
const timeoutMs =
Number(SIGNATURE_DELETION_TIMEOUTS[timingKey as keyof typeof SIGNATURE_DELETION_TIMEOUTS]) || 10000;
setCountdown(Math.ceil(timeoutMs / 1000)); setCountdown(Math.ceil(timeoutMs / 1000));
// start new interval // start new interval
@@ -94,7 +92,7 @@ function useSignatureUndo(
intervalRef.current = null; intervalRef.current = null;
} }
}; };
}, [pendingIds, settings[SETTINGS_KEYS.DELETION_TIMING]]); }, [pendingIds, settings]);
// undo handler // undo handler
const handleUndo = useCallback(async () => { const handleUndo = useCallback(async () => {

View File

@@ -128,9 +128,8 @@ export const SystemSignaturesContent = ({
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
if (onSignatureDeleted && selectedSignatures.length > 0) {
onSignatureDeleted(selectedSignatures); // Delete key should always immediately delete, never show pending deletions
}
handleDeleteSelected(); handleDeleteSelected();
}); });

View File

@@ -148,7 +148,8 @@ export enum SIGNATURES_DELETION_TIMING {
EXTENDED, EXTENDED,
} }
export type SignatureDeletionTimingType = { [key in SIGNATURES_DELETION_TIMING]?: unknown }; // Now use a stricter type: every timing key maps to a number
export type SignatureDeletionTimingType = Record<SIGNATURES_DELETION_TIMING, number>;
export const SIGNATURE_SETTINGS = { export const SIGNATURE_SETTINGS = {
filterFlags: [ filterFlags: [
@@ -219,12 +220,28 @@ export const SETTINGS_VALUES: SignatureSettingsType = {
[SETTINGS_KEYS.COMBAT_SITE]: true, [SETTINGS_KEYS.COMBAT_SITE]: true,
}; };
// Now this map is strongly typed as “number” for each timing enum
export const SIGNATURE_DELETION_TIMEOUTS: SignatureDeletionTimingType = { export const SIGNATURE_DELETION_TIMEOUTS: SignatureDeletionTimingType = {
[SIGNATURES_DELETION_TIMING.DEFAULT]: 10_000,
[SIGNATURES_DELETION_TIMING.IMMEDIATE]: 0, [SIGNATURES_DELETION_TIMING.IMMEDIATE]: 0,
[SIGNATURES_DELETION_TIMING.DEFAULT]: 10_000,
[SIGNATURES_DELETION_TIMING.EXTENDED]: 30_000, [SIGNATURES_DELETION_TIMING.EXTENDED]: 30_000,
}; };
/**
* Helper function to extract the deletion timeout in milliseconds from settings
*/
export function getDeletionTimeoutMs(settings: SignatureSettingsType): number {
const raw = settings[SETTINGS_KEYS.DELETION_TIMING];
const timing =
raw && typeof raw === 'object' && 'value' in raw
? (raw as { value: SIGNATURES_DELETION_TIMING }).value
: (raw as SIGNATURES_DELETION_TIMING | undefined);
const validTiming = typeof timing === 'number' ? timing : SIGNATURES_DELETION_TIMING.DEFAULT;
return SIGNATURE_DELETION_TIMEOUTS[validTiming];
}
// Replace the flat structure with a nested structure by language // Replace the flat structure with a nested structure by language
export const LANGUAGE_TYPE_MAPPINGS = { export const LANGUAGE_TYPE_MAPPINGS = {
EN: { EN: {

View File

@@ -5,7 +5,10 @@ import { OutCommand } from '@/hooks/Mapper/types/mapHandlers';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import useRefState from 'react-usestateref'; import useRefState from 'react-usestateref';
import { SETTINGS_KEYS } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts'; import {
SETTINGS_KEYS,
getDeletionTimeoutMs,
} from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants.ts';
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider'; import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
import { getActualSigs } from '../helpers'; import { getActualSigs } from '../helpers';
import { UseSystemSignaturesDataProps } from './types'; import { UseSystemSignaturesDataProps } from './types';
@@ -74,8 +77,16 @@ export const useSystemSignaturesData = ({
if (removed.length > 0) { if (removed.length > 0) {
await processRemovedSignatures(removed, added, updated); await processRemovedSignatures(removed, added, updated);
if (onSignatureDeleted) {
onSignatureDeleted(removed); // Only show pending deletions if:
// 1. Lazy deletion is enabled AND
// 2. Deletion timing is not immediate (> 0)
if (onSignatureDeleted && lazyDeleteValue) {
const timeoutMs = getDeletionTimeoutMs(settings);
if (timeoutMs > 0) {
onSignatureDeleted(removed);
}
} }
} }
@@ -102,11 +113,6 @@ export const useSystemSignaturesData = ({
const handleDeleteSelected = useCallback(async () => { const handleDeleteSelected = useCallback(async () => {
if (!selectedSignatures.length) return; if (!selectedSignatures.length) return;
// Call onSignatureDeleted with the full signature objects for visual feedback
if (onSignatureDeleted) {
onSignatureDeleted(selectedSignatures);
}
const selectedIds = selectedSignatures.map(s => s.eve_id); const selectedIds = selectedSignatures.map(s => s.eve_id);
const finalList = signatures.filter(s => !selectedIds.includes(s.eve_id)); const finalList = signatures.filter(s => !selectedIds.includes(s.eve_id));
@@ -117,7 +123,7 @@ export const useSystemSignaturesData = ({
// Update local state after server call // Update local state after server call
setSignatures(finalList); setSignatures(finalList);
setSelectedSignatures([]); setSelectedSignatures([]);
}, [handleUpdateSignatures, selectedSignatures, signatures, onSignatureDeleted, setSignatures]); }, [handleUpdateSignatures, selectedSignatures, signatures, setSignatures]);
const handleSelectAll = useCallback(() => { const handleSelectAll = useCallback(() => {
setSelectedSignatures(signatures); setSelectedSignatures(signatures);