From 47ab3eb18d66b66e68d75192ccefd6573b1ef8e1 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:56:20 +0100 Subject: [PATCH] [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 :cl: fix: ForceEvent tgui panel search is more reliable. /:cl: * Improves the ForceEvent TGUI Search Function --------- Co-authored-by: nevimer <77420409+nevimer@users.noreply.github.com> --- tgui/packages/tgui/interfaces/ForceEvent.tsx | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tgui/packages/tgui/interfaces/ForceEvent.tsx b/tgui/packages/tgui/interfaces/ForceEvent.tsx index a93ea6a5f43..4811e2fc20f 100644 --- a/tgui/packages/tgui/interfaces/ForceEvent.tsx +++ b/tgui/packages/tgui/interfaces/ForceEvent.tsx @@ -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;