Small message cleanup
parent
2f82ecf301
commit
957bac6da1
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "szuru-chrome",
|
"name": "szuru-chrome",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"description": "Import media from various sites into szurubooru",
|
"description": "Import media from various sites into szurubooru",
|
||||||
"author": "neobooru",
|
"author": "neobooru",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ export default Vue.extend({
|
||||||
// Try to upload the post to the selected szurubooru instance
|
// Try to upload the post to the selected szurubooru instance
|
||||||
async upload() {
|
async upload() {
|
||||||
this.clearMessages();
|
this.clearMessages();
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
|
||||||
if (!this.post || !this.post.imageUrl) {
|
if (!this.post || !this.post.imageUrl) {
|
||||||
this.pushError("There is no post to upload!");
|
this.pushError("There is no post to upload!");
|
||||||
|
|
@ -166,7 +167,6 @@ export default Vue.extend({
|
||||||
// Create and upload post
|
// Create and upload post
|
||||||
let uploadMsg = new Message("Uploading...");
|
let uploadMsg = new Message("Uploading...");
|
||||||
this.messages.push(uploadMsg);
|
this.messages.push(uploadMsg);
|
||||||
window.scrollTo(0, 0);
|
|
||||||
const createdPost = await this.szuru.createPost(this.post);
|
const createdPost = await this.szuru.createPost(this.post);
|
||||||
// TODO: Clicking a link doesn't actually open it in a new tab,
|
// TODO: Clicking a link doesn't actually open it in a new tab,
|
||||||
// see https://stackoverflow.com/questions/8915845
|
// see https://stackoverflow.com/questions/8915845
|
||||||
|
|
@ -208,8 +208,6 @@ export default Vue.extend({
|
||||||
alert(ex);
|
alert(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scrollToMessages();
|
|
||||||
},
|
},
|
||||||
// Open extension settings page in new tab
|
// Open extension settings page in new tab
|
||||||
async openSettings() {
|
async openSettings() {
|
||||||
|
|
@ -251,16 +249,24 @@ export default Vue.extend({
|
||||||
return classes;
|
return classes;
|
||||||
},
|
},
|
||||||
// Add info message
|
// Add info message
|
||||||
pushInfo(message: string) {
|
pushInfo(message: string): Message {
|
||||||
this.messages.push(new Message(message));
|
let msg = new Message(message);
|
||||||
|
this.messages.push(msg);
|
||||||
|
return msg;
|
||||||
},
|
},
|
||||||
// Add error message
|
// Add error message
|
||||||
pushError(message: string) {
|
pushError(message: string): Message {
|
||||||
this.messages.push(new Message(message, "error"));
|
let msg = new Message(message, "error");
|
||||||
|
this.messages.push(msg);
|
||||||
|
return msg;
|
||||||
},
|
},
|
||||||
clearMessages() {
|
clearMessages() {
|
||||||
this.messages = [];
|
this.messages = [];
|
||||||
},
|
},
|
||||||
|
removeMessage(message: Message) {
|
||||||
|
const idx = this.messages.indexOf(message);
|
||||||
|
if (idx != -1) this.messages.splice(idx, 1);
|
||||||
|
},
|
||||||
getPostUrl(post: Post): string {
|
getPostUrl(post: Post): string {
|
||||||
if (!this.activeSite) return "";
|
if (!this.activeSite) return "";
|
||||||
return this.activeSite.domain + "/post/" + post.id;
|
return this.activeSite.domain + "/post/" + post.id;
|
||||||
|
|
@ -286,9 +292,23 @@ export default Vue.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pushInfo("Searching for similar posts...");
|
// Remove messages that contain "Post already uploaded" or "No similar posts found"
|
||||||
|
// but keep the other messages.
|
||||||
|
for (let i = 0; i < this.messages.length; i++) {
|
||||||
|
if (
|
||||||
|
this.messages[i].content.indexOf("No similar posts found") != -1 ||
|
||||||
|
this.messages[i].content.indexOf("Post already uploaded") != -1
|
||||||
|
) {
|
||||||
|
// Decrement i to negate the i++, because if we remove one object the items
|
||||||
|
// shift one place to the left, aka index--
|
||||||
|
// If we don't do i-- we'll skip the next item in our for loop
|
||||||
|
this.messages.splice(i--, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const msgSearchSimilar = this.pushInfo("Searching for similar posts...");
|
||||||
const res = await this.szuru.reverseSearch(this.post.imageUrl);
|
const res = await this.szuru.reverseSearch(this.post.imageUrl);
|
||||||
this.clearMessages();
|
this.removeMessage(msgSearchSimilar);
|
||||||
|
|
||||||
if (!res.exactPost && res.similarPosts.length == 0) {
|
if (!res.exactPost && res.similarPosts.length == 0) {
|
||||||
this.pushInfo("No similar posts found");
|
this.pushInfo("No similar posts found");
|
||||||
|
|
@ -312,14 +332,6 @@ export default Vue.extend({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scrollToMessages();
|
|
||||||
},
|
|
||||||
// Scroll to top if there are any messages
|
|
||||||
scrollToMessages() {
|
|
||||||
if (this.messages.length > 0) {
|
|
||||||
window.scrollTo(0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue