Skip to content

Commit add5f88

Browse files
committed
Quick Tags: send browser notifications upon success or failure
1 parent 5740457 commit add5f88

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

src/scripts/quick_tags.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,48 @@
6363

6464
tags.push(...tagsToAdd);
6565

66-
await apiFetch(`/v2/blog/${uuid}/posts/${postId}`, {
67-
method: 'PUT',
68-
body: {
69-
content,
70-
date,
71-
hide_trail: hideTrail,
72-
placement_id: placementId,
73-
slug,
74-
tags: tags.join(',')
66+
try {
67+
const { response: { displayText } } = await apiFetch(`/v2/blog/${uuid}/posts/${postId}`, {
68+
method: 'PUT',
69+
body: {
70+
content,
71+
date,
72+
hide_trail: hideTrail,
73+
placement_id: placementId,
74+
slug,
75+
tags: tags.join(',')
76+
}
77+
});
78+
79+
browser.runtime.sendMessage({
80+
command: 'notifications:create',
81+
arguments: {
82+
options: { type: 'basic', title: 'XKit', message: displayText }
83+
}
84+
});
85+
86+
const tagsElement = Object.assign(document.createElement('div'), { className: tagsClass });
87+
88+
const innerTagsDiv = document.createElement('div');
89+
tagsElement.appendChild(innerTagsDiv);
90+
91+
for (const tag of tags) {
92+
innerTagsDiv.appendChild(Object.assign(document.createElement('a'), {
93+
textContent: `#${tag.trim()}`,
94+
href: `/tagged/${encodeURIComponent(tag)}`,
95+
target: '_blank'
96+
}));
7597
}
76-
});
77-
78-
const tagsElement = Object.assign(document.createElement('div'), { className: tagsClass });
7998

80-
const innerTagsDiv = document.createElement('div');
81-
tagsElement.appendChild(innerTagsDiv);
82-
83-
for (const tag of tags) {
84-
innerTagsDiv.appendChild(Object.assign(document.createElement('a'), {
85-
textContent: `#${tag.trim()}`,
86-
href: `/tagged/${encodeURIComponent(tag)}`,
87-
target: '_blank'
88-
}));
99+
postElement.querySelector('footer').parentNode.prepend(tagsElement);
100+
} catch ({ body }) {
101+
browser.runtime.sendMessage({
102+
command: 'notifications:create',
103+
arguments: {
104+
options: { type: 'basic', title: 'XKit', message: body.errors[0].detail }
105+
}
106+
});
89107
}
90-
91-
postElement.querySelector('footer').parentNode.prepend(tagsElement);
92108
};
93109

94110
const processPosts = async function () {

0 commit comments

Comments
 (0)