mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 02:35:42 +00:00
fix issue with deselection and linked sig splash filters (#187)
This commit is contained in:
@@ -156,11 +156,14 @@ export function SystemSignaturesContent({
|
||||
[selectable, onSelect, setSelectedSignatures],
|
||||
);
|
||||
|
||||
const groupSettings = settings.filter(s => GROUPS_LIST.includes(s.key as SignatureGroup));
|
||||
const showDescriptionColumn = settings.find(s => s.key === SHOW_DESCRIPTION_COLUMN_SETTING)?.value;
|
||||
const showUpdatedColumn = settings.find(s => s.key === SHOW_UPDATED_COLUMN_SETTING)?.value;
|
||||
const showCharacterColumn = settings.find(s => s.key === SHOW_CHARACTER_COLUMN_SETTING)?.value;
|
||||
|
||||
const enabledGroups = settings
|
||||
.filter(s => GROUPS_LIST.includes(s.key as SignatureGroup) && s.value === true)
|
||||
.map(s => s.key);
|
||||
|
||||
const filteredSignatures = useMemo<ExtendedSystemSignature[]>(() => {
|
||||
return signatures.filter(sig => {
|
||||
if (hideLinkedSignatures && sig.linked_system) {
|
||||
@@ -168,18 +171,16 @@ export function SystemSignaturesContent({
|
||||
}
|
||||
if (sig.kind === COSMIC_SIGNATURE) {
|
||||
const showCosmic = settings.find(y => y.key === COSMIC_SIGNATURE)?.value;
|
||||
if (!showCosmic) {
|
||||
return false;
|
||||
}
|
||||
if (sig.group && groupSettings.find(y => y.key === sig.group)?.value === false) {
|
||||
return false;
|
||||
if (!showCosmic) return false;
|
||||
if (sig.group) {
|
||||
return enabledGroups.includes(sig.group);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return settings.find(y => y.key === sig.kind)?.value;
|
||||
}
|
||||
});
|
||||
}, [signatures, settings, groupSettings, hideLinkedSignatures]);
|
||||
}, [signatures, hideLinkedSignatures, settings, enabledGroups]);
|
||||
|
||||
return (
|
||||
<div ref={tableRef} className="h-full">
|
||||
|
||||
@@ -1,45 +1,32 @@
|
||||
import { SystemSignature, SignatureKind, SignatureGroup } from '@/hooks/Mapper/types';
|
||||
import { SystemSignature } from '@/hooks/Mapper/types';
|
||||
import { GROUPS_LIST } from '@/hooks/Mapper/components/mapInterface/widgets/SystemSignatures/constants';
|
||||
import { getState } from './getState';
|
||||
|
||||
/**
|
||||
* Compare two lists of signatures and return which are added, updated, or removed.
|
||||
*
|
||||
* @param oldSignatures existing signatures (in memory or from server)
|
||||
* @param newSignatures newly parsed or incoming signatures from user input
|
||||
* @param updateOnly if true, do NOT remove old signatures not found in newSignatures
|
||||
* @param skipUpdateUntouched if true, do NOT push unmodified signatures into the `updated` array
|
||||
*/
|
||||
export const getActualSigs = (
|
||||
oldSignatures: SystemSignature[],
|
||||
newSignatures: SystemSignature[],
|
||||
updateOnly: boolean,
|
||||
updateOnly?: boolean,
|
||||
skipUpdateUntouched?: boolean,
|
||||
): { added: SystemSignature[]; updated: SystemSignature[]; removed: SystemSignature[] } => {
|
||||
const updated: SystemSignature[] = [];
|
||||
const removed: SystemSignature[] = [];
|
||||
const added: SystemSignature[] = [];
|
||||
const mergedNewIds = new Set<string>();
|
||||
|
||||
oldSignatures.forEach(oldSig => {
|
||||
let newSig: SystemSignature | undefined;
|
||||
if (
|
||||
oldSig.kind === SignatureKind.CosmicSignature &&
|
||||
oldSig.group === SignatureGroup.Wormhole &&
|
||||
oldSig.eve_id.length !== 7
|
||||
) {
|
||||
newSig = newSignatures.find(
|
||||
s =>
|
||||
s.kind === SignatureKind.CosmicSignature &&
|
||||
s.group === SignatureGroup.Wormhole &&
|
||||
s.eve_id.toUpperCase().startsWith(oldSig.eve_id.toUpperCase() + '-'),
|
||||
);
|
||||
if (newSig) {
|
||||
const mergedSig: SystemSignature = { ...newSig, kind: oldSig.kind, name: oldSig.name };
|
||||
added.push(mergedSig);
|
||||
removed.push(oldSig);
|
||||
mergedNewIds.add(newSig.eve_id);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
newSig = newSignatures.find(s => s.eve_id === oldSig.eve_id);
|
||||
}
|
||||
const newSig = newSignatures.find(s => s.eve_id === oldSig.eve_id);
|
||||
if (newSig) {
|
||||
const needUpgrade = getState(GROUPS_LIST, newSig) > getState(GROUPS_LIST, oldSig);
|
||||
const mergedSig = { ...oldSig };
|
||||
let changed = false;
|
||||
|
||||
if (needUpgrade) {
|
||||
mergedSig.group = newSig.group;
|
||||
mergedSig.name = newSig.name;
|
||||
@@ -49,6 +36,7 @@ export const getActualSigs = (
|
||||
mergedSig.description = newSig.description;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
try {
|
||||
const oldInfo = JSON.parse(oldSig.custom_info || '{}');
|
||||
const newInfo = JSON.parse(newSig.custom_info || '{}');
|
||||
@@ -66,10 +54,12 @@ export const getActualSigs = (
|
||||
} catch (e) {
|
||||
console.error(`getActualSigs: Error merging custom_info for ${oldSig.eve_id}`, e);
|
||||
}
|
||||
|
||||
if (newSig.updated_at !== oldSig.updated_at) {
|
||||
mergedSig.updated_at = newSig.updated_at;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
updated.push(mergedSig);
|
||||
} else if (!skipUpdateUntouched) {
|
||||
@@ -84,9 +74,10 @@ export const getActualSigs = (
|
||||
|
||||
const oldIds = new Set(oldSignatures.map(x => x.eve_id));
|
||||
newSignatures.forEach(s => {
|
||||
if (!oldIds.has(s.eve_id) && !mergedNewIds.has(s.eve_id)) {
|
||||
if (!oldIds.has(s.eve_id)) {
|
||||
added.push(s);
|
||||
}
|
||||
});
|
||||
|
||||
return { added, updated, removed };
|
||||
};
|
||||
|
||||
@@ -30,10 +30,12 @@ export function useSignatureFetching({
|
||||
data: { system_id: systemId },
|
||||
});
|
||||
const serverSigs = (resp.signatures ?? []) as SystemSignature[];
|
||||
|
||||
const extended = serverSigs.map(s => ({
|
||||
...s,
|
||||
character_name: characters.find(c => c.eve_id === s.character_eve_id)?.name,
|
||||
})) as ExtendedSystemSignature[];
|
||||
|
||||
setSignatures(prev => mergeLocalPendingAdditions(extended, prev));
|
||||
}, [characters, systemId, localPendingDeletions, outCommand, setSignatures]);
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ export function useSystemSignaturesData({
|
||||
systemId,
|
||||
setSignatures,
|
||||
});
|
||||
|
||||
const { pendingUndoAdditions, setPendingUndoAdditions, processAddedSignatures, clearPendingAdditions } =
|
||||
usePendingAdditions({
|
||||
setSignatures,
|
||||
@@ -49,6 +48,7 @@ export function useSystemSignaturesData({
|
||||
const handlePaste = useCallback(
|
||||
async (clipboardString: string) => {
|
||||
const lazyDeleteValue = settings.find(s => s.key === LAZY_DELETE_SIGNATURES_SETTING)?.value ?? false;
|
||||
|
||||
const incomingSignatures = parseSignatures(
|
||||
clipboardString,
|
||||
settings.map(s => s.key),
|
||||
@@ -64,6 +64,7 @@ export function useSystemSignaturesData({
|
||||
if (added.length > 0) {
|
||||
processAddedSignatures(added);
|
||||
}
|
||||
|
||||
if (removed.length > 0) {
|
||||
await processRemovedSignatures(removed, added, updated);
|
||||
} else {
|
||||
@@ -89,7 +90,9 @@ export function useSystemSignaturesData({
|
||||
|
||||
const keepLazy = settings.find(s => s.key === KEEP_LAZY_DELETE_SETTING)?.value ?? false;
|
||||
if (lazyDeleteValue && !keepLazy) {
|
||||
onLazyDeleteChange?.(false);
|
||||
setTimeout(() => {
|
||||
onLazyDeleteChange?.(false);
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -108,6 +111,7 @@ export function useSystemSignaturesData({
|
||||
if (!selectedSignatures.length) return;
|
||||
const selectedIds = selectedSignatures.map(s => s.eve_id);
|
||||
const finalList = signatures.filter(s => !selectedIds.includes(s.eve_id));
|
||||
|
||||
await handleUpdateSignatures(finalList, false, true);
|
||||
setSelectedSignatures([]);
|
||||
}, [selectedSignatures, signatures, handleUpdateSignatures]);
|
||||
@@ -122,6 +126,7 @@ export function useSystemSignaturesData({
|
||||
setSignatures(prev =>
|
||||
prev.map(x => (x.pendingDeletion ? { ...x, pendingDeletion: false, pendingUntil: undefined } : x)),
|
||||
);
|
||||
|
||||
if (pendingUndoAdditions.length) {
|
||||
pendingUndoAdditions.forEach(async sig => {
|
||||
await outCommand({
|
||||
|
||||
Reference in New Issue
Block a user