/** * @file * @copyright 2020 Aleksej Komarov * @license MIT */ import { toFixed } from 'common/math'; import { useLocalState } from 'tgui/backend'; import { useDispatch, useSelector } from 'tgui/backend'; import { Box, Button, ColorBox, Divider, Dropdown, Flex, Input, LabeledList, NumberInput, Section, Stack, Tabs, TextArea } from 'tgui/components'; import { ChatPageSettings } from '../chat'; import { rebuildChat, saveChatToDisk, purgeChatMessageArchive } from '../chat/actions'; import { THEMES } from '../themes'; import { changeSettingsTab, updateSettings, addHighlightSetting, removeHighlightSetting, updateHighlightSetting } from './actions'; import { SETTINGS_TABS, FONTS, MAX_HIGHLIGHT_SETTINGS } from './constants'; import { selectActiveTab, selectSettings, selectHighlightSettings, selectHighlightSettingById } 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' && }
); }; export const SettingsGeneral = (props) => { const { theme, fontFamily, fontSize, lineHeight, showReconnectWarning } = useSelector(selectSettings); const dispatch = useDispatch(); const [freeFont, setFreeFont] = useLocalState('freeFont', false); return (
dispatch( updateSettings({ theme: value, }) ) } /> {(!freeFont && ( dispatch( updateSettings({ fontFamily: value, }) ) } /> )) || ( dispatch( updateSettings({ fontFamily: value, }) ) } /> )}
); }; export const MessageLimits = (props) => { const dispatch = useDispatch(); const { visibleMessageLimit, persistentMessageLimit, combineMessageLimit, combineIntervalLimit, } = useSelector(selectSettings); return (
toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ visibleMessageLimit: value, }) ) } /> toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ persistentMessageLimit: value, }) ) } /> toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ combineMessageLimit: value, }) ) } /> toFixed(value)} onDrag={(e, value) => dispatch( updateSettings({ combineIntervalLimit: value, }) ) } />
); }; export const ExportTab = (props) => { const dispatch = useDispatch(); const { logRetainDays, logLineCount, totalStoredMessages } = useSelector(selectSettings); const [purgeConfirm, setPurgeConfirm] = useLocalState('purgeConfirm', 0); return (
{/* FIXME: Implement this later on dispatch( updateSettings({ logRetainDays: value, }) ) } /> */} 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 (