theme refactor and bug fix
This commit is contained in:
parent
de69a7c76b
commit
1019a94221
10 changed files with 66 additions and 63 deletions
1
ui/dist/index.html
vendored
1
ui/dist/index.html
vendored
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400italic,600italic,600' rel='stylesheet' type='text/css'>
|
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400italic,600italic,600' rel='stylesheet' type='text/css'>
|
||||||
<link href="./css/all.css" rel="stylesheet" type="text/css" media="screen,print" />
|
<link href="./css/all.css" rel="stylesheet" type="text/css" media="screen,print" />
|
||||||
<link id="theme" href="" rel="stylesheet" type="text/css" media="screen,print" />
|
|
||||||
<link rel="icon" type="image/png" href="./img/fav/favicon-32x32.png" sizes="32x32">
|
<link rel="icon" type="image/png" href="./img/fav/favicon-32x32.png" sizes="32x32">
|
||||||
<link rel="icon" type="image/png" href="./img/fav/favicon-194x194.png" sizes="194x194">
|
<link rel="icon" type="image/png" href="./img/fav/favicon-194x194.png" sizes="194x194">
|
||||||
<link rel="icon" type="image/png" href="./img/fav/favicon-96x96.png" sizes="96x96">
|
<link rel="icon" type="image/png" href="./img/fav/favicon-96x96.png" sizes="96x96">
|
||||||
|
|
1
ui/dist/quit.html
vendored
1
ui/dist/quit.html
vendored
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400italic,600italic,600' rel='stylesheet' type='text/css'>
|
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400italic,600italic,600' rel='stylesheet' type='text/css'>
|
||||||
<link href="./css/all.css" rel="stylesheet" type="text/css" media="screen,print" />
|
<link href="./css/all.css" rel="stylesheet" type="text/css" media="screen,print" />
|
||||||
<link href="./js/mediaelement/mediaelementplayer.css" rel="stylesheet" type="text/css" />
|
|
||||||
<link rel="icon" type="image/png" href="./img/fav/favicon-32x32.png" sizes="32x32">
|
<link rel="icon" type="image/png" href="./img/fav/favicon-32x32.png" sizes="32x32">
|
||||||
<link rel="icon" type="image/png" href="./img/fav/favicon-194x194.png" sizes="194x194">
|
<link rel="icon" type="image/png" href="./img/fav/favicon-194x194.png" sizes="194x194">
|
||||||
<link rel="icon" type="image/png" href="./img/fav/favicon-96x96.png" sizes="96x96">
|
<link rel="icon" type="image/png" href="./img/fav/favicon-96x96.png" sizes="96x96">
|
||||||
|
|
|
@ -176,7 +176,6 @@ export function doDaemonReady() {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
dispatch(doAuthenticate());
|
dispatch(doAuthenticate());
|
||||||
dispatch({ type: types.DAEMON_READY });
|
dispatch({ type: types.DAEMON_READY });
|
||||||
//dispatch(doSetTheme(lbry.getClientSetting(settings.THEME)));
|
|
||||||
dispatch(doFetchDaemonSettings());
|
dispatch(doFetchDaemonSettings());
|
||||||
dispatch(doFileList());
|
dispatch(doFileList());
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as types from "constants/action_types";
|
import * as types from "constants/action_types";
|
||||||
import * as settings from "constants/settings";
|
import * as settings from "constants/settings";
|
||||||
|
import { doAlertError } from "actions/app";
|
||||||
import batchActions from "util/batchActions";
|
import batchActions from "util/batchActions";
|
||||||
|
|
||||||
import lbry from "lbry";
|
import lbry from "lbry";
|
||||||
|
@ -8,8 +9,7 @@ import http from "http";
|
||||||
|
|
||||||
const { remote } = require("electron");
|
const { remote } = require("electron");
|
||||||
const { extname } = require("path");
|
const { extname } = require("path");
|
||||||
const { download } = remote.require("electron-dl");
|
const { readdir } = remote.require("fs");
|
||||||
const { readdirSync } = remote.require("fs");
|
|
||||||
|
|
||||||
export function doFetchDaemonSettings() {
|
export function doFetchDaemonSettings() {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
|
@ -53,45 +53,23 @@ export function doSetClientSetting(key, value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doGetThemes() {
|
export function doGetThemes() {
|
||||||
const dir = `${remote.app.getAppPath()}/dist/themes`;
|
|
||||||
|
|
||||||
if (!fs.existsSync(dir)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all .css files
|
|
||||||
const files = readdirSync(dir).filter(file => extname(file) === ".css");
|
|
||||||
|
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
// Find themes
|
const dir = `${remote.app.getAppPath()}/dist/themes`;
|
||||||
const themes = files.map(file => ({
|
|
||||||
name: file.replace(".css", ""),
|
|
||||||
path: `./themes/${file}`,
|
|
||||||
}));
|
|
||||||
|
|
||||||
dispatch(doSetClientSetting(settings.THEMES, themes));
|
readdir(dir, (error, files) => {
|
||||||
};
|
if (!error) {
|
||||||
}
|
dispatch(
|
||||||
|
doSetClientSetting(
|
||||||
export function doSetTheme(name) {
|
settings.THEMES,
|
||||||
return function(dispatch, getState) {
|
files
|
||||||
// Find a theme from themes list
|
.filter(file => extname(file) === ".css")
|
||||||
const find = themeName => themes.find(theme => theme.name === themeName);
|
.map(file => file.replace(".css", ""))
|
||||||
|
)
|
||||||
// Get themes
|
);
|
||||||
const themes = lbry.getClientSetting(settings.THEMES);
|
} else {
|
||||||
|
dispatch(doAlertError(error));
|
||||||
// Find theme and set fallback
|
}
|
||||||
const theme = find(name) || find("light");
|
});
|
||||||
|
|
||||||
if (theme.path) {
|
|
||||||
// load css
|
|
||||||
const link = document.getElementById("theme");
|
|
||||||
link.href = theme.path;
|
|
||||||
|
|
||||||
// update theme
|
|
||||||
dispatch(doSetClientSetting(settings.THEME, theme.name));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import Router from "component/router/index";
|
import Router from "component/router/index";
|
||||||
import Header from "component/header";
|
import Header from "component/header";
|
||||||
|
import Theme from "component/theme";
|
||||||
import ModalRouter from "modal/modalRouter";
|
import ModalRouter from "modal/modalRouter";
|
||||||
import lbry from "lbry";
|
import lbry from "lbry";
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ class App extends React.PureComponent {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div id="window">
|
<div id="window">
|
||||||
|
<Theme />
|
||||||
<Header />
|
<Header />
|
||||||
<div id="main-content">
|
<div id="main-content">
|
||||||
<Router />
|
<Router />
|
||||||
|
|
10
ui/js/component/theme/index.js
Normal file
10
ui/js/component/theme/index.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import React from "react";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { selectThemePath } from "selectors/settings.js";
|
||||||
|
import Theme from "./view";
|
||||||
|
|
||||||
|
const select = state => ({
|
||||||
|
themePath: selectThemePath(state),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(select, null)(Theme);
|
21
ui/js/component/theme/view.jsx
Normal file
21
ui/js/component/theme/view.jsx
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const Theme = props => {
|
||||||
|
const { themePath } = props;
|
||||||
|
|
||||||
|
if (!themePath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<link
|
||||||
|
id="theme"
|
||||||
|
href={themePath}
|
||||||
|
rel="stylesheet"
|
||||||
|
type="text/css"
|
||||||
|
media="screen,print"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Theme;
|
|
@ -1,5 +1,6 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
import * as settings from "constants/settings";
|
||||||
import { doClearCache } from "actions/app";
|
import { doClearCache } from "actions/app";
|
||||||
import {
|
import {
|
||||||
doSetDaemonSetting,
|
doSetDaemonSetting,
|
||||||
|
@ -9,6 +10,7 @@ import {
|
||||||
doChangeLanguage,
|
doChangeLanguage,
|
||||||
} from "actions/settings";
|
} from "actions/settings";
|
||||||
import {
|
import {
|
||||||
|
makeSelectClientSetting,
|
||||||
selectDaemonSettings,
|
selectDaemonSettings,
|
||||||
selectShowNsfw,
|
selectShowNsfw,
|
||||||
selectLanguages,
|
selectLanguages,
|
||||||
|
@ -21,14 +23,14 @@ const select = state => ({
|
||||||
showNsfw: selectShowNsfw(state),
|
showNsfw: selectShowNsfw(state),
|
||||||
language: selectCurrentLanguage(state),
|
language: selectCurrentLanguage(state),
|
||||||
languages: selectLanguages(state),
|
languages: selectLanguages(state),
|
||||||
|
theme: makeSelectClientSetting(settings.THEME)(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
|
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
|
||||||
clearCache: () => dispatch(doClearCache()),
|
clearCache: () => dispatch(doClearCache()),
|
||||||
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
||||||
setTheme: name => dispatch(doSetTheme(name)),
|
getThemes: () => dispatch(doGetThemes()),
|
||||||
getThemes: () => dispatch(doGetThemes),
|
|
||||||
changeLanguage: newLanguage => dispatch(doChangeLanguage(newLanguage)),
|
changeLanguage: newLanguage => dispatch(doChangeLanguage(newLanguage)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -42,19 +42,6 @@ class SettingsPage extends React.PureComponent {
|
||||||
this.props.setDaemonSetting(name, value);
|
this.props.setDaemonSetting(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
setClientSetting(name, value) {
|
|
||||||
lbry.setClientSetting(name, value);
|
|
||||||
this._onSettingSaveSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
setTheme(value) {
|
|
||||||
this.props.setTheme(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
getThemes() {
|
|
||||||
this.props.getThemes();
|
|
||||||
}
|
|
||||||
|
|
||||||
onRunOnStartChange(event) {
|
onRunOnStartChange(event) {
|
||||||
this.setDaemonSetting("run_on_startup", event.target.checked);
|
this.setDaemonSetting("run_on_startup", event.target.checked);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +64,7 @@ class SettingsPage extends React.PureComponent {
|
||||||
|
|
||||||
onThemeChange(event) {
|
onThemeChange(event) {
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
this.setTheme(value);
|
this.props.setClientSetting(settings.THEME, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// onMaxUploadPrefChange(isLimited) {
|
// onMaxUploadPrefChange(isLimited) {
|
||||||
|
@ -118,13 +105,13 @@ class SettingsPage extends React.PureComponent {
|
||||||
onShowUnavailableChange(event) {}
|
onShowUnavailableChange(event) {}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.getThemes();
|
this.props.getThemes();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {}
|
componentDidMount() {}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { daemonSettings, language, languages } = this.props;
|
const { daemonSettings, language, languages, theme } = this.props;
|
||||||
|
|
||||||
if (!daemonSettings || Object.keys(daemonSettings).length === 0) {
|
if (!daemonSettings || Object.keys(daemonSettings).length === 0) {
|
||||||
return (
|
return (
|
||||||
|
@ -270,12 +257,12 @@ class SettingsPage extends React.PureComponent {
|
||||||
<FormField
|
<FormField
|
||||||
type="select"
|
type="select"
|
||||||
onChange={this.onThemeChange.bind(this)}
|
onChange={this.onThemeChange.bind(this)}
|
||||||
defaultValue={lbry.getClientSetting("theme")}
|
value={theme}
|
||||||
className="form-field__input--inline"
|
className="form-field__input--inline"
|
||||||
>
|
>
|
||||||
{this.state.themes.map((theme, index) =>
|
{this.state.themes.map((theme, index) =>
|
||||||
<option key={index} value={theme.name}>
|
<option key={theme} value={theme}>
|
||||||
{__(`${theme.name} theme`)}
|
{theme}
|
||||||
</option>
|
</option>
|
||||||
)}
|
)}
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as settings from "constants/settings";
|
||||||
import { createSelector } from "reselect";
|
import { createSelector } from "reselect";
|
||||||
|
|
||||||
const _selectState = state => state.settings || {};
|
const _selectState = state => state.settings || {};
|
||||||
|
@ -33,3 +34,8 @@ export const selectLanguages = createSelector(
|
||||||
_selectState,
|
_selectState,
|
||||||
state => state.languages || {}
|
state => state.languages || {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectThemePath = createSelector(
|
||||||
|
makeSelectClientSetting(settings.THEME),
|
||||||
|
theme => "themes/" + (theme || "light") + ".css"
|
||||||
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue