Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Tags: Work correctly on non-NPF posts #969

Merged
merged 6 commits into from
Aug 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/scripts/quick_tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cloneControlButton, createControlButtonTemplate } from '../util/control
import { keyToCss } from '../util/css_map.js';
import { dom } from '../util/dom.js';
import { postSelector } from '../util/interface.js';
import { megaEdit } from '../util/mega_editor.js';
import { pageModifications } from '../util/mutations.js';
import { notify } from '../util/notifications.js';
import { registerPostOption, unregisterPostOption } from '../util/post_actions.js';
Expand Down Expand Up @@ -146,26 +147,33 @@ const togglePostOptionPopupDisplay = async function ({ target, currentTarget })

const addTagsToPost = async function ({ postElement, inputTags = [] }) {
const postId = postElement.dataset.id;
const { blog: { uuid } } = await timelineObject(postElement);
const { blog: { uuid }, blogName } = await timelineObject(postElement);

const { response: postData } = await apiFetch(`/v2/blog/${uuid}/posts/${postId}`);
const { tags = [] } = postData;
const { tags = [], isBlocksPostFormat, shouldOpenInLegacy } = postData;

const isNpfCompatible = isBlocksPostFormat || shouldOpenInLegacy === false;

const tagsToAdd = inputTags.filter(inputTag => tags.includes(inputTag) === false);
if (tagsToAdd.length === 0) { return; }

tags.push(...tagsToAdd);

try {
const { response: { displayText } } = await apiFetch(`/v2/blog/${uuid}/posts/${postId}`, {
method: 'PUT',
body: {
...createEditRequestBody(postData),
tags: tags.join(',')
}
});

notify(displayText);
if (isNpfCompatible) {
const { response: { displayText } } = await apiFetch(`/v2/blog/${uuid}/posts/${postId}`, {
method: 'PUT',
body: {
...createEditRequestBody(postData),
tags: tags.join(',')
}
});

notify(displayText);
} else {
await megaEdit([postId], { mode: 'add', tags: tagsToAdd });
notify(`Edited on ${blogName} (legacy)`);
AprilSylph marked this conversation as resolved.
Show resolved Hide resolved
marcustyphoon marked this conversation as resolved.
Show resolved Hide resolved
}

const tagsElement = dom('div', { class: tagsClass });

Expand Down