client/posts: make discard thumbnail link delete existing custom thumb
I can see the intent, sadly this was always broken in the case where the post already has a custom thumbnail from initial load, and we don't drag any new files. It did not actually remove the existing thumbnail. Before 12c4542bb2482fac89aae9a04b15984a56bb8fb0 it would actually crash, but this now makes it behave as expected. Also properly syncs internal state with what's displayed to the user.
This commit is contained in:
parent
a496e8980f
commit
7972c34448
3 changed files with 24 additions and 15 deletions
|
@ -294,11 +294,16 @@ class Api extends events.EventTarget {
|
|||
// transform the request: upload each file, then make the request use
|
||||
// its tokens.
|
||||
data = Object.assign({}, data);
|
||||
let fileData = {};
|
||||
let abortFunction = () => {};
|
||||
let promise = Promise.resolve();
|
||||
if (files) {
|
||||
for (let key of Object.keys(files)) {
|
||||
const file = files[key];
|
||||
if (file === null) {
|
||||
fileData[key] = null;
|
||||
continue;
|
||||
}
|
||||
const fileId = this._getFileId(file);
|
||||
if (fileTokens[fileId]) {
|
||||
data[key + "Token"] = fileTokens[fileId];
|
||||
|
@ -324,7 +329,7 @@ class Api extends events.EventTarget {
|
|||
url,
|
||||
requestFactory,
|
||||
data,
|
||||
{},
|
||||
fileData,
|
||||
options
|
||||
);
|
||||
abortFunction = () => requestPromise.abort();
|
||||
|
@ -388,7 +393,7 @@ class Api extends events.EventTarget {
|
|||
if (files) {
|
||||
for (let key of Object.keys(files)) {
|
||||
const value = files[key];
|
||||
if (value.constructor === String) {
|
||||
if (value !== null && value.constructor === String) {
|
||||
data[key + "Url"] = value;
|
||||
} else {
|
||||
req.attach(key, value || new Blob());
|
||||
|
|
|
@ -178,15 +178,11 @@ class PostMainController extends BasePostController {
|
|||
if (e.detail.relations !== undefined) {
|
||||
post.relations = e.detail.relations;
|
||||
}
|
||||
if (e.detail.content !== undefined) {
|
||||
post.newContent = e.detail.content;
|
||||
}
|
||||
if (e.detail.thumbnail !== undefined) {
|
||||
post.newThumbnail = e.detail.thumbnail;
|
||||
}
|
||||
if (e.detail.source !== undefined) {
|
||||
post.source = e.detail.source;
|
||||
}
|
||||
post.newContent = e.detail.content;
|
||||
post.newThumbnail = e.detail.thumbnail;
|
||||
post.save().then(
|
||||
() => {
|
||||
this._view.sidebarControl.showSuccess("Post saved.");
|
||||
|
|
|
@ -138,10 +138,7 @@ class PostEditSidebarControl extends events.EventTarget {
|
|||
this._thumbnailRemovalLinkNode.addEventListener("click", (e) =>
|
||||
this._evtRemoveThumbnailClick(e)
|
||||
);
|
||||
this._thumbnailRemovalLinkNode.style.display = this._post
|
||||
.customThumbnailUrl
|
||||
? "block"
|
||||
: "none";
|
||||
this._thumbnailRemovalLinkUpdate(this._post);
|
||||
}
|
||||
|
||||
if (this._addNoteLinkNode) {
|
||||
|
@ -249,12 +246,25 @@ class PostEditSidebarControl extends events.EventTarget {
|
|||
this._poolsExpander.title = `Pools (${this._post.pools.length})`;
|
||||
}
|
||||
|
||||
_thumbnailRemovalLinkUpdate(post) {
|
||||
if (this._thumbnailRemovalLinkNode) {
|
||||
this._thumbnailRemovalLinkNode.style.display = post
|
||||
.customThumbnailUrl
|
||||
? "block"
|
||||
: "none";
|
||||
}
|
||||
}
|
||||
|
||||
_evtPostContentChange(e) {
|
||||
this._contentFileDropper.reset();
|
||||
this._thumbnailRemovalLinkUpdate(e.detail.post);
|
||||
this._newPostContent = null;
|
||||
}
|
||||
|
||||
_evtPostThumbnailChange(e) {
|
||||
this._thumbnailFileDropper.reset();
|
||||
this._thumbnailRemovalLinkUpdate(e.detail.post);
|
||||
this._newPostThumbnail = undefined;
|
||||
}
|
||||
|
||||
_evtRemoveThumbnailClick(e) {
|
||||
|
@ -427,9 +437,7 @@ class PostEditSidebarControl extends events.EventTarget {
|
|||
: undefined,
|
||||
|
||||
thumbnail:
|
||||
this._newPostThumbnail !== undefined
|
||||
? this._newPostThumbnail
|
||||
: undefined,
|
||||
this._newPostThumbnail,
|
||||
|
||||
source: this._sourceInputNode
|
||||
? this._sourceInputNode.value
|
||||
|
|
Reference in a new issue