[MIRROR] Improves the ForceEvent TGUI Search Function (#26603)

* Improves the ForceEvent TGUI Search Function (#81541)

## About The Pull Request

Fixes the search logic about checking for nulls, mostly to prevent it
from being broken if something else is wrong.

## Why It's Good For The Game

Less bugs, more reliable in the case of errors.

## Changelog
🆑
fix: ForceEvent tgui panel search is more reliable.
/🆑

* Improves the ForceEvent TGUI Search Function

---------

Co-authored-by: nevimer <77420409+nevimer@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-02-22 16:56:20 +01:00
committed by GitHub
co-authored by nevimer
parent 1523ba2828
commit 47ab3eb18d
+17 -8
View File
@@ -21,13 +21,15 @@ const paginateEvents = (events: Event[], maxPerPage: number): Event[][] => {
let maxChars = EVENT_PAGE_MAXCHARS;
for (const event of events) {
maxChars -= event.name.length;
if (maxChars <= 0) {
// would overflow the next line over
itemsToAdd = maxPerPage;
maxChars = EVENT_PAGE_MAXCHARS - event.name.length;
pages.push(page);
page = [];
if (event.name && typeof event.name === 'string') {
maxChars -= event.name.length;
if (maxChars <= 0) {
// would overflow the next line over
itemsToAdd = maxPerPage;
maxChars = EVENT_PAGE_MAXCHARS - event.name.length;
pages.push(page);
page = [];
}
}
page.push(event);
itemsToAdd--;
@@ -127,7 +129,14 @@ export const EventSection = (props) => {
return false;
}
// remove events not being searched for, if a search is active
if (searchQuery && !event.name.toLowerCase().includes(searchQuery)) {
if (
searchQuery &&
event.name &&
typeof event.name === 'string' &&
searchQuery &&
typeof searchQuery === 'string' &&
!event.name.toLowerCase().includes(searchQuery.toLowerCase())
) {
return false;
}
return true;