Skip to content

Commit

Permalink
Fix to update NavigationInspectorPanel in real time
Browse files Browse the repository at this point in the history
  • Loading branch information
iaincollins committed Jan 29, 2023
1 parent e248991 commit 7cb6e9d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SPACE_STATIONS, SURFACE_PORTS, PLANETARY_BASES, MEGASHIPS, SOL_RADIUS_I
import { kelvinToCelius, kelvinToFahrenheit } from 'lib/convert'
import CopyOnClick from 'components/copy-on-click'

export default function NavigationInspectorPanel ({ cacheTimestamp, systemObject, setSystemObjectByName }) {
export default function NavigationInspectorPanel ({ systemObject, setSystemObjectByName }) {
if (!systemObject) return <div className='navigation-panel__inspector navigation-panel__inspector--hidden' />

const isLandable = systemObject.isLandable || SPACE_STATIONS.concat(MEGASHIPS).includes(systemObject.type) || PLANETARY_BASES.includes(systemObject.type)
Expand Down
12 changes: 9 additions & 3 deletions src/client/pages/nav/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ export default function NavListPage () {
if (['FSSDiscoveryScan', 'FSSAllBodiesFound', 'SAASignalsFound', 'FSSBodySignals', 'Scan'].includes(log.event)) {
const newSystem = await sendEvent('getSystem', { name: system?.name, useCache: false })
if (newSystem) setSystem(newSystem)

// Update system object so NavigationInspectorPanel is also updated
if (systemObject?.name) {
const newSystemObject = newSystem.objectsInSystem.filter(child => child.name.toLowerCase() === systemObject.name?.toLowerCase())[0]
setSystemObject(newSystemObject)
}
}
}), [system])
}), [system, systemObject])

useEffect(() => {
if (!router.isReady) return
Expand Down Expand Up @@ -155,8 +161,8 @@ export default function NavListPage () {
</div>
<Layout connected={connected} active={active} ready={ready} loader={!componentReady}>
<Panel layout='full-width' navigation={NavPanelNavItems('List', query)} search={search} exit={system?.isCurrentLocation === false ? () => getSystem() : null}>
<NavigationListPanel cacheTimestamp={system?._cacheTimestamp} system={system} systemObject={systemObject} setSystemObject={setSystemObject} showHelp={() => setHelpVisible(true)} />
<NavigationInspectorPanel cacheTimestamp={system?._cacheTimestamp} systemObject={systemObject} setSystemObjectByName={setSystemObjectByName} />
<NavigationListPanel system={system} systemObject={systemObject} setSystemObject={setSystemObject} showHelp={() => setHelpVisible(true)} />
<NavigationInspectorPanel systemObject={systemObject} setSystemObjectByName={setSystemObjectByName} />
</Panel>
</Layout>
</>
Expand Down
12 changes: 9 additions & 3 deletions src/client/pages/nav/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ export default function NavMapPage () {
if (['FSSDiscoveryScan', 'FSSAllBodiesFound', 'SAASignalsFound', 'FSSBodySignals', 'Scan'].includes(log.event)) {
const newSystem = await sendEvent('getSystem', { name: system?.name, useCache: false })
if (newSystem) setSystem(newSystem)

// Update system object so NavigationInspectorPanel is also updated
if (systemObject?.name) {
const newSystemObject = newSystem.objectsInSystem.filter(child => child.name.toLowerCase() === systemObject.name?.toLowerCase())[0]
setSystemObject(newSystemObject)
}
}
}), [system])
}), [system, systemObject])

useEffect(() => eventListener('gameStateChange', async (log) => {
setCmdrStatus(await sendEvent('getCmdrStatus'))
Expand All @@ -101,8 +107,8 @@ export default function NavMapPage () {
return (
<Layout connected={connected} active={active} ready={ready} loader={!componentReady}>
<Panel layout='full-width' navigation={NavPanelNavItems('Map', query)} search={search} exit={system?.isCurrentLocation === false ? () => getSystem() : null}>
<NavigationSystemMapPanel cacheTimestamp={system?._cacheTimestamp} system={system} systemObject={systemObject} setSystemObject={setSystemObject} getSystem={getSystem} cmdrStatus={cmdrStatus} />
<NavigationInspectorPanel cacheTimestamp={system?._cacheTimestamp} systemObject={systemObject} setSystemObjectByName={setSystemObjectByName} />
<NavigationSystemMapPanel system={system} systemObject={systemObject} setSystemObject={setSystemObject} getSystem={getSystem} cmdrStatus={cmdrStatus} />
<NavigationInspectorPanel systemObject={systemObject} setSystemObjectByName={setSystemObjectByName} />
</Panel>
</Layout>
)
Expand Down
1 change: 0 additions & 1 deletion src/service/lib/event-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class EventHandlers {
// }
// },
testMessage: ({name, message}) => {
console.log('sending test message', name)
// Method to simulate messages, intended for developers
if (name !== 'testMessage') broadcastEvent(name, message)
},
Expand Down

0 comments on commit 7cb6e9d

Please sign in to comment.