2021-07-31 16:23:08 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-07-28 15:15:52 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import './Settings.scss';
|
|
|
|
|
2021-07-31 10:21:19 +02:00
|
|
|
import initMatrix from '../../../client/initMatrix';
|
2021-07-28 15:15:52 +02:00
|
|
|
import settings from '../../../client/state/settings';
|
|
|
|
|
|
|
|
import Text from '../../atoms/text/Text';
|
|
|
|
import IconButton from '../../atoms/button/IconButton';
|
|
|
|
import SegmentedControls from '../../atoms/segmented-controls/SegmentedControls';
|
|
|
|
|
2021-07-31 16:23:08 +02:00
|
|
|
import PopupWindow, { PWContentSelector } from '../../molecules/popup-window/PopupWindow';
|
2021-07-28 15:15:52 +02:00
|
|
|
import SettingTile from '../../molecules/setting-tile/SettingTile';
|
|
|
|
|
2021-07-31 16:23:08 +02:00
|
|
|
import SunIC from '../../../../public/res/ic/outlined/sun.svg';
|
|
|
|
import LockIC from '../../../../public/res/ic/outlined/lock.svg';
|
|
|
|
import InfoIC from '../../../../public/res/ic/outlined/info.svg';
|
2021-07-28 15:15:52 +02:00
|
|
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
|
|
|
|
2021-07-31 16:23:08 +02:00
|
|
|
function AppearanceSection() {
|
|
|
|
return (
|
|
|
|
<div className="settings-content">
|
|
|
|
<SettingTile
|
|
|
|
title="Theme"
|
|
|
|
content={(
|
|
|
|
<SegmentedControls
|
|
|
|
selected={settings.getThemeIndex()}
|
|
|
|
segments={[
|
|
|
|
{ text: 'Light' },
|
|
|
|
{ text: 'Silver' },
|
|
|
|
{ text: 'Dark' },
|
|
|
|
{ text: 'Butter' },
|
|
|
|
]}
|
|
|
|
onSelect={(index) => settings.setTheme(index)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SecuritySection() {
|
|
|
|
return <div className="settings-content" />;
|
|
|
|
}
|
|
|
|
|
|
|
|
function AboutSection() {
|
|
|
|
return (
|
|
|
|
<div className="settings-content">
|
|
|
|
<Text className="settings__about" variant="b1">
|
|
|
|
<a href="https://cinny.in/#about" target="_blank" rel="noreferrer">About</a>
|
|
|
|
</Text>
|
|
|
|
<Text className="settings__about">Version: 1.0.0</Text>
|
|
|
|
<Text className="settings__about">{`Device ID: ${initMatrix.matrixClient.getDeviceId()}`}</Text>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:15:52 +02:00
|
|
|
function Settings({ isOpen, onRequestClose }) {
|
2021-07-31 16:23:08 +02:00
|
|
|
const settingSections = [{
|
|
|
|
name: 'Appearance',
|
|
|
|
iconSrc: SunIC,
|
|
|
|
render() {
|
|
|
|
return <AppearanceSection />;
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: 'Security & Privacy',
|
|
|
|
iconSrc: LockIC,
|
|
|
|
render() {
|
|
|
|
return <SecuritySection />;
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: 'Help & About',
|
|
|
|
iconSrc: InfoIC,
|
|
|
|
render() {
|
|
|
|
return <AboutSection />;
|
|
|
|
},
|
|
|
|
}];
|
|
|
|
const [selectedSection, setSelectedSection] = useState(settingSections[0]);
|
|
|
|
|
2021-07-28 15:15:52 +02:00
|
|
|
return (
|
|
|
|
<PopupWindow
|
|
|
|
className="settings-window"
|
|
|
|
isOpen={isOpen}
|
|
|
|
onRequestClose={onRequestClose}
|
|
|
|
title="Settings"
|
2021-07-31 16:23:08 +02:00
|
|
|
contentTitle={selectedSection.name}
|
|
|
|
drawer={
|
|
|
|
settingSections.map((section) => (
|
|
|
|
<PWContentSelector
|
|
|
|
key={section.name}
|
|
|
|
selected={selectedSection.name === section.name}
|
|
|
|
onClick={() => setSelectedSection(section)}
|
|
|
|
iconSrc={section.iconSrc}
|
|
|
|
>
|
|
|
|
{section.name}
|
|
|
|
</PWContentSelector>
|
|
|
|
))
|
|
|
|
}
|
2021-07-28 15:15:52 +02:00
|
|
|
contentOptions={<IconButton src={CrossIC} onClick={onRequestClose} tooltip="Close" />}
|
|
|
|
>
|
2021-07-31 16:23:08 +02:00
|
|
|
{selectedSection.render()}
|
2021-07-28 15:15:52 +02:00
|
|
|
</PopupWindow>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings.propTypes = {
|
|
|
|
isOpen: PropTypes.bool.isRequired,
|
|
|
|
onRequestClose: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Settings;
|