From 9019bb3c3212ec0acfe134d52191b1b1c84169a1 Mon Sep 17 00:00:00 2001 From: neobooru <50623835+neobooru@users.noreply.github.com> Date: Sun, 1 Sep 2019 01:44:06 +0200 Subject: [PATCH] WIP tag category setter --- src/SzuruTypes.ts | 2 +- src/popup/App.vue | 27 ++++++++++++++++++++++++--- tsconfig.json | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/SzuruTypes.ts b/src/SzuruTypes.ts index efe8b49..52d0536 100644 --- a/src/SzuruTypes.ts +++ b/src/SzuruTypes.ts @@ -26,7 +26,7 @@ export interface Tag { names: string[]; category: string; version: number; - description?: any; + description?: string; // Markdown creationTime: Date; lastEditTime?: Date; usages: number; diff --git a/src/popup/App.vue b/src/popup/App.vue index a154f5c..7a6eb0c 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -146,13 +146,34 @@ export default Vue.extend({ } try { - this.pushInfo("Uploading..."); + // Create and upload post + let uploadMsg = new Message("Uploading..."); + this.messages.push(uploadMsg); window.scrollTo(0, 0); const createdPost = await this.szuru.createPost(this.post); - this.clearMessages(); // TODO: Clicking a link doesn't actually open it in a new tab, // see https://stackoverflow.com/questions/8915845 - this.pushInfo(`Uploaded post`); + uploadMsg.content = `Uploaded post`; + + let tagsMsg = new Message("Checking tags..."); + this.messages.push(tagsMsg); + + // Find tags with "default" category and update it + // TODO: Make all these categories configurable + const tagsWithCategory = this.post.tags.filter(x => x.category); + const unsetCategoryTags = createdPost.tags + .filter(x => x.category == "default") + .filter(x => tagsWithCategory.some(y => x.names.includes(y.name))); + + console.dir(unsetCategoryTags); + + if (unsetCategoryTags.length == 0) { + tagsMsg.content = "All tags have the correct category"; + } else { + tagsMsg.content = `${unsetCategoryTags.length} tags need a different category`; + // TODO: Call /tags?query={tag1},{tag2},{tag3} + // TODO: Foreach tag call PUT /tag/{tag1} with updated category + } } catch (ex) { const error = ex as LocalError; diff --git a/tsconfig.json b/tsconfig.json index 9cfb044..7b569c4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "esModuleInterop": true, "experimentalDecorators": true, "lib": [ - "es2015", + "es2017", "dom" ], "plugins": [