/**
* @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 (
);
};
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 (
);
};
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,
})
)
}
/>
dispatch(
updateHighlightSetting({
id: id,
highlightWholeMessage: !highlightWholeMessage,
})
)
}
/>
dispatch(
updateHighlightSetting({
id: id,
matchWord: !matchWord,
})
)
}
/>
dispatch(
updateHighlightSetting({
id: id,
matchCase: !matchCase,
})
)
}
/>
dispatch(
updateHighlightSetting({
id: id,
highlightColor: value,
})
)
}
/>
);
};