Skip to content

Commit

Permalink
Add button which imports tag categories from the selected configured …
Browse files Browse the repository at this point in the history
…szurubooru instance
  • Loading branch information
neobooru committed Oct 27, 2023
1 parent 335bc6e commit adc25d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Empty file removed src/config.ts
Empty file.
17 changes: 16 additions & 1 deletion src/options/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TabPanel from "primevue/tabpanel";
import DataTable from "primevue/datatable";
import Column from "primevue/column";
import { SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
import SzurubooruApi from "~/api";
const statusText = ref("");
const statusType = ref("status-quiet");
Expand Down Expand Up @@ -87,6 +88,20 @@ function addTagCategory() {
cfg.value.tagCategories.push(new TagCategoryColor("category", "#abcdef"));
}
async function importTagCategoriesFromInstance() {
const szuruConfig = cfg.value.sites.find((x) => x.id == cfg.value.selectedSiteId)!;
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
const cats = (await szuru.getTagCategories()).results;
for (const cat of cats) {
if (cat.name == "default") continue;
if (!cfg.value.tagCategories.find((x) => x.name == cat.name)) {
cfg.value.tagCategories.push(new TagCategoryColor(cat.name, cat.color));
}
}
}
// For debugging
const wnd = window as any;
wnd.szc_get_config = () => JSON.parse(JSON.stringify(cfg.value));
Expand Down Expand Up @@ -241,7 +256,7 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);

<div class="col-12 flex flex-wrap grid grid-nogutter gap-1">
<button class="primary" @click="addTagCategory">Add new category</button>
<!-- <button>Import from connected instances</button> -->
<button @click="importTagCategoriesFromInstance">Import from active instance</button>
<button class="bg-danger sm:ml-auto" @click="resetTagCategories">Reset to default</button>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/popup/pages/MergePost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const props = defineProps(["siteId", "postId"]);
const merge = useMergeStore();
const pop = usePopupStore();
// Why is this cloneDeep needed? Or maybe it isn't?
const szuruConfig = cloneDeep(cfg.value.sites.find((x) => x.id == props.siteId))!;
const szuru = SzurubooruApi.createFromConfig(szuruConfig);
Expand Down

0 comments on commit adc25d4

Please sign in to comment.