DEV: Merge topic list card component (#17)
This PR merges the topic-list-item card component into the nextgen theme. Also does the following cleanup: * Use template-only ember components * Use `fire` instead of deprecated `fa-fire` icon * Lower version requirement for node to 18 to match core * Add english locale strings for topic status column * Remove dummy theme settings --------- Co-authored-by: Martin Brennan <martin@discourse.org>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import avatar from "discourse/helpers/avatar";
|
||||
|
||||
const TopicAuthorAvatarColumn = <template>
|
||||
<span class="topic-author-avatar">
|
||||
{{avatar @topic.creator imageSize="large"}}
|
||||
</span>
|
||||
</template>;
|
||||
|
||||
export default TopicAuthorAvatarColumn;
|
||||
@@ -0,0 +1,5 @@
|
||||
const TopicAuthorColumn = <template>
|
||||
<span class="topic-author">@{{@topic.creator.username}}</span>
|
||||
</template>;
|
||||
|
||||
export default TopicAuthorColumn;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { categoryLinkHTML } from "discourse/helpers/category-link";
|
||||
|
||||
const TopicCategoryColumn = <template>
|
||||
{{categoryLinkHTML @topic.category}}
|
||||
</template>;
|
||||
|
||||
export default TopicCategoryColumn;
|
||||
@@ -0,0 +1,9 @@
|
||||
import icon from "discourse/helpers/d-icon";
|
||||
|
||||
const TopicLikesColumn = <template>
|
||||
{{#if @topic.like_count}}
|
||||
<span class="topic-likes">{{icon "heart"}}{{@topic.like_count}}</span>
|
||||
{{/if}}
|
||||
</template>;
|
||||
|
||||
export default TopicLikesColumn;
|
||||
@@ -0,0 +1,9 @@
|
||||
import icon from "discourse/helpers/d-icon";
|
||||
|
||||
const TopicRepliesColumn = <template>
|
||||
{{#if @topic.posts_count}}
|
||||
<span class="topic-replies">{{icon "reply"}}{{@topic.posts_count}}</span>
|
||||
{{/if}}
|
||||
</template>;
|
||||
|
||||
export default TopicRepliesColumn;
|
||||
@@ -0,0 +1,115 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { on } from "@ember/modifier";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import { and } from "truth-helpers";
|
||||
import icon from "discourse/helpers/d-icon";
|
||||
import i18n from "discourse-i18n";
|
||||
|
||||
export default class TopicStatusColumn extends Component {
|
||||
@service currentUser;
|
||||
@service siteSettings;
|
||||
|
||||
get canAct() {
|
||||
return this.currentUser && !this.args.disableActions;
|
||||
}
|
||||
|
||||
get statusClass() {
|
||||
let classes = ["topic-status-card"];
|
||||
if (this.args.topic.bookmarked) {
|
||||
classes.push("--bookmark");
|
||||
} else if (this.args.topic.closed && this.args.topic.archived) {
|
||||
classes.push("--locked --archived");
|
||||
} else if (this.args.topic.closed) {
|
||||
classes.push("--locked");
|
||||
} else if (this.args.topic.archived) {
|
||||
classes.push("--archived");
|
||||
} else if (this.args.topic.is_warning) {
|
||||
classes.push("--warning");
|
||||
} else if (
|
||||
this.args.showPrivateMessageIcon &&
|
||||
this.args.topic.isPrivateMessage
|
||||
) {
|
||||
classes.push("--private-message");
|
||||
} else if (this.args.topic.pinned) {
|
||||
classes.push("--pinned");
|
||||
} else if (this.args.topic.unpinned) {
|
||||
classes.push("--unpinned");
|
||||
}
|
||||
return classes.join(" ");
|
||||
}
|
||||
|
||||
get heatMap() {
|
||||
return this.args.topic.views > this.siteSettings.topic_views_heat_medium;
|
||||
}
|
||||
|
||||
@action
|
||||
togglePinned(event) {
|
||||
event.preventDefault();
|
||||
this.args.topic.togglePinnedForUser();
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if @topic.bookmarked}}
|
||||
<span class={{this.statusClass}}>{{icon "bookmark"}}{{i18n
|
||||
(themePrefix "topic_bookmarked")
|
||||
}}</span>
|
||||
{{/if}}
|
||||
{{#if (and @topic.closed @topic.archived)~}}
|
||||
<span class={{this.statusClass}}>{{i18n
|
||||
(themePrefix "topic_closed_and_archived")
|
||||
}}</span>
|
||||
{{else if @topic.closed}}
|
||||
<span class={{this.statusClass}}>{{i18n
|
||||
(themePrefix "topic_closed")
|
||||
}}</span>
|
||||
{{else if @topic.archived}}
|
||||
<span class={{this.statusClass}}>{{i18n
|
||||
(themePrefix "topic_archived")
|
||||
}}</span>
|
||||
{{/if}}
|
||||
{{#if @topic.is_warning}}
|
||||
<span class={{this.statusClass}}>{{i18n
|
||||
(themePrefix "topic_warning")
|
||||
}}</span>
|
||||
{{else if (and @showPrivateMessageIcon @topic.isPrivateMessage)}}
|
||||
<span class={{this.statusClass}}>{{i18n
|
||||
(themePrefix "topic_personal_message")
|
||||
}}</span>
|
||||
{{/if}}
|
||||
{{#if @topic.pinned}}
|
||||
{{#if this.canAct}}
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.togglePinned}}
|
||||
class={{this.statusClass}}
|
||||
>{{icon "thumbtack"}}{{i18n (themePrefix "topic_pinned")}}</button>
|
||||
{{else}}
|
||||
<span class={{this.statusClass}}>{{icon "thumbtack"}}{{i18n
|
||||
(themePrefix "topic_pinned")
|
||||
}}</span>
|
||||
{{/if}}
|
||||
{{else if @topic.unpinned}}
|
||||
{{#if this.canAct}}
|
||||
<button
|
||||
type="button"
|
||||
{{on "click" this.togglePinned}}
|
||||
class={{this.statusClass}}
|
||||
>{{icon "thumbtack" class="unpinned"}}{{i18n
|
||||
(themePrefix "topic_unpinned")
|
||||
}}</button>
|
||||
{{else}}
|
||||
<span class={{this.statusClass}}>{{icon
|
||||
"thumbtack"
|
||||
class="unpinned"
|
||||
}}{{i18n (themePrefix "topic_unpinned")}}</span>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{#if this.heatMap}}
|
||||
<span class="topic-status-card --hot">{{icon "fire"}}{{i18n
|
||||
(themePrefix "topic_hot")
|
||||
}}</span>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import TopicAuthorAvatarColumn from "../components/card/topic-author-avatar-column";
|
||||
import TopicAuthorColumn from "../components/card/topic-author-column";
|
||||
import TopicCategoryColumn from "../components/card/topic-category-column";
|
||||
import TopicLikesColumn from "../components/card/topic-likes-column";
|
||||
import TopicRepliesColumn from "../components/card/topic-replies-column";
|
||||
import TopicStatusColumn from "../components/card/topic-status-column";
|
||||
|
||||
const TopicAuthor = <template>
|
||||
<td class="topic-author-data">
|
||||
<TopicAuthorColumn @topic={{@topic}} />
|
||||
</td>
|
||||
</template>;
|
||||
|
||||
const TopicAuthorAvatar = <template>
|
||||
<td class="topic-author-avatar-data">
|
||||
<TopicAuthorAvatarColumn @topic={{@topic}} />
|
||||
</td>
|
||||
</template>;
|
||||
|
||||
const TopicCategoryStatus = <template>
|
||||
<td class="topic-category-status-data">
|
||||
<TopicCategoryColumn @topic={{@topic}} />
|
||||
<TopicStatusColumn @topic={{@topic}} />
|
||||
</td>
|
||||
</template>;
|
||||
|
||||
const TopicLikesReplies = <template>
|
||||
<td class="topic-likes-replies-data">
|
||||
<TopicLikesColumn @topic={{@topic}} />
|
||||
<TopicRepliesColumn @topic={{@topic}} />
|
||||
</td>
|
||||
</template>;
|
||||
|
||||
export default {
|
||||
name: "topic-list-customizations",
|
||||
|
||||
initialize() {
|
||||
withPluginApi("1.39.0", (api) => {
|
||||
api.registerValueTransformer(
|
||||
"topic-list-columns",
|
||||
({ value: columns }) => {
|
||||
columns.add("topic-author", {
|
||||
item: TopicAuthor,
|
||||
after: "activity",
|
||||
});
|
||||
columns.add("topic-category-status", {
|
||||
item: TopicCategoryStatus,
|
||||
after: "topic-author",
|
||||
});
|
||||
columns.add("topic-author-avatar", {
|
||||
item: TopicAuthorAvatar,
|
||||
after: "topic-category-status",
|
||||
});
|
||||
columns.add("topic-likes-replies", {
|
||||
item: TopicLikesReplies,
|
||||
after: "topic-author-avatar",
|
||||
});
|
||||
columns.delete("posters");
|
||||
columns.delete("views");
|
||||
columns.delete("replies");
|
||||
return columns;
|
||||
}
|
||||
);
|
||||
|
||||
api.registerValueTransformer(
|
||||
"topic-list-item-class",
|
||||
({ value: classes, context }) => {
|
||||
if (context.topic.pinned || context.topic.pinned_globally) {
|
||||
classes.push("--pinned");
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
);
|
||||
|
||||
api.registerValueTransformer("topic-list-item-mobile-layout", () => {
|
||||
return false;
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user