Switch editor to add style mode when id=nonexistentstyle

This commit is contained in:
tophf 2017-03-21 00:35:51 +03:00
parent f746cb1581
commit 9fd067c6e3
2 changed files with 11 additions and 3 deletions

View File

@ -1087,7 +1087,11 @@ function init() {
// This is an edit // This is an edit
tE("heading", "editStyleHeading", null, false); tE("heading", "editStyleHeading", null, false);
getStylesSafe({id: params.id}).then(styles => { getStylesSafe({id: params.id}).then(styles => {
const style = styles[0]; let style = styles[0];
if (!style) {
style = {id: null, sections: []};
history.replaceState({}, document.title, location.pathname);
}
styleId = style.id; styleId = style.id;
setStyleMeta(style); setStyleMeta(style);
onload = () => { onload = () => {

View File

@ -182,9 +182,13 @@ function filterStyles(options = {}) {
const styles = id == null const styles = id == null
? (code ? cachedStyles.list : cachedStyles.noCode) ? (code ? cachedStyles.list : cachedStyles.noCode)
: [code ? cachedStyles.byId.get(id).style : cachedStyles.byId.get(id).noCode]; : [(cachedStyles.byId.get(id) || {})[code ? 'style' : 'noCode']];
const filtered = asHash ? {} : []; const filtered = asHash ? {} : [];
if (!styles) {
// may happen when users [accidentally] reopen an old URL
// of edit.html with a non-existent style id parameter
return filtered;
}
for (let i = 0, style; (style = styles[i]); i++) { for (let i = 0, style; (style = styles[i]); i++) {
if ((enabled == null || style.enabled == enabled) if ((enabled == null || style.enabled == enabled)
&& (url == null || style.url == url) && (url == null || style.url == url)