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

View file

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