review fixes, plus unbreak to work with new webpack layout

This commit is contained in:
Matthew Hodgson 2017-01-18 14:06:47 +00:00
parent a0bbe3a306
commit 3d30553b7f
3 changed files with 123 additions and 96 deletions

View file

@ -174,7 +174,7 @@ module.exports = {
tintables.push(tintable); tintables.push(tintable);
}, },
tint: function(primaryColor, secondaryColor, tertiaryColor, whiteColor) { tint: function(primaryColor, secondaryColor, tertiaryColor) {
if (!cached) { if (!cached) {
calcCssFixups(); calcCssFixups();
@ -205,19 +205,16 @@ module.exports = {
tertiaryColor = rgbToHex(rgb1); tertiaryColor = rgbToHex(rgb1);
} }
if (!whiteColor) {
whiteColor = colors[3];
}
if (colors[0] === primaryColor && if (colors[0] === primaryColor &&
colors[1] === secondaryColor && colors[1] === secondaryColor &&
colors[2] === tertiaryColor && colors[2] === tertiaryColor)
colors[3] === whiteColor)
{ {
return; return;
} }
colors = [primaryColor, secondaryColor, tertiaryColor, whiteColor]; colors[0] = primaryColor;
colors[1] = secondaryColor;
colors[2] = tertiaryColor;
if (DEBUG) console.log("Tinter.tint"); if (DEBUG) console.log("Tinter.tint");
@ -231,6 +228,19 @@ module.exports = {
}); });
}, },
tintSvgWhite: function(whiteColor) {
if (!whiteColor) {
whiteColor = colors[3];
}
if (colors[3] === whiteColor) {
return;
}
colors[3] = whiteColor;
tintables.forEach(function(tintable) {
tintable();
});
},
// XXX: we could just move this all into TintableSvg, but as it's so similar // XXX: we could just move this all into TintableSvg, but as it's so similar
// to the CSS fixup stuff in Tinter (just that the fixups are stored in TintableSvg) // to the CSS fixup stuff in Tinter (just that the fixups are stored in TintableSvg)
// keeping it here for now. // keeping it here for now.

View file

@ -608,8 +608,9 @@ module.exports = React.createClass({
var i, a; var i, a;
for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) { for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
var href = a.getAttribute("href"); var href = a.getAttribute("href");
if (href.startsWith("theme-")) { var match = href.match(/^bundles\/.*\/theme-(.*)\.css$/);
if (href.startsWith("theme-" + theme + ".")) { if (match) {
if (match[1] === theme) {
a.disabled = false; a.disabled = false;
} }
else { else {
@ -621,10 +622,10 @@ module.exports = React.createClass({
if (theme === 'dark') { if (theme === 'dark') {
// abuse the tinter to change all the SVG's #fff to #2d2d2d // abuse the tinter to change all the SVG's #fff to #2d2d2d
// XXX: obviously this shouldn't be hardcoded here. // XXX: obviously this shouldn't be hardcoded here.
Tinter.tint(undefined, undefined, undefined, '#2d2d2d'); Tinter.tintSvgWhite('#2d2d2d');
} }
else { else {
Tinter.tint(undefined, undefined, undefined, '#ffffff'); Tinter.tintSvgWhite('#ffffff');
} }
}, },

View file

@ -32,6 +32,47 @@ var AddThreepid = require('../../AddThreepid');
const REACT_SDK_VERSION = const REACT_SDK_VERSION =
'dist' in package_json ? package_json.version : package_json.gitHead || "<local>"; 'dist' in package_json ? package_json.version : package_json.gitHead || "<local>";
// Enumerate some simple 'flip a bit' UI settings (if any)
const SETTINGS_LABELS = [
/*
{
id: 'alwaysShowTimestamps',
label: 'Always show message timestamps',
},
{
id: 'showTwelveHourTimestamps',
label: 'Show timestamps in 12 hour format (e.g. 2:30pm)',
},
{
id: 'useCompactLayout',
label: 'Use compact timeline layout',
},
{
id: 'useFixedWidthFont',
label: 'Use fixed width font',
},
*/
];
// Enumerate the available themes, with a nice human text label.
// XXX: Ideally we would have a theme manifest or something and they'd be nicely
// packaged up in a single directory, and/or located at the application layer.
// But for now for expedience we just hardcode them here.
const THEMES = [
{
id: 'theme',
label: 'Light theme',
value: 'light',
},
{
id: 'theme',
label: 'Dark theme',
value: 'dark',
}
];
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'UserSettings', displayName: 'UserSettings',
@ -93,6 +134,12 @@ module.exports = React.createClass({
middleOpacity: 0.3, middleOpacity: 0.3,
}); });
this._refreshFromServer(); this._refreshFromServer();
var syncedSettings = UserSettingsStore.getSyncedSettings();
if (!syncedSettings.theme) {
syncedSettings.theme = 'light';
}
this._syncedSettings = syncedSettings;
}, },
componentDidMount: function() { componentDidMount: function() {
@ -342,99 +389,68 @@ module.exports = React.createClass({
_renderUserInterfaceSettings: function() { _renderUserInterfaceSettings: function() {
var client = MatrixClientPeg.get(); var client = MatrixClientPeg.get();
var settingsLabels = [
/*
{
id: 'alwaysShowTimestamps',
label: 'Always show message timestamps',
},
{
id: 'showTwelveHourTimestamps',
label: 'Show timestamps in 12 hour format (e.g. 2:30pm)',
},
{
id: 'useCompactLayout',
label: 'Use compact timeline layout',
},
{
id: 'useFixedWidthFont',
label: 'Use fixed width font',
},
*/
];
var themes = [
{
id: 'theme',
label: 'Light theme',
value: 'light',
},
{
id: 'theme',
label: 'Dark theme',
value: 'dark',
}
];
var syncedSettings = UserSettingsStore.getSyncedSettings();
if (!syncedSettings.theme) {
syncedSettings.theme = 'light';
}
return ( return (
<div> <div>
<h3>User Interface</h3> <h3>User Interface</h3>
<div className="mx_UserSettings_section"> <div className="mx_UserSettings_section">
<div className="mx_UserSettings_toggle"> { this._renderUrlPreviewSelector() }
<input id="urlPreviewsDisabled" { SETTINGS_LABELS.map( this._renderSyncedSetting ) }
type="checkbox" { THEMES.map( this._renderThemeSelector ) }
defaultChecked={ UserSettingsStore.getUrlPreviewsDisabled() }
onChange={ e => UserSettingsStore.setUrlPreviewsDisabled(e.target.checked) }
/>
<label htmlFor="urlPreviewsDisabled">
Disable inline URL previews by default
</label>
</div>
{ settingsLabels.map( setting => {
return <div className="mx_UserSettings_toggle" key={ setting.id }>
<input id={ setting.id }
type="checkbox"
defaultChecked={ syncedSettings[setting.id] }
onChange={ e => UserSettingsStore.setSyncedSetting(setting.id, e.target.checked) }
/>
<label htmlFor={ setting.id }>
{ setting.label }
</label>
</div>
})}
{ themes.map( setting => {
return <div className="mx_UserSettings_toggle" key={ setting.id + "_" + setting.value }>
<input id={ setting.id + "_" + setting.value }
type="radio"
name={ setting.id }
value={ setting.value }
defaultChecked={ syncedSettings[setting.id] === setting.value }
onChange={ e => {
if (e.target.checked) {
UserSettingsStore.setSyncedSetting(setting.id, setting.value)
}
dis.dispatch({
action: 'set_theme',
value: setting.value,
});
}
}
/>
<label htmlFor={ setting.id + "_" + setting.value }>
{ setting.label }
</label>
</div>
})}
</div> </div>
</div> </div>
); );
}, },
_renderUrlPreviewSelector: function() {
return <div className="mx_UserSettings_toggle">
<input id="urlPreviewsDisabled"
type="checkbox"
defaultChecked={ UserSettingsStore.getUrlPreviewsDisabled() }
onChange={ e => UserSettingsStore.setUrlPreviewsDisabled(e.target.checked) }
/>
<label htmlFor="urlPreviewsDisabled">
Disable inline URL previews by default
</label>
</div>
},
_renderSyncedSetting: function(setting) {
return <div className="mx_UserSettings_toggle" key={ setting.id }>
<input id={ setting.id }
type="checkbox"
defaultChecked={ this._syncedSettings[setting.id] }
onChange={ e => UserSettingsStore.setSyncedSetting(setting.id, e.target.checked) }
/>
<label htmlFor={ setting.id }>
{ setting.label }
</label>
</div>
},
_renderThemeSelector: function(setting) {
return <div className="mx_UserSettings_toggle" key={ setting.id + "_" + setting.value }>
<input id={ setting.id + "_" + setting.value }
type="radio"
name={ setting.id }
value={ setting.value }
defaultChecked={ this._syncedSettings[setting.id] === setting.value }
onChange={ e => {
if (e.target.checked) {
UserSettingsStore.setSyncedSetting(setting.id, setting.value)
}
dis.dispatch({
action: 'set_theme',
value: setting.value,
});
}
}
/>
<label htmlFor={ setting.id + "_" + setting.value }>
{ setting.label }
</label>
</div>
},
_renderCryptoInfo: function() { _renderCryptoInfo: function() {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const deviceId = client.deviceId; const deviceId = client.deviceId;