Ensure correct style is pre-filled

This commit is contained in:
Gusted 2021-06-12 17:45:16 +02:00
parent 6b9dafe4ef
commit 59f3f23b55
No known key found for this signature in database
GPG Key ID: FD821B732837125F

View File

@ -367,15 +367,17 @@ const styleMan = (() => {
case 'publish': case 'publish':
if (!style._usw || !style._usw.token) { if (!style._usw || !style._usw.token) {
style._linking = true; // Ensures just the style does have the _linking property as `true`.
await saveStyle(style); for (const {style: someStyle} of dataMap.values()) {
const data = id2data(style.id); if (someStyle._id === style._id) {
if (!data) { someStyle._linking = true;
storeInMap(style); someStyle.sourceCode = style.sourceCode;
} else { } else {
data.style = style; delete someStyle._linking;
delete someStyle.sourceCode;
}
handleSave(await saveStyle(someStyle), null, null, false);
} }
style._usw = { style._usw = {
token: await tokenMan.getToken('userstylesworld', true, style), token: await tokenMan.getToken('userstylesworld', true, style),
}; };
@ -477,7 +479,7 @@ const styleMan = (() => {
return style; return style;
} }
function handleSave(style, reason, codeIsUpdated) { function handleSave(style, reason, codeIsUpdated, broadcast = true) {
const data = id2data(style.id); const data = id2data(style.id);
const method = data ? 'styleUpdated' : 'styleAdded'; const method = data ? 'styleUpdated' : 'styleAdded';
if (!data) { if (!data) {
@ -485,7 +487,7 @@ const styleMan = (() => {
} else { } else {
data.style = style; data.style = style;
} }
broadcastStyleUpdated(style, reason, method, codeIsUpdated); if (broadcast) broadcastStyleUpdated(style, reason, method, codeIsUpdated);
return style; return style;
} }