mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 02:35:42 +00:00
fix(Map): Refactor init and update of mapper
This commit is contained in:
@@ -73,6 +73,11 @@ export const ContextMenuSystemInfo: React.FC<ContextMenuSystemInfoProps> = ({
|
|||||||
icon: PrimeIcons.MAP_MARKER,
|
icon: PrimeIcons.MAP_MARKER,
|
||||||
command: onHubToggle,
|
command: onHubToggle,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: !hubs.includes(systemId) ? 'Add in Routes' : 'Remove from Routes',
|
||||||
|
icon: PrimeIcons.MAP_MARKER,
|
||||||
|
command: onHubToggle,
|
||||||
|
},
|
||||||
...(!systemOnMap
|
...(!systemOnMap
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ const INITIAL_DATA: MapData = {
|
|||||||
systemSignatures: {} as Record<string, SystemSignature[]>,
|
systemSignatures: {} as Record<string, SystemSignature[]>,
|
||||||
options: {} as Record<string, string | boolean>,
|
options: {} as Record<string, string | boolean>,
|
||||||
isSubscriptionActive: false,
|
isSubscriptionActive: false,
|
||||||
|
mainCharacterEveId: null,
|
||||||
|
followingCharacterEveId: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface MapContextProps {
|
export interface MapContextProps {
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ export const SolarSystemNodeDefault = memo((props: NodeProps<MapSolarSystemType>
|
|||||||
<>
|
<>
|
||||||
{nodeVars.visible && (
|
{nodeVars.visible && (
|
||||||
<div className={classes.Bookmarks}>
|
<div className={classes.Bookmarks}>
|
||||||
{nodeVars.labelCustom !== '' && (
|
|
||||||
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.custom)}>
|
|
||||||
<span className="[text-shadow:_0_1px_0_rgb(0_0_0_/_40%)]">{nodeVars.labelCustom}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{nodeVars.isShattered && (
|
{nodeVars.isShattered && (
|
||||||
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.shattered, '!pr-[2px]')}>
|
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.shattered, '!pr-[2px]')}>
|
||||||
<WdTooltipWrapper content="Shattered" position={TooltipPosition.top}>
|
<WdTooltipWrapper content="Shattered" position={TooltipPosition.top}>
|
||||||
@@ -55,6 +49,12 @@ export const SolarSystemNodeDefault = memo((props: NodeProps<MapSolarSystemType>
|
|||||||
</KillsCounter>
|
</KillsCounter>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{nodeVars.labelCustom !== '' && (
|
||||||
|
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.custom)}>
|
||||||
|
<span className="[text-shadow:_0_1px_0_rgb(0_0_0_/_40%)]">{nodeVars.labelCustom}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{nodeVars.labelsInfo.map(x => (
|
{nodeVars.labelsInfo.map(x => (
|
||||||
<div key={x.id} className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES[x.id])}>
|
<div key={x.id} className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES[x.id])}>
|
||||||
{x.shortName}
|
{x.shortName}
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ export const SolarSystemNodeTheme = memo((props: NodeProps<MapSolarSystemType>)
|
|||||||
<>
|
<>
|
||||||
{nodeVars.visible && (
|
{nodeVars.visible && (
|
||||||
<div className={classes.Bookmarks}>
|
<div className={classes.Bookmarks}>
|
||||||
{nodeVars.labelCustom !== '' && (
|
|
||||||
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.custom)}>
|
|
||||||
<span className="[text-shadow:_0_1px_0_rgb(0_0_0_/_40%)]">{nodeVars.labelCustom}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{nodeVars.isShattered && (
|
{nodeVars.isShattered && (
|
||||||
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.shattered, '!pr-[2px]')}>
|
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.shattered, '!pr-[2px]')}>
|
||||||
<WdTooltipWrapper content="Shattered" position={TooltipPosition.top}>
|
<WdTooltipWrapper content="Shattered" position={TooltipPosition.top}>
|
||||||
@@ -55,6 +49,12 @@ export const SolarSystemNodeTheme = memo((props: NodeProps<MapSolarSystemType>)
|
|||||||
</KillsCounter>
|
</KillsCounter>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{nodeVars.labelCustom !== '' && (
|
||||||
|
<div className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES.custom)}>
|
||||||
|
<span className="[text-shadow:_0_1px_0_rgb(0_0_0_/_40%)]">{nodeVars.labelCustom}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{nodeVars.labelsInfo.map(x => (
|
{nodeVars.labelsInfo.map(x => (
|
||||||
<div key={x.id} className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES[x.id])}>
|
<div key={x.id} className={clsx(classes.Bookmark, MARKER_BOOKMARK_BG_STYLES[x.id])}>
|
||||||
{x.shortName}
|
{x.shortName}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const useMapCommands = () => {
|
|||||||
const ref = useRef({ update });
|
const ref = useRef({ update });
|
||||||
ref.current = { update };
|
ref.current = { update };
|
||||||
|
|
||||||
const mapUpdated = useCallback(({ hubs, system_signatures }: CommandMapUpdated) => {
|
const mapUpdated = useCallback(({ hubs, system_signatures, kills }: CommandMapUpdated) => {
|
||||||
const out: Partial<MapData> = {};
|
const out: Partial<MapData> = {};
|
||||||
|
|
||||||
if (hubs) {
|
if (hubs) {
|
||||||
@@ -19,6 +19,10 @@ export const useMapCommands = () => {
|
|||||||
out.systemSignatures = system_signatures;
|
out.systemSignatures = system_signatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kills) {
|
||||||
|
out.kills = kills.reduce((acc, x) => ({ ...acc, [x.solar_system_id]: x.kills }), {});
|
||||||
|
}
|
||||||
|
|
||||||
ref.current.update(out);
|
ref.current.update(out);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ function usePrevious<T>(value: T): T | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useLoadRoutes = () => {
|
export const useLoadRoutes = () => {
|
||||||
|
// TODO ??
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { data: routesSettings } = useRouteProvider();
|
const { data: routesSettings } = useRouteProvider();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
outCommand,
|
outCommand,
|
||||||
data: { selectedSystems, hubs, systems, connections },
|
data: { selectedSystems, hubs, systems, connections, routes },
|
||||||
} = useMapRootState();
|
} = useMapRootState();
|
||||||
|
|
||||||
const prevSys = usePrevious(systems);
|
const prevSys = usePrevious(systems);
|
||||||
@@ -38,10 +39,15 @@ export const useLoadRoutes = () => {
|
|||||||
routes_settings: routesSettings,
|
routes_settings: routesSettings,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
setLoading(true);
|
||||||
},
|
},
|
||||||
[outCommand],
|
[outCommand],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(false);
|
||||||
|
}, [routes]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedSystems.length !== 1) {
|
if (selectedSystems.length !== 1) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
|
||||||
import { OutCommand } from '@/hooks/Mapper/types/mapHandlers';
|
import { OutCommand } from '@/hooks/Mapper/types/mapHandlers';
|
||||||
import type { ActivitySummary } from '@/hooks/Mapper/components/mapRootContent/components/CharacterActivity/CharacterActivity';
|
import { ActivitySummary } from '@/hooks/Mapper/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for character activity related handlers
|
* Hook for character activity related handlers
|
||||||
|
|||||||
@@ -8,13 +8,29 @@ export const useMapUpdated = () => {
|
|||||||
const ref = useRef({ update });
|
const ref = useRef({ update });
|
||||||
ref.current = { update };
|
ref.current = { update };
|
||||||
|
|
||||||
return useCallback(({ hubs }: CommandMapUpdated) => {
|
return useCallback((props: CommandMapUpdated) => {
|
||||||
const { update } = ref.current;
|
const { update } = ref.current;
|
||||||
|
|
||||||
const out: Partial<MapRootData> = {};
|
const out: Partial<MapRootData> = {};
|
||||||
|
|
||||||
if (hubs) {
|
if ('hubs' in props) {
|
||||||
out.hubs = hubs;
|
out.hubs = props.hubs;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('system_signatures' in props) {
|
||||||
|
out.systemSignatures = props.system_signatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('following_character_eve_id' in props) {
|
||||||
|
out.userCharacters = props.user_characters;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('following_character_eve_id' in props) {
|
||||||
|
out.followingCharacterEveId = props.following_character_eve_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('main_character_eve_id' in props) {
|
||||||
|
out.mainCharacterEveId = props.main_character_eve_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(out);
|
update(out);
|
||||||
|
|||||||
Reference in New Issue
Block a user