Add: fetch style object from DB directly in the editor (#507)
This commit is contained in:
parent
2fd531e253
commit
5cbe8a8d78
|
@ -14,6 +14,9 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
|
|||
saveStyle,
|
||||
deleteStyle,
|
||||
|
||||
getStyleFromDB: id =>
|
||||
dbExec('get', id).then(event => event.target.result),
|
||||
|
||||
download(msg) {
|
||||
delete msg.method;
|
||||
return download(msg.url, msg);
|
||||
|
|
13
edit/edit.js
13
edit/edit.js
|
@ -226,7 +226,7 @@ function isUsercss(style) {
|
|||
function initStyleData() {
|
||||
// TODO: remove .replace(/^\?/, '') when minimum_chrome_version >= 52 (https://crbug.com/601425)
|
||||
const params = new URLSearchParams(location.search.replace(/^\?/, ''));
|
||||
const id = params.get('id');
|
||||
const id = Number(params.get('id'));
|
||||
const createEmptyStyle = () => ({
|
||||
id: null,
|
||||
name: params.get('domain') ||
|
||||
|
@ -242,8 +242,8 @@ function initStyleData() {
|
|||
)
|
||||
],
|
||||
});
|
||||
return API.getStyles({id: id || -1})
|
||||
.then(([style = createEmptyStyle()]) => {
|
||||
return fetchStyle()
|
||||
.then(style => {
|
||||
styleId = style.id;
|
||||
if (styleId) sessionStorage.justEditedStyleId = styleId;
|
||||
// we set "usercss" class on <html> when <body> is empty
|
||||
|
@ -257,6 +257,13 @@ function initStyleData() {
|
|||
}
|
||||
return style;
|
||||
});
|
||||
|
||||
function fetchStyle() {
|
||||
if (id) {
|
||||
return API.getStyleFromDB(id);
|
||||
}
|
||||
return Promise.resolve(createEmptyStyle());
|
||||
}
|
||||
}
|
||||
|
||||
function initHooks() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user