diff --git a/tgui/packages/tgui/interfaces/ClockworkSlab.js b/tgui/packages/tgui/interfaces/ClockworkSlab.js index 3aab0d7617..56ac7b6f3a 100644 --- a/tgui/packages/tgui/interfaces/ClockworkSlab.js +++ b/tgui/packages/tgui/interfaces/ClockworkSlab.js @@ -6,12 +6,14 @@ * @license MIT */ -import { useBackend, useSharedState } from '../backend'; +import { useBackend, useLocalState, useSharedState } from '../backend'; +import { createSearch } from 'common/string'; import { map } from 'common/collections'; -import { Section, Tabs, Table, Button, Box, NoticeBox, Divider } from '../components'; +import { Section, Tabs, Table, Button, Box, NoticeBox, Divider, Input } from '../components'; import { Fragment } from 'inferno'; import { Window } from '../layouts'; +const MAX_SEARCH_RESULTS = 25; let REC_RATVAR = ""; // You may ask "why is this not inside ClockworkSlab" // It's because cslab gets called every time. Lag is bad. @@ -31,13 +33,35 @@ export const ClockworkSlab = (props, context) => { tab, setTab, ] = useSharedState(context, 'tab', 'Application'); - const scriptInTab = scripture - && scripture[tab] - || []; + const tierInfo = tier_infos && tier_infos[tab] || {}; + const [ + searchText, + setSearchText, + ] = useLocalState(context, 'searchText', ''); + + const testSearch = createSearch(searchText, script => { + return script.name + script.descname; + }); + + let bucketOfScriptures = []; + // merge it, no need to throw a var. + + const scriptInTab = (searchText.length > 0) + // Flatten all categories and apply search to it + // truthy because WE DO NOT WANT TO RETURN THIS! + && !!map((v, k) => { + bucketOfScriptures = bucketOfScriptures.concat(v); + })(scripture) + && bucketOfScriptures.filter(testSearch) + .filter((item, i) => i < MAX_SEARCH_RESULTS) + // Return the default one + || scripture[tab] + || null; // this is nullable, it's recommended that you null it. + return ( {
act('toggle')}> - Recollection - + + Search + setSearchText(value)} + mx={1} /> + + )}> {power} power is available for scripture and other consumers. @@ -67,13 +99,13 @@ export const ClockworkSlab = (props, context) => { key={name} selected={tab === name} onClick={() => setTab(name)}> - {name} + {name} ({scriptures?.length || 0}) ))(scripture)} {tierInfo.ready ? ( @@ -125,16 +157,16 @@ export const CSScripture = (props, context) => { power_unformatted = 0, } = data; const { - scriptInTab, + scriptInTab = [], } = props; return ( - scriptInTab?.map(script => ( + scriptInTab?.length > 0 ? scriptInTab.map(script => ( {script.name} @@ -176,7 +208,14 @@ export const CSScripture = (props, context) => { - )) + )) : ( + + Nothing here! + + ) ); }; @@ -209,7 +248,7 @@ export const CSTutorial = (props, context) => { {REC_RATVAR} ) : ( - + <> { not let it confuse you! You are free to use the names in pronoun form when speaking in normal languages. - + )} {recollection_categories?.map(cat => (