Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
61 changes: 45 additions & 16 deletions extensions/tags/js/src/forum/components/DiscussionTaggedPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,56 @@ import EventPost from 'flarum/forum/components/EventPost';
import tagsLabel from '../../common/helpers/tagsLabel';

export default class DiscussionTaggedPost extends EventPost {
static initAttrs(attrs) {
super.initAttrs(attrs);
oninit(vnode) {
super.oninit(vnode);

const oldTags = attrs.post.content()[0];
const newTags = attrs.post.content()[1];
const oldTags = this.attrs.post.content()[0];
const newTags = this.attrs.post.content()[1];

function diffTags(tags1, tags2) {
return tags1.filter((tag) => tags2.indexOf(tag) === -1).map((id) => app.store.getById('tags', id));
this.tagsAdded = [];
this.tagsRemoved = [];

this.fetchRequired = false;
this.loading = true;

const tagsMutation = [...this.diffTags(newTags, oldTags), ...this.diffTags(oldTags, newTags)];
if (tagsMutation.includes(undefined)) {
this.fetchRequired = true;
}

attrs.tagsAdded = diffTags(newTags, oldTags);
attrs.tagsRemoved = diffTags(oldTags, newTags);
const afterFetch = () => {
this.tagsAdded = this.diffTags(newTags, oldTags);
this.tagsRemoved = this.diffTags(oldTags, newTags);

this.loading = false;
m.redraw();
};

if (this.fetchRequired) {
app.store
.find('tags')
.then(afterFetch)
.catch(() => {
this.loading = false;
m.redraw();
});
} else {
afterFetch();
}
}

diffTags(tags1, tags2) {
return tags1.filter((tag) => tags2.indexOf(tag) === -1).map((id) => app.store.getById('tags', id));
// .filter(Boolean);
}

icon() {
return 'fas fa-tag';
}

descriptionKey() {
if (this.attrs.tagsAdded.length) {
if (this.attrs.tagsRemoved.length) {
if (this.tagsAdded.length) {
if (this.tagsRemoved.length) {
return 'flarum-tags.forum.post_stream.added_and_removed_tags_text';
}

Expand All @@ -35,17 +64,17 @@ export default class DiscussionTaggedPost extends EventPost {
descriptionData() {
const data = {};

if (this.attrs.tagsAdded.length) {
if (this.tagsAdded.length) {
data.tagsAdded = app.translator.trans('flarum-tags.forum.post_stream.tags_text', {
tags: tagsLabel(this.attrs.tagsAdded, { link: true }),
count: this.attrs.tagsAdded.length,
tags: tagsLabel(this.tagsAdded, { link: true }),
count: this.tagsAdded.length,
});
}

if (this.attrs.tagsRemoved.length) {
if (this.tagsRemoved.length) {
data.tagsRemoved = app.translator.trans('flarum-tags.forum.post_stream.tags_text', {
tags: tagsLabel(this.attrs.tagsRemoved, { link: true }),
count: this.attrs.tagsRemoved.length,
tags: tagsLabel(this.tagsRemoved, { link: true }),
count: this.tagsRemoved.length,
});
}

Expand Down
1 change: 1 addition & 0 deletions extensions/tags/less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@import "forum/TagCloud";
@import "forum/TagHero";
@import "forum/TagPost";
@import "forum/TagTiles";
@import "forum/ToggleButton";

Expand Down
6 changes: 6 additions & 0 deletions extensions/tags/less/forum/TagPost.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.EventPost.DiscussionTaggedPost.Post.Post--loading {
height: 62px;
}
.DiscussionTaggedPost .LoadingIndicator-container--block {
height: auto;
}
Loading