/** * @file * @copyright 2020 Aleksej Komarov * @license MIT */ import { toFixed } from 'common/math'; import { useState } from 'react'; import { useDispatch, useSelector } from 'tgui/backend'; import { Box, Button, Collapsible, ColorBox, Divider, Dropdown, Flex, Input, LabeledList, NumberInput, Section, Stack, Tabs, TextArea, } from 'tgui/components'; import { ChatPageSettings } from '../chat'; import { purgeChatMessageArchive, rebuildChat, saveChatToDisk, } from '../chat/actions'; import { MESSAGE_TYPES } from '../chat/constants'; import { useGame } from '../game'; import { THEMES } from '../themes'; import { addHighlightSetting, changeSettingsTab, removeHighlightSetting, updateHighlightSetting, updateSettings, updateToggle, } from './actions'; import { FONTS, MAX_HIGHLIGHT_SETTINGS, SETTINGS_TABS } from './constants'; import { selectActiveTab, selectHighlightSettingById, selectHighlightSettings, selectSettings, } from './selectors'; export const SettingsPanel = (props) => { const activeTab = useSelector(selectActiveTab); const dispatch = useDispatch(); return (
{SETTINGS_TABS.map((tab) => ( dispatch( changeSettingsTab({ tabId: tab.id, }), ) } > {tab.name} ))}
{activeTab === 'general' && } {activeTab === 'limits' && } {activeTab === 'export' && } {activeTab === 'chatPage' && } {activeTab === 'textHighlight' && } {activeTab === 'adminSettings' && }
); }; export const SettingsGeneral = (props) => { const { theme, fontFamily, fontSize, lineHeight, showReconnectWarning, prependTimestamps, interleave, interleaveColor, } = useSelector(selectSettings); const dispatch = useDispatch(); const [freeFont, setFreeFont] = useState(false); return (
dispatch( updateSettings({ theme: value, }), ) } /> {(!freeFont && ( dispatch( updateSettings({ fontFamily: value, }), ) } /> )) || ( dispatch( updateSettings({ fontFamily: value, }), ) } /> )} toFixed(value)} onChange={(e, value) => dispatch( updateSettings({ fontSize: value, }), ) } /> toFixed(value, 2)} onDrag={(e, value) => dispatch( updateSettings({ lineHeight: value, }), ) } /> dispatch( updateSettings({ showReconnectWarning: !showReconnectWarning, }), ) } /> dispatch( updateSettings({ interleave: !interleave, }), ) } /> dispatch( updateSettings({ interleaveColor: value, }), ) } /> dispatch( updateSettings({ prependTimestamps: !prependTimestamps, }), ) } /> Can freeze the chat for a while.
); }; export const MessageLimits = (props) => { const dispatch = useDispatch(); const { visibleMessageLimit, persistentMessageLimit, combineMessageLimit, combineIntervalLimit, saveInterval, } = useSelector(selectSettings); return (
toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ visibleMessageLimit: value, }), ) } />   {visibleMessageLimit >= 5000 ? ( Impacts performance! ) : ( '' )} toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ persistentMessageLimit: value, }), ) } />   {persistentMessageLimit >= 2500 ? ( Delays initialization! ) : ( '' )} toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ combineMessageLimit: value, }), ) } /> toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ combineIntervalLimit: value, }), ) } /> toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ saveInterval: value, }), ) } />   {saveInterval <= 3 ? ( Warning, experimental! Might crash! ) : ( '' )}
); }; export const ExportTab = (props) => { const dispatch = useDispatch(); const game = useGame(); const { storedRounds, exportStart, exportEnd, logRetainRounds, logEnable, logLineCount, logLimit, totalStoredMessages, storedTypes, } = useSelector(selectSettings); const [purgeConfirm, setPurgeConfirm] = useState(0); const [logConfirm, setLogConfirm] = useState(0); return (
{logEnable ? ( logConfirm ? ( ) : ( ) ) : ( )} Round ID:  {game.roundId ? game.roundId : 'ERROR'} {logEnable ? ( <> toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ logRetainRounds: value, }), ) } />   {logRetainRounds > 3 ? ( Warning, might crash! ) : ( '' )} toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ logLimit: value, }), ) } />   {logLimit > 0 ? ( 10000 ? 'red' : 'label'} > {logLimit > 15000 ? 'Warning, might crash! Takes priority above round retention.' : 'Takes priority above round retention.'} ) : ( '' )}
{MESSAGE_TYPES.map((typeDef) => ( dispatch( updateToggle({ type: typeDef.type, }), ) } > {typeDef.name} ))}
) : ( '' )} toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ exportStart: value, }), ) } /> toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ exportEnd: value, }), ) } />   Stored Rounds:  {storedRounds} toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ logLineCount: value, }), ) } /> {totalStoredMessages} {purgeConfirm > 0 ? ( ) : ( )}
); }; const TextHighlightSettings = (props) => { const highlightSettings = useSelector(selectHighlightSettings); const dispatch = useDispatch(); return (
{highlightSettings.map((id, i) => ( ))} {highlightSettings.length < MAX_HIGHLIGHT_SETTINGS && ( )}
Can freeze the chat for a while.
); }; const TextHighlightSetting = (props) => { const { id, ...rest } = props; const highlightSettingById = useSelector(selectHighlightSettingById); const dispatch = useDispatch(); const { highlightColor, highlightText, blacklistText, highlightWholeMessage, highlightBlacklist, matchWord, matchCase, } = highlightSettingById[id]; return ( dispatch( updateHighlightSetting({ id: id, highlightBlacklist: !highlightBlacklist, }), ) } > Highlight Blacklist dispatch( updateHighlightSetting({ id: id, highlightWholeMessage: !highlightWholeMessage, }), ) } > Whole Message dispatch( updateHighlightSetting({ id: id, matchWord: !matchWord, }), ) } > Exact dispatch( updateHighlightSetting({ id: id, matchCase: !matchCase, }), ) } > Case dispatch( updateHighlightSetting({ id: id, highlightColor: value, }), ) } />