2017-02-28 21:32:23 +00:00
|
|
|
import React, {PureComponent, PropTypes} from 'react';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-08 05:52:17 +00:00
|
|
|
import Button from '../base/button';
|
|
|
|
import Link from '../base/link';
|
2017-01-20 21:54:03 +00:00
|
|
|
|
2017-02-26 21:12:51 +00:00
|
|
|
import imgLight from '../../images/light.png';
|
|
|
|
import imgDark from '../../images/dark.png';
|
|
|
|
import imgDefault from '../../images/default.png';
|
|
|
|
import imgSolarizedLight from '../../images/solarized-light.png';
|
|
|
|
import imgSolarizedDark from '../../images/solarized-dark.png';
|
|
|
|
import imgSolarized from '../../images/solarized.png';
|
|
|
|
import imgRailscasts from '../../images/railscasts.png';
|
|
|
|
import imgPurple from '../../images/purple.png';
|
|
|
|
import imgMaterial from '../../images/material.png';
|
2017-01-23 22:41:31 +00:00
|
|
|
import * as session from '../../../sync/session';
|
2017-01-20 21:54:03 +00:00
|
|
|
|
2017-01-23 22:41:31 +00:00
|
|
|
const THEMES_PER_ROW = 3;
|
|
|
|
const THEMES = [
|
2017-01-20 21:54:03 +00:00
|
|
|
{key: 'default', name: 'Insomnia', img: imgDefault},
|
|
|
|
{key: 'light', name: 'Simple Light', img: imgLight},
|
2017-01-24 03:35:02 +00:00
|
|
|
{key: 'dark', name: 'Simple Dark', img: imgDark},
|
2017-01-23 22:41:31 +00:00
|
|
|
{key: 'purple', name: 'Purple', img: imgPurple, paid: true},
|
|
|
|
{key: 'material', name: 'Material', img: imgMaterial, paid: true},
|
|
|
|
{key: 'solarized', name: 'Solarized', img: imgSolarized, paid: true},
|
|
|
|
{key: 'solarized-light', name: 'Solarized Light', img: imgSolarizedLight, paid: true},
|
|
|
|
{key: 'solarized-dark', name: 'Solarized Dark', img: imgSolarizedDark, paid: true},
|
2017-03-03 20:09:08 +00:00
|
|
|
{key: 'railscasts', name: 'Railscasts', img: imgRailscasts, paid: true}
|
2017-01-23 22:41:31 +00:00
|
|
|
];
|
2017-01-20 21:54:03 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-03-08 05:52:17 +00:00
|
|
|
class Theme extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2017-03-03 20:09:08 +00:00
|
|
|
isPremium: window.localStorage.getItem('settings.theme.isPremium') || false
|
2017-03-03 01:44:07 +00:00
|
|
|
};
|
|
|
|
}
|
2017-01-23 22:41:31 +00:00
|
|
|
|
|
|
|
async componentDidMount () {
|
|
|
|
// NOTE: This is kind of sketchy because we're relying on our parent (tab view)
|
|
|
|
// to remove->add us every time our tab is shown. If it didn't, we would need to
|
|
|
|
// also hook into componentWillUpdate somehow to refresh more often.
|
|
|
|
|
|
|
|
if (!session.isLoggedIn()) {
|
|
|
|
this.setState({isPremium: false});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {isPremium} = await session.whoami();
|
|
|
|
if (this.state.isPremium !== isPremium) {
|
|
|
|
this.setState({isPremium});
|
2017-03-03 20:09:08 +00:00
|
|
|
window.localStorage.setItem('settings.theme.isPremium', isPremium);
|
2017-01-23 22:41:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
renderTheme (theme) {
|
2017-01-20 21:54:03 +00:00
|
|
|
const {handleChangeTheme, activeTheme} = this.props;
|
2017-01-23 22:41:31 +00:00
|
|
|
const {isPremium} = this.state;
|
|
|
|
const isActive = activeTheme === theme.key;
|
|
|
|
const disabled = theme.paid && !isPremium;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={theme.key} className="themes__theme" style={{maxWidth: `${100 / THEMES_PER_ROW}%`}}>
|
|
|
|
<h2 className="txt-lg">
|
|
|
|
{theme.name}
|
2017-03-03 20:09:08 +00:00
|
|
|
{' '}
|
2017-01-23 22:41:31 +00:00
|
|
|
{isActive ? <span className="no-margin-top faint italic txt-md">(Active)</span> : null}
|
|
|
|
</h2>
|
|
|
|
{disabled ? (
|
2017-03-01 21:15:56 +00:00
|
|
|
<Link button href="https://insomnia.rest/pricing/" className="themes__theme--locked">
|
2017-01-23 22:41:31 +00:00
|
|
|
<img src={theme.img} alt={theme.name} style={{maxWidth: '100%'}}/>
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
<Button onClick={handleChangeTheme} value={theme.key}>
|
|
|
|
<img src={theme.img} alt={theme.name} style={{maxWidth: '100%'}}/>
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2017-01-23 22:41:31 +00:00
|
|
|
|
|
|
|
renderThemeRows (themes) {
|
|
|
|
const rows = [];
|
|
|
|
let row = [];
|
|
|
|
|
|
|
|
for (const theme of themes) {
|
|
|
|
row.push(theme);
|
|
|
|
if (row.length === THEMES_PER_ROW) {
|
|
|
|
rows.push(row);
|
|
|
|
row = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the last row if it wasn't finished
|
|
|
|
if (row.length) {
|
|
|
|
rows.push(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rows.map((row, i) => (
|
|
|
|
<div key={i} className="themes__row">
|
|
|
|
{row.map(this.renderTheme)}
|
|
|
|
</div>
|
|
|
|
));
|
2017-03-03 20:09:08 +00:00
|
|
|
}
|
2017-01-23 22:41:31 +00:00
|
|
|
|
|
|
|
render () {
|
2017-01-20 21:54:03 +00:00
|
|
|
return (
|
2017-03-29 02:21:49 +00:00
|
|
|
<div className="themes">
|
|
|
|
<h1 className="no-margin-top pad">Color Themes</h1>
|
2017-01-23 22:41:31 +00:00
|
|
|
{this.renderThemeRows(THEMES)}
|
2017-01-20 21:54:03 +00:00
|
|
|
</div>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2017-01-20 21:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 05:52:17 +00:00
|
|
|
Theme.propTypes = {
|
2017-01-20 21:54:03 +00:00
|
|
|
handleChangeTheme: PropTypes.func.isRequired,
|
2017-03-03 20:09:08 +00:00
|
|
|
activeTheme: PropTypes.string.isRequired
|
2017-01-20 21:54:03 +00:00
|
|
|
};
|
|
|
|
|
2017-03-08 05:52:17 +00:00
|
|
|
export default Theme;
|