Skip to content

Commit

Permalink
[MIRROR] Improves the ForceEvent TGUI Search Function (#1096)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and StealsThePRs committed Feb 22, 2024
1 parent 796994b commit c4870e7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tgui/packages/tgui/interfaces/ForceEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c4870e7

Please sign in to comment.