mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-23 17:47:24 +00:00
rewrite action -> doSetTheme
This commit is contained in:
parent
1233b2d4fd
commit
2db24b059f
10 changed files with 54 additions and 62 deletions
6
ui/dist/themes/light.css
vendored
Normal file
6
ui/dist/themes/light.css
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
:root {
|
||||||
|
--color-primary: #155B4A;
|
||||||
|
--color-canvas: #f5f5f5;
|
||||||
|
--color-bg: #ffffff;
|
||||||
|
--color-bg-alt: #D9D9D9;
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ import {
|
||||||
selectHistoryForward,
|
selectHistoryForward,
|
||||||
} from "selectors/app";
|
} from "selectors/app";
|
||||||
import { doSearch } from "actions/search";
|
import { doSearch } from "actions/search";
|
||||||
import { doFetchDaemonSettings } from "actions/settings";
|
import { doFetchDaemonSettings, doSetClientSetting } from "actions/settings";
|
||||||
import { doAuthenticate } from "actions/user";
|
import { doAuthenticate } from "actions/user";
|
||||||
import { doFileList } from "actions/file_info";
|
import { doFileList } from "actions/file_info";
|
||||||
import { toQueryString } from "util/query_params";
|
import { toQueryString } from "util/query_params";
|
||||||
|
@ -351,3 +351,22 @@ export function doQuit() {
|
||||||
remote.app.quit();
|
remote.app.quit();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function doGetThemes() {
|
||||||
|
const dir = `${remote.app.getAppPath()}/dist/themes`;
|
||||||
|
|
||||||
|
// Get all .css files
|
||||||
|
const files = fs
|
||||||
|
.readdirSync(dir)
|
||||||
|
.filter(file => path.extname(file) === ".css");
|
||||||
|
|
||||||
|
return function(dispatch, getState) {
|
||||||
|
// Find themes
|
||||||
|
const themes = files.map(file => ({
|
||||||
|
name: file.replace(".css", ""),
|
||||||
|
path: `./themes/${file}`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
dispatch(doSetClientSetting("themes", themes));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import * as types from "constants/action_types";
|
import * as types from "constants/action_types";
|
||||||
|
import * as settings from "constants/settings";
|
||||||
import lbry from "lbry";
|
import lbry from "lbry";
|
||||||
import { readdirSync } from "fs";
|
|
||||||
import { extname } from "path";
|
|
||||||
import { remote } from "electron";
|
|
||||||
|
|
||||||
export function doFetchDaemonSettings() {
|
export function doFetchDaemonSettings() {
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
|
@ -45,34 +43,23 @@ export function doSetClientSetting(key, value) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doSetTheme(themeName) {
|
export function doSetTheme(name) {
|
||||||
const name = themeName || "light";
|
return function(dispatch, getState) {
|
||||||
|
const last = lbry.getClientSetting(settings.THEME);
|
||||||
|
const find = name => themes.find(theme => theme.name === name);
|
||||||
|
|
||||||
|
// Get themes
|
||||||
|
const themes = lbry.getClientSetting(settings.THEMES);
|
||||||
|
|
||||||
|
// Find theme
|
||||||
|
const theme = find(name) || find(last) || find("light");
|
||||||
|
|
||||||
|
if (theme.path) {
|
||||||
|
// update theme
|
||||||
const link = document.getElementById("theme");
|
const link = document.getElementById("theme");
|
||||||
|
|
||||||
return function(dispatch, getState) {
|
|
||||||
const { themes } = getState().settings.clientSettings;
|
|
||||||
const theme = themes.find(theme => theme.name === name);
|
|
||||||
|
|
||||||
if (theme) {
|
|
||||||
link.href = theme.path;
|
link.href = theme.path;
|
||||||
dispatch(doSetClientSetting("theme", theme));
|
|
||||||
|
dispatch(doSetClientSetting(settings.THEME, theme.name));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doGetThemes() {
|
|
||||||
const path = `${remote.app.getAppPath()}/dist/themes`;
|
|
||||||
|
|
||||||
// Get all .css files
|
|
||||||
const files = readdirSync(path).filter(file => extname(file) === ".css");
|
|
||||||
|
|
||||||
return function(dispatch, getState) {
|
|
||||||
// Find themes
|
|
||||||
const themes = files.map(file => ({
|
|
||||||
name: file.replace(".css", ""),
|
|
||||||
path: `./themes/${file}`,
|
|
||||||
}));
|
|
||||||
|
|
||||||
dispatch(doSetClientSetting("themes", themes));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
doOpenModal,
|
doOpenModal,
|
||||||
doAlertError,
|
doAlertError,
|
||||||
doRecordScroll,
|
doRecordScroll,
|
||||||
|
doGetThemes,
|
||||||
} from "actions/app";
|
} from "actions/app";
|
||||||
|
|
||||||
import { doFetchRewardedContent } from "actions/content";
|
import { doFetchRewardedContent } from "actions/content";
|
||||||
|
@ -29,6 +30,7 @@ const perform = dispatch => ({
|
||||||
updateBalance: balance => dispatch(doUpdateBalance(balance)),
|
updateBalance: balance => dispatch(doUpdateBalance(balance)),
|
||||||
fetchRewardedContent: () => dispatch(doFetchRewardedContent()),
|
fetchRewardedContent: () => dispatch(doFetchRewardedContent()),
|
||||||
recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)),
|
recordScroll: scrollPosition => dispatch(doRecordScroll(scrollPosition)),
|
||||||
|
getThemes: () => dispatch(doGetThemes()),
|
||||||
setTheme: name => dispatch(doSetTheme(name)),
|
setTheme: name => dispatch(doSetTheme(name)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ class App extends React.PureComponent {
|
||||||
checkUpgradeAvailable,
|
checkUpgradeAvailable,
|
||||||
updateBalance,
|
updateBalance,
|
||||||
fetchRewardedContent,
|
fetchRewardedContent,
|
||||||
|
getThemes,
|
||||||
setTheme,
|
setTheme,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
@ -32,6 +33,10 @@ class App extends React.PureComponent {
|
||||||
|
|
||||||
window.addEventListener("scroll", this.scrollListener);
|
window.addEventListener("scroll", this.scrollListener);
|
||||||
|
|
||||||
|
// Load themes
|
||||||
|
getThemes();
|
||||||
|
|
||||||
|
// Select theme
|
||||||
setTheme();
|
setTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ let lbry = {
|
||||||
customLighthouseServers: [],
|
customLighthouseServers: [],
|
||||||
showDeveloperMenu: false,
|
showDeveloperMenu: false,
|
||||||
language: "en",
|
language: "en",
|
||||||
theme: { name: "light", path: "" },
|
theme: "light",
|
||||||
themes: [],
|
themes: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,14 +5,8 @@ import {
|
||||||
doSetDaemonSetting,
|
doSetDaemonSetting,
|
||||||
doSetClientSetting,
|
doSetClientSetting,
|
||||||
doSetTheme,
|
doSetTheme,
|
||||||
doGetThemes,
|
|
||||||
} from "actions/settings";
|
} from "actions/settings";
|
||||||
import {
|
import { selectDaemonSettings, selectShowNsfw } from "selectors/settings";
|
||||||
selectDaemonSettings,
|
|
||||||
selectShowNsfw,
|
|
||||||
selectThemes,
|
|
||||||
selectTheme,
|
|
||||||
} from "selectors/settings";
|
|
||||||
import SettingsPage from "./view";
|
import SettingsPage from "./view";
|
||||||
|
|
||||||
const select = state => ({
|
const select = state => ({
|
||||||
|
@ -25,7 +19,6 @@ const perform = dispatch => ({
|
||||||
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)),
|
setTheme: name => dispatch(doSetTheme(name)),
|
||||||
getThemes: () => dispatch(doGetThemes()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(SettingsPage);
|
export default connect(select, perform)(SettingsPage);
|
||||||
|
|
|
@ -38,10 +38,6 @@ class SettingsPage extends React.PureComponent {
|
||||||
setTimeout(clear, 1000, { once: true });
|
setTimeout(clear, 1000, { once: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
getThemes() {
|
|
||||||
this.props.getThemes();
|
|
||||||
}
|
|
||||||
|
|
||||||
setDaemonSetting(name, value) {
|
setDaemonSetting(name, value) {
|
||||||
this.props.setDaemonSetting(name, value);
|
this.props.setDaemonSetting(name, value);
|
||||||
}
|
}
|
||||||
|
@ -118,9 +114,7 @@ class SettingsPage extends React.PureComponent {
|
||||||
|
|
||||||
onShowUnavailableChange(event) {}
|
onShowUnavailableChange(event) {}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {}
|
||||||
this.getThemes();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { daemonSettings } = this.props;
|
const { daemonSettings } = this.props;
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import * as types from "constants/action_types";
|
import * as types from "constants/action_types";
|
||||||
|
import * as settings from "constants/settings";
|
||||||
import lbry from "lbry";
|
import lbry from "lbry";
|
||||||
|
|
||||||
const reducers = {};
|
const reducers = {};
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
clientSettings: {
|
clientSettings: {
|
||||||
showNsfw: lbry.getClientSetting("showNsfw"),
|
showNsfw: lbry.getClientSetting("showNsfw"),
|
||||||
themes: [],
|
theme: lbry.getClientSetting(settings.THEME),
|
||||||
|
themes: lbry.getClientSetting(settings.THEMES),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,12 +28,6 @@ reducers[types.CLIENT_SETTING_CHANGED] = function(state, action) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[types.GET_THEMES] = function(state, action) {
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
themes: action.data.themes,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action) {
|
export default function reducer(state = defaultState, action) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
if (handler) return handler(state, action);
|
if (handler) return handler(state, action);
|
||||||
|
|
|
@ -21,13 +21,3 @@ export const selectShowNsfw = createSelector(
|
||||||
selectClientSettings,
|
selectClientSettings,
|
||||||
clientSettings => !!clientSettings.showNsfw
|
clientSettings => !!clientSettings.showNsfw
|
||||||
);
|
);
|
||||||
|
|
||||||
export const selectThemes = createSelector(
|
|
||||||
selectClientSettings,
|
|
||||||
clientSettings => clientSettings.themes
|
|
||||||
);
|
|
||||||
|
|
||||||
export const selectTheme = createSelector(
|
|
||||||
selectClientSettings,
|
|
||||||
clientSettings => clientSettings.theme
|
|
||||||
);
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue