rewrite fallback for themes

This commit is contained in:
btzr-io 2017-08-24 10:55:24 -06:00
parent c257691b57
commit 8e7c783750
2 changed files with 9 additions and 6 deletions

View file

@ -1,4 +1,5 @@
import * as types from "constants/action_types";
import * as settings from "constants/settings";
import lbry from "lbry";
import {
selectUpdateUrl,
@ -320,7 +321,8 @@ export function doDaemonReady() {
type: types.DAEMON_READY,
data: { page },
});
dispatch(doSetTheme());
// Load last theme selected
dispatch(doSetTheme(lbry.getClientSetting(settings.THEME)));
dispatch(doFetchDaemonSettings());
dispatch(doFileList());
};

View file

@ -67,20 +67,21 @@ export function doGetThemes() {
export function doSetTheme(name) {
return function(dispatch, getState) {
const last = lbry.getClientSetting(settings.THEME);
const find = name => themes.find(theme => theme.name === name);
// Find a theme from themes list
const find = themeName => themes.find(theme => theme.name === themeName);
// Get themes
const themes = lbry.getClientSetting(settings.THEMES);
// Find theme
const theme = find(name) || find(last) || find("light");
// Find theme and set fallback
const theme = find(name) || find("light");
if (theme.path) {
// update theme
// load css
const link = document.getElementById("theme");
link.href = theme.path;
// update theme
dispatch(doSetClientSetting(settings.THEME, theme.name));
}
};