import React, { useState } from 'react'; import PropTypes from 'prop-types'; import './Settings.scss'; import initMatrix from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; import settings from '../../../client/state/settings'; import { toggleSystemTheme, toggleMarkdown, toggleMembershipEvents, toggleNickAvatarEvents, toggleNotifications, } from '../../../client/action/settings'; import logout from '../../../client/action/logout'; import { usePermission } from '../../hooks/usePermission'; import Text from '../../atoms/text/Text'; import IconButton from '../../atoms/button/IconButton'; import Button from '../../atoms/button/Button'; import Toggle from '../../atoms/button/Toggle'; import SegmentedControls from '../../atoms/segmented-controls/SegmentedControls'; import PopupWindow, { PWContentSelector } from '../../molecules/popup-window/PopupWindow'; import SettingTile from '../../molecules/setting-tile/SettingTile'; import ImportE2ERoomKeys from '../../molecules/import-export-e2e-room-keys/ImportE2ERoomKeys'; import ExportE2ERoomKeys from '../../molecules/import-export-e2e-room-keys/ExportE2ERoomKeys'; import ProfileEditor from '../profile-editor/ProfileEditor'; import SettingsIC from '../../../../public/res/ic/outlined/settings.svg'; import SunIC from '../../../../public/res/ic/outlined/sun.svg'; import LockIC from '../../../../public/res/ic/outlined/lock.svg'; import BellIC from '../../../../public/res/ic/outlined/bell.svg'; import InfoIC from '../../../../public/res/ic/outlined/info.svg'; import PowerIC from '../../../../public/res/ic/outlined/power.svg'; import CrossIC from '../../../../public/res/ic/outlined/cross.svg'; import CinnySVG from '../../../../public/res/svg/cinny.svg'; function GeneralSection() { return (
)} />
); } function AppearanceSection() { const [, updateState] = useState({}); return (
{ toggleSystemTheme(); updateState({}); }} /> )} content={Use light or dark mode based on the system's settings.} /> {(() => { if (!settings.useSystemTheme) { return ( settings.setTheme(index)} /> )} /> ); } })()} { toggleMarkdown(); updateState({}); }} /> )} content={Format messages with markdown syntax before sending.} /> { toggleMembershipEvents(); updateState({}); }} /> )} content={Hide membership change messages from room timeline. (Join, Leave, Invite, Kick and Ban)} /> { toggleNickAvatarEvents(); updateState({}); }} /> )} content={Hide nick and avatar change messages from room timeline.} />
); } function NotificationsSection() { const [permission, setPermission] = usePermission('notifications', window.Notification?.permission); const [, updateState] = useState({}); const renderOptions = () => { if (window.Notification === undefined) { return Not supported in this browser.; } if (permission === 'granted') { return ( { toggleNotifications(); setPermission(window.Notification?.permission); updateState({}); }} /> ); } return ( ); }; return (
Show notifications when new messages arrive.} />
); } function SecuritySection() { return (
Use this device ID-key combo to verify or manage this session from Element client.} /> Export end-to-end encryption room keys to decrypt old messages in other session. In order to encrypt keys you need to set a password, which will be used while importing. )} /> {'To decrypt older messages, Export E2EE room keys from Element (Settings > Security & Privacy > Encryption > Cryptography) and import them here. Imported keys are encrypted so you\'ll have to enter the password you set in order to decrypt it.'} )} />
); } function AboutSection() { return (
Cinny logo
Cinny {`v${cons.version}`} Yet another matrix client
Credits
); } function Settings({ isOpen, onRequestClose }) { const settingSections = [{ name: 'General', iconSrc: SettingsIC, render() { return ; }, }, { name: 'Appearance', iconSrc: SunIC, render() { return ; }, }, { name: 'Notifications', iconSrc: BellIC, render() { return ; }, }, { name: 'Security & Privacy', iconSrc: LockIC, render() { return ; }, }, { name: 'Help & About', iconSrc: InfoIC, render() { return ; }, }]; const [selectedSection, setSelectedSection] = useState(settingSections[0]); const handleLogout = () => { if (confirm('Confirm logout')) logout(); }; return ( { settingSections.map((section) => ( setSelectedSection(section)} iconSrc={section.iconSrc} > {section.name} )) } Logout )} contentOptions={} > {selectedSection.render()} ); } Settings.propTypes = { isOpen: PropTypes.bool.isRequired, onRequestClose: PropTypes.func.isRequired, }; export default Settings;