2024-05-15 16:54:55 +02:00
|
|
|
import { useState } from 'react';
|
2024-05-09 16:04:24 +02:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2024-05-09 18:29:55 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-05-10 12:46:52 +02:00
|
|
|
import styles from './settings-modal.module.css';
|
|
|
|
|
import useTheme from '../../hooks/use-theme';
|
2024-05-09 18:29:55 +02:00
|
|
|
import packageJson from '../../../package.json';
|
2024-05-15 16:54:55 +02:00
|
|
|
import AccountSettings from './account-settings';
|
|
|
|
|
import CryptoAddressSetting from './crypto-address-setting';
|
2024-05-15 21:20:14 +02:00
|
|
|
import CryptoWalletsSetting from './crypto-wallets-setting';
|
2024-05-09 16:04:24 +02:00
|
|
|
|
2024-05-10 12:46:52 +02:00
|
|
|
const commitRef = process.env.REACT_APP_COMMIT_REF;
|
|
|
|
|
const isElectron = window.isElectron === true;
|
|
|
|
|
|
|
|
|
|
const CheckForUpdates = () => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
|
|
|
|
const checkForUpdates = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
const packageRes = await fetch('https://raw.githubusercontent.com/plebbit/plebchan/master/package.json', { cache: 'no-cache' });
|
|
|
|
|
const packageData = await packageRes.json();
|
|
|
|
|
let updateAvailable = false;
|
|
|
|
|
|
|
|
|
|
if (packageJson.version !== packageData.version) {
|
|
|
|
|
const newVersionText = t('new_stable_version', { newVersion: packageData.version, oldVersion: packageJson.version });
|
|
|
|
|
const updateActionText = isElectron
|
|
|
|
|
? t('download_latest_desktop', { link: 'https://github.com/plebbit/plebchan/releases/latest', interpolation: { escapeValue: false } })
|
|
|
|
|
: t('refresh_to_update');
|
|
|
|
|
alert(newVersionText + ' ' + updateActionText);
|
|
|
|
|
updateAvailable = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commitRef && commitRef.length > 0) {
|
|
|
|
|
const commitRes = await fetch('https://api.github.com/repos/plebbit/plebchan/commits?per_page=1&sha=development', { cache: 'no-cache' });
|
|
|
|
|
const commitData = await commitRes.json();
|
|
|
|
|
|
|
|
|
|
const latestCommitHash = commitData[0].sha;
|
|
|
|
|
|
|
|
|
|
if (latestCommitHash.trim() !== commitRef.trim()) {
|
|
|
|
|
const newVersionText =
|
|
|
|
|
t('new_development_version', { newCommit: latestCommitHash.slice(0, 7), oldCommit: commitRef.slice(0, 7) }) + ' ' + t('refresh_to_update');
|
|
|
|
|
alert(newVersionText);
|
|
|
|
|
updateAvailable = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!updateAvailable) {
|
|
|
|
|
alert(
|
|
|
|
|
commitRef
|
|
|
|
|
? `${t('latest_development_version', { commit: commitRef.slice(0, 7), link: 'https://plebchan.eth.limo/#/', interpolation: { escapeValue: false } })}`
|
|
|
|
|
: `${t('latest_stable_version', { version: packageJson.version })}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
alert('Failed to fetch latest version info: ' + error);
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-05-10 17:03:33 +02:00
|
|
|
<button className={styles.checkForUpdatesButton} onClick={checkForUpdates} disabled={loading}>
|
|
|
|
|
{t('check')}
|
|
|
|
|
</button>
|
2024-05-10 12:46:52 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Style = () => {
|
2024-05-09 18:29:55 +02:00
|
|
|
const [theme, setTheme] = useTheme();
|
2024-05-09 16:04:24 +02:00
|
|
|
|
|
|
|
|
return (
|
2024-05-09 18:29:55 +02:00
|
|
|
<select className={styles.themeSettings} value={theme} onChange={(e) => setTheme(e.target.value)}>
|
|
|
|
|
<option value='yotsuba'>Yotsuba</option>
|
|
|
|
|
<option value='yotsuba-b'>Yotsuba B</option>
|
|
|
|
|
<option value='futaba'>Futaba</option>
|
|
|
|
|
<option value='burichan'>Burichan</option>
|
|
|
|
|
<option value='tomorrow'>Tomorrow</option>
|
|
|
|
|
<option value='photon'>Photon</option>
|
|
|
|
|
</select>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// prettier-ignore
|
|
|
|
|
const availableLanguages = ['ar', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fil', 'fr', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'ko', 'mr', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sq', 'sv', 'te', 'th', 'tr', 'uk', 'ur', 'vi', 'zh'];
|
|
|
|
|
|
2024-05-10 12:46:52 +02:00
|
|
|
const InterfaceLanguage = () => {
|
2024-05-09 18:29:55 +02:00
|
|
|
const { i18n } = useTranslation();
|
|
|
|
|
const { changeLanguage, language } = i18n;
|
|
|
|
|
|
|
|
|
|
const onSelectLanguage = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
|
|
|
changeLanguage(e.target.value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.languageSettings}>
|
|
|
|
|
<select value={language} onChange={onSelectLanguage}>
|
|
|
|
|
{availableLanguages.map((lang) => (
|
|
|
|
|
<option key={lang} value={lang}>
|
|
|
|
|
{lang}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
2024-05-09 16:04:24 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-15 22:23:11 +02:00
|
|
|
// const PlebbitOptionsSettings = () => {
|
|
|
|
|
// return (
|
|
|
|
|
// <>
|
|
|
|
|
// <div className={styles.setting}></div>
|
|
|
|
|
// </>
|
|
|
|
|
// );
|
|
|
|
|
// };
|
2024-05-10 17:03:33 +02:00
|
|
|
|
2024-05-09 18:29:55 +02:00
|
|
|
const SettingsModal = () => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
|
|
const closeModal = () => {
|
|
|
|
|
navigate(-1);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-10 17:03:33 +02:00
|
|
|
const [showAccountSettings, setShowAccountSettings] = useState(false);
|
2024-05-15 16:54:55 +02:00
|
|
|
const [showCryptoAddressSetting, setShowCryptoAddressSetting] = useState(false);
|
|
|
|
|
const [showCryptoWalletSettings, setShowCryptoWalletSettings] = useState(false);
|
2024-05-16 22:00:22 +02:00
|
|
|
const [expandAll, setExpandAll] = useState(false);
|
|
|
|
|
|
|
|
|
|
const handleExpandAll = () => {
|
|
|
|
|
const newExpandState = !expandAll;
|
|
|
|
|
setExpandAll(newExpandState);
|
|
|
|
|
setShowAccountSettings(newExpandState);
|
|
|
|
|
setShowCryptoAddressSetting(newExpandState);
|
|
|
|
|
setShowCryptoWalletSettings(newExpandState);
|
|
|
|
|
};
|
2024-05-10 17:03:33 +02:00
|
|
|
|
2024-05-09 18:29:55 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className={styles.overlay} onClick={closeModal}></div>
|
|
|
|
|
<div className={styles.settingsModal}>
|
|
|
|
|
<div className={styles.header}>
|
|
|
|
|
<span className={styles.version}>
|
|
|
|
|
<a href={`https://github.com/plebbit/plebchan/releases/tag/v${packageJson.version}`} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
v{packageJson.version}
|
|
|
|
|
</a>
|
|
|
|
|
{commitRef && (
|
|
|
|
|
<a href={`https://github.com/plebbit/plebchan/commit/${commitRef}`} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
#{commitRef.slice(0, 7)}
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
<span className={styles.title}>{t('settings')}</span>
|
|
|
|
|
<span className={styles.closeButton} title='close' onClick={closeModal} />
|
|
|
|
|
</div>
|
2024-05-16 22:00:22 +02:00
|
|
|
<div className={styles.expandAllSettings}>
|
|
|
|
|
[<span onClick={handleExpandAll}>{expandAll ? 'Collapse All Settings' : 'Expand All Settings'}</span>]
|
|
|
|
|
</div>
|
2024-05-10 12:46:52 +02:00
|
|
|
<div className={styles.setting}>
|
2024-05-10 17:03:33 +02:00
|
|
|
{t('update')}: <CheckForUpdates />
|
2024-05-10 12:46:52 +02:00
|
|
|
</div>
|
|
|
|
|
<div className={styles.setting}>
|
2024-05-10 17:03:33 +02:00
|
|
|
{t('style')}: <Style />
|
2024-05-10 12:46:52 +02:00
|
|
|
</div>
|
|
|
|
|
<div className={styles.setting}>
|
2024-05-10 17:03:33 +02:00
|
|
|
{t('interface_language')}: <InterfaceLanguage />
|
2024-05-10 12:46:52 +02:00
|
|
|
</div>
|
2024-05-10 17:03:33 +02:00
|
|
|
<div className={`${styles.setting} ${styles.category}`}>
|
|
|
|
|
<label onClick={() => setShowAccountSettings(!showAccountSettings)}>
|
|
|
|
|
<span className={showAccountSettings ? styles.hideButton : styles.showButton} />
|
2024-05-15 22:12:32 +02:00
|
|
|
{t('account')}
|
2024-05-10 17:03:33 +02:00
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
{showAccountSettings && <AccountSettings />}
|
2024-05-15 16:54:55 +02:00
|
|
|
<div className={`${styles.setting} ${styles.category}`}>
|
|
|
|
|
<label onClick={() => setShowCryptoAddressSetting(!showCryptoAddressSetting)}>
|
|
|
|
|
<span className={showCryptoAddressSetting ? styles.hideButton : styles.showButton} />
|
2024-05-15 22:12:32 +02:00
|
|
|
{t('crypto_address')}
|
2024-05-15 16:54:55 +02:00
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
{showCryptoAddressSetting && <CryptoAddressSetting />}
|
|
|
|
|
<div className={`${styles.setting} ${styles.category}`}>
|
|
|
|
|
<label onClick={() => setShowCryptoWalletSettings(!showCryptoWalletSettings)}>
|
|
|
|
|
<span className={showCryptoWalletSettings ? styles.hideButton : styles.showButton} />
|
2024-05-15 22:12:32 +02:00
|
|
|
{t('crypto_wallets')}
|
2024-05-15 16:54:55 +02:00
|
|
|
</label>
|
|
|
|
|
</div>
|
2024-05-15 21:20:14 +02:00
|
|
|
{showCryptoWalletSettings && <CryptoWalletsSetting />}
|
2024-05-15 22:23:11 +02:00
|
|
|
{/* <div className={`${styles.setting} ${styles.category}`}>
|
2024-05-10 17:03:33 +02:00
|
|
|
<label onClick={() => setShowPlebbitOptionsSettings(!showPlebbitOptionsSettings)}>
|
|
|
|
|
<span className={showPlebbitOptionsSettings ? styles.hideButton : styles.showButton} />
|
2024-05-15 22:12:32 +02:00
|
|
|
{t('plebbit_options')}
|
2024-05-10 17:03:33 +02:00
|
|
|
</label>
|
|
|
|
|
</div>
|
2024-05-15 22:23:11 +02:00
|
|
|
{showPlebbitOptionsSettings && <PlebbitOptionsSettings />} */}
|
2024-05-09 18:29:55 +02:00
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-09 16:04:24 +02:00
|
|
|
export default SettingsModal;
|