-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(efb): Fix refresh of atc list issue during flight #5186
Conversation
21 commits for a 1 line change? This PR increases the refresh rate. It doesn't decrease it. |
Hello, indeed ... I update the title ;) for the commits, I don't know why git add the already merged commits. I did a pull from the branch first |
src/instruments/src/EFB/ATC/ATC.tsx
Outdated
}, 60 * 1000); | ||
|
||
return () => clearInterval(interval); | ||
}, [lastUpdate]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you added lastUpdate
as a dependency to this hook? You're not using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the hook executes everytime lastUpdate change.
I had to use this 'hack' otherwise the "currentLatitude" and "currentLongitude" wasn't updated within the setInterval()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you're hiding the real dependencies currentLatitude and currentLongitude. You could refactor the loadAtc to use useCallback instead and make loadAtc a dependency. Or make currentLatitude and currentLongitude a parameter to loadAtc. The proposed change as-is is hacky and not robust at all.
src/instruments/src/EFB/ATC/ATC.tsx
Outdated
}, 60 * 1000); | ||
|
||
return () => clearInterval(interval); | ||
}, [lastUpdate]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you're hiding the real dependencies currentLatitude and currentLongitude. You could refactor the loadAtc to use useCallback instead and make loadAtc a dependency. Or make currentLatitude and currentLongitude a parameter to loadAtc. The proposed change as-is is hacky and not robust at all.
@beheh Can you show me an example with a set interval ? |
@beheh : I updated the code based on your remark. Could you validate this is better now ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, one more required change: atisSource is a dependency, so it must be in the hooks array.
There is another general cleanup you could do (but I don't see as a strict requirement): Rather than repeatedly setting apiClient.ATC.getAtc with the same atisSource every 5 seconds when the lat/long changes, you could split that part out into a separate memo which you only redo when atisSource alone changes. Then you simply redo the filtering whenever lat/long changes. In that case you could even completely drop useInterval.
src/instruments/src/EFB/ATC/ATC.tsx
Outdated
} | ||
} | ||
allAtc.sort((a1, a2) => (a1.distance > a2.distance ? 1 : -1)); | ||
allAtc = allAtc.slice(0, 26); | ||
allAtc.push({ callsign: 'UNICOM', frequency: '122.800', type: apiClient.AtcType.RADAR, visualRange: 999999, distance: 0, latitude: 0, longitude: 0, textAtis: [] }); | ||
setControllers(allAtc.filter((a) => a.distance <= a.visualRange)); | ||
}); | ||
}; | ||
}, [currentLatitude, currentLongitude]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, [currentLatitude, currentLongitude]); | |
}, [currentLatitude, currentLongitude, atisSource]); |
I remove atisSource from dependencies array because the only way to change source is via the settings page and going to settings page and coming back to atc page will reload the component I call getAtc every 5 minutes because the list of controllers can change in case a controller join or left the Network. So refresh is needed for location changes but also on regular interval. |
If it doesn't change, it's a no-op, so it doesn't hurt having it. Imagine we refactor this component in future and there's another way for the ATIS source to change, maybe a second EFB or an API for a third-party tool or something - at that point we would want this! In all other cases, it does not hurt. Until you're very familiar with hooks I would highly suggest sticking exactly to the rules of hooks, because unfortunately there's a lot of hidden footguns otherwise. Religiously following the rules of hooks protects you from these.
That seems fair. Another way you could do this is following my suggestion, but having a separate counter state variable that you increment every few minutes (and you can reset after a few iterations), so it always triggers an invalidation of the callback. |
Make sense indeed. I will add atisSource. |
@beheh All requested changes implemented. thanks |
* squash: flyPad ui overhaul (flyPadOS v2) Co-authored-by: Aaryan Kapoor <[email protected]> Co-authored-by: ZigTag <[email protected]> Co-authored-by: Saschl <[email protected]> Co-authored-by: Benjamin Dupont <[email protected]> * fix: merge conflicts * quick transitions 🗼 * fix: eslint errors * fix: layout adaption of throttle config (#4662) * final changes 🚨 * apply requested changes 🎉 * add error handling 🥟 * fix peristence 🥖 * fix lint 😡 * feat(efb): EFB Landing Performance ⚡ (#3581) * Add runway landing performance page * Update takeoff page Inop styling * Constrain inputs to sensible values (e.g. LDA must be positive) * Simplify getTailWind function * Separate wind direction/magnitude into separate inputs * Update changelog * Restrict landing performance inputs to more sensible values * Fix broken README line endings * Fix README line endings again * Convert landing widget to function component, implement auto-fill for weight and weather info * Fix lint errors * Fix eslint errors * squash: flyPad ui overhaul (flyPadOS v2) Co-authored-by: Aaryan Kapoor <[email protected]> Co-authored-by: ZigTag <[email protected]> Co-authored-by: Saschl <[email protected]> Co-authored-by: Benjamin Dupont <[email protected]> * Disable auto-fill and calculate buttons when missing data. Update ICAO input label. Pad wind direction to be 3 digits. Limit number of decimal places to sensible amounts for landing performance inputs. Add clear button for landing performance inputs. Convert SimpleInput to functional component. * Remove missed merge conflict marker * Remove files missed in merge * Adjust formatting * Remove duplicate types definition missed in merge * Fix disabled buttons not showing as disabled in-game * squash: flyPad ui overhaul (flyPadOS v2) Co-authored-by: Aaryan Kapoor <[email protected]> Co-authored-by: ZigTag <[email protected]> Co-authored-by: Saschl <[email protected]> Co-authored-by: Benjamin Dupont <[email protected]> * fix: merge conflicts * quick transitions 🗼 * fix: eslint errors * fix: layout adaption of throttle config (#4662) * final changes 🚨 * apply requested changes 🎉 * add error handling 🥟 * fix peristence 🥖 * fix lint 😡 * Fix files out of sync with flypados-v2 branch Co-authored-by: Niklas Steiner <[email protected]> Co-authored-by: Harry <[email protected]> Co-authored-by: Aaryan Kapoor <[email protected]> Co-authored-by: Aaryan Kapoor <[email protected]> Co-authored-by: ZigTag <[email protected]> Co-authored-by: Saschl <[email protected]> Co-authored-by: Benjamin Dupont <[email protected]> * fix issues and ui consistency 🍚 * fix lint 🍻 * build: re-add replace entries for flyPadOS 2 * fix lint 🍕 * fix navigraph env require 🥗 * fix lint 🍠 * fix issues 🥨 * fix: Fixed compillation errors * fix readability & dotenv import 🏣 * fix lint 🚀 * update settings page 🚨 * more changes to weather and settings 🎉 * major changes, ui consistency & layout rewrites 🎁 * fix keybind trigger 🎉 * fix focusOut function 🥽 * Add monospace font to EFB (#5102) * Add flypad themed simbrief maps to EFB (#5106) * navigraph zoom & font fixes 🎉 * fix(efb): state persistence update for landing perf (#5104) * fix(efb): state persistence update for landing perf - updated landing performance with reducer to persist state in session - updated onchange function for select component to accept boolean as arg - TODO: context and reducer for performance to be refactored in checklists pr * fix(efb): Fix map theme to be dark * feat: EFB page with the list of ATCs from VATSIM and IVAO (#4919) * display page with the list of ATCs * code simplification * fix sorting issue * clean console.log * performance improvment * remove useless css file * add wrap for text atis * align with new api-client version * merge * merge * Revert "merge" This reverts commit db6ab62. * update api-client package * Update ATC.tsx * Revert "Update ATC.tsx" This reverts commit ef45e2b. * fix issue on atc list refresh * remove console.log * add atis controllers in ATC page * remove console.log * build: switch to postcss8, fix purging * build: add A32NX_PRODUCTION_BUILD in dotenv * fix: include react-components used classes in purging * Some ESLint fixes * enable tailwindcss jit ⚡ * fix: bad tailwind safelist path * fix: actually fix react-components classes purging this time * feat(efb): Fix refresh of atc list issue during flight (#5186) * display page with the list of ATCs * code simplification * fix sorting issue * clean console.log * performance improvment * remove useless css file * add wrap for text atis * align with new api-client version * merge * merge * Revert "merge" This reverts commit db6ab62. * update api-client package * Update ATC.tsx * Revert "Update ATC.tsx" This reverts commit ef45e2b. * fix issue on atc list refresh * remove console.log * add atis controllers in ATC page * remove console.log * decrease refresh rate * fix refresh issue * remove double load * increase font-size * fix distance calculation * use useCallback and useInterval * add atisSource as dependency * try to repect rules of hook * fix lint 🌌 * disable JIT, because rollup 🎱 * fix fuel page layout ⚡ * fix button font size ☁️ Co-authored-by: ZigTag <[email protected]> Co-authored-by: Saschl <[email protected]> Co-authored-by: Benjamin Dupont <[email protected]> Co-authored-by: Matthew Winfield <[email protected]> Co-authored-by: Niklas Steiner <[email protected]> Co-authored-by: Harry <[email protected]> Co-authored-by: Aaryan Kapoor <[email protected]> Co-authored-by: benjozork <[email protected]> Co-authored-by: Johan Bouveng <[email protected]> Co-authored-by: Antony <[email protected]> Co-authored-by: ZeroKaa <[email protected]> Co-authored-by: Will Pine <[email protected]> Co-authored-by: 2hwk <[email protected]>
Summary of Changes
Reduce the interval between refresh to 1 second
Testing instructions
How to download the PR for QA
Every new commit to this PR will cause a new A32NX artifact to be created, built, and uploaded.