diff --git a/tgui/packages/tgui/interfaces/STUI.jsx b/tgui/packages/tgui/interfaces/STUI.tsx similarity index 53% rename from tgui/packages/tgui/interfaces/STUI.jsx rename to tgui/packages/tgui/interfaces/STUI.tsx index 92fde129ab95..2eda55448ea3 100644 --- a/tgui/packages/tgui/interfaces/STUI.jsx +++ b/tgui/packages/tgui/interfaces/STUI.tsx @@ -1,20 +1,45 @@ +import { useEffect, useState } from 'react'; import { useBackend, useLocalState } from '../backend'; import { Tabs, Section, Box, Flex, Input, Slider, LabeledList } from '../components'; import { Window } from '../layouts'; -export const STUI = (props) => { - const { act, data } = useBackend(); - const tabs = data.tabs || ['Attack']; - const [selectedTab, setSelectedTab] = useLocalState('progress', tabs[0]); - const logs = data.logs[selectedTab].length ? data.logs[selectedTab] : ['']; +type STUIData = { + tabs: Array; + logs: Map>; +}; +const useSearchTerm = () => { const [searchTerm, setSearchTerm] = useLocalState('searchTerm', ''); + return { searchTerm, setSearchTerm }; +}; +const useLogFont = () => { const [logsfontnumber, setLogsFontSize] = useLocalState('logsfontnumber', 7); - const logsfontsize = logsfontnumber + 'pt'; + return { + logsfontnumber, + setLogsFontSize, + }; +}; - const bigfontnumber = logsfontnumber + 5; - const bigfontsize = bigfontnumber + 'pt'; +const useTabs = () => { + const [selectedTab, setSelectedTab] = useLocalState('progress', 'Attack'); + return { + selectedTab, + setSelectedTab, + }; +}; + +export const STUI = () => { + const { data } = useBackend(); + const { selectedTab } = useTabs(); + const { searchTerm, setSearchTerm } = useSearchTerm(); + const { logsfontnumber, setLogsFontSize } = useLogFont(); + + const [logs, setLogs] = useState>([]); + + useEffect(() => { + setLogs(data.logs[selectedTab].length ? data.logs[selectedTab] : []); + }, [data.logs, selectedTab]); return ( @@ -50,27 +75,7 @@ export const STUI = (props) => { -
- {logs.map((log) => { - if (!log.toLowerCase().match(searchTerm)) { - return; - } - return ( - - {log} - - ); - })} - {(logs.length > 1 && ( - - --- End of Logs -- - - )) || ( - - --- No Logs -- - - )} -
+
@@ -78,10 +83,39 @@ export const STUI = (props) => { ); }; -const STUItabs = (props) => { - const { act, data } = useBackend(); - const tabs = data.tabs || ['Attack']; - const [selectedTab, setSelectedTab] = useLocalState('progress', tabs[0]); +const RenderLogs = (props: { readonly logs: Array }) => { + const { searchTerm } = useSearchTerm(); + const { logs } = props; + const { logsfontnumber } = useLogFont(); + const bigfontsize = logsfontnumber + 5 + 'pt'; + return ( +
+ {logs + .filter((x) => x.toLowerCase().match(searchTerm) !== null) + .map((log, i) => ( + + ))} + + {logs.length > 1 ? '--- End of Logs --' : '--- No Logs --'} + +
+ ); +}; + +const RenderLog = (props: { readonly log: string }) => { + const { logsfontnumber } = useLogFont(); + const logsfontsize = logsfontnumber + 'pt'; + return ( + + {props.log} + + ); +}; + +const STUItabs = () => { + const { act, data } = useBackend(); + const tabs = data.tabs ?? ['']; + const { selectedTab, setSelectedTab } = useTabs(); return (