Skip to content

Commit 41a9fe1

Browse files
FEATURE: Apply category filters when filtered by tag (#37)
Also takes the opportunity to convert the service to native class syntax, and lean on the new 'discovery' service for finding the active category/tag in a safe way.
1 parent b3c7272 commit 41a9fe1

File tree

3 files changed

+31
-56
lines changed

3 files changed

+31
-56
lines changed

.discourse-compatibility

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
< 3.2.0.beta4-dev: b3c727286bdad3661d6cb2b83e369588e91b458f
12
3.1.999: a69770189aa2146d29ee57465ffb1c7d7e84795f
2-

javascripts/discourse/initializers/topic-thumbnails-init.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,9 @@ import { htmlSafe } from "@ember/template";
1212
export default {
1313
name: "topic-thumbnails-init",
1414
initialize() {
15-
this.applyViewClassWorkaround();
1615
withPluginApi("0.8.7", (api) => this.initWithApi(api));
1716
},
1817

19-
applyViewClassWorkaround() {
20-
// Workaround for https://github.com/discourse/discourse/pull/12685
21-
// Can be removed once that has been merged, and sites have had time to update
22-
const viewClassKey = Object.keys(requirejs.entries).find((k) =>
23-
k.endsWith("raw-views/topic-list-thumbnail")
24-
);
25-
requirejs.entries["discourse/raw-views/topic-list-thumbnail"] =
26-
requirejs.entries[viewClassKey];
27-
},
28-
2918
initWithApi(api) {
3019
api.modifyClass("component:topic-list", {
3120
pluginId: "topic-thumbnails",
@@ -44,7 +33,7 @@ export default {
4433
isBlogStyleGrid: readOnly("topicThumbnailsService.displayBlogStyle"),
4534
});
4635

47-
const siteSettings = api.container.lookup("site-settings:main");
36+
const siteSettings = api.container.lookup("service:site-settings");
4837

4938
if (settings.docs_thumbnail_mode !== "none" && siteSettings.docs_enabled) {
5039
api.modifyClass("component:docs-topic-list", {

javascripts/discourse/services/topic-thumbnails.js

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Service, { inject as service } from "@ember/service";
22
import discourseComputed from "discourse-common/utils/decorators";
33
import Site from "discourse/models/site";
4+
import { dependentKeyCompat } from "@ember/object/compat";
45

56
const minimalGridCategories = settings.minimal_grid_categories
67
.split("|")
@@ -28,49 +29,34 @@ const gridTags = settings.grid_tags.split("|");
2829
const masonryTags = settings.masonry_tags.split("|");
2930
const blogStyleTags = settings.blog_style_tags.split("|");
3031

31-
export default Service.extend({
32-
router: service("router"),
32+
export default class TopicThumbnailService extends Service {
33+
@service router;
34+
@service discovery;
3335

34-
@discourseComputed("router.currentRouteName")
35-
isTopicListRoute(currentRouteName) {
36-
return (
37-
currentRouteName.match(/^discovery\./) ||
38-
currentRouteName.match(/^tags?\.show/)
39-
);
40-
},
36+
@dependentKeyCompat
37+
get isTopicListRoute() {
38+
return this.discovery.onDiscoveryRoute;
39+
}
4140

4241
@discourseComputed("router.currentRouteName")
4342
isTopicRoute(currentRouteName) {
4443
return currentRouteName.match(/^topic\./);
45-
},
44+
}
4645

4746
@discourseComputed("router.currentRouteName")
4847
isDocsRoute(currentRouteName) {
4948
return currentRouteName.match(/^docs\./);
50-
},
49+
}
5150

52-
@discourseComputed(
53-
"router.currentRouteName",
54-
"router.currentRoute.attributes.category.id"
55-
)
56-
viewingCategoryId(currentRouteName, categoryId) {
57-
if (!currentRouteName.match(/^discovery\./)) {
58-
return;
59-
}
60-
return categoryId;
61-
},
51+
@dependentKeyCompat
52+
get viewingCategoryId() {
53+
return this.discovery.category?.id;
54+
}
6255

63-
@discourseComputed(
64-
"router.currentRouteName",
65-
"router.currentRoute.attributes.id", // For discourse instances earlier than https://github.com/discourse/discourse/commit/f7b5ff39cf
66-
"router.currentRoute.attributes.tag.id"
67-
)
68-
viewingTagId(currentRouteName, legacyTagId, tagId) {
69-
if (!currentRouteName.match(/^tags?\.show/)) {
70-
return;
71-
}
72-
return tagId || legacyTagId;
73-
},
56+
@dependentKeyCompat
57+
get viewingTagId() {
58+
return this.discovery.tag?.id;
59+
}
7460

7561
@discourseComputed(
7662
"viewingCategoryId",
@@ -120,50 +106,50 @@ export default Service.extend({
120106
} else {
121107
return "none";
122108
}
123-
},
109+
}
124110

125111
@discourseComputed("displayMode")
126112
enabledForRoute(displayMode) {
127113
return displayMode !== "none";
128-
},
114+
}
129115

130116
@discourseComputed()
131117
enabledForDevice() {
132118
return Site.current().mobileView ? settings.mobile_thumbnails : true;
133-
},
119+
}
134120

135121
@discourseComputed("enabledForRoute", "enabledForDevice")
136122
shouldDisplay(enabledForRoute, enabledForDevice) {
137123
return enabledForRoute && enabledForDevice;
138-
},
124+
}
139125

140126
@discourseComputed("shouldDisplay", "displayMode")
141127
displayMinimalGrid(shouldDisplay, displayMode) {
142128
return shouldDisplay && displayMode === "minimal-grid";
143-
},
129+
}
144130

145131
@discourseComputed("shouldDisplay", "displayMode")
146132
displayList(shouldDisplay, displayMode) {
147133
return shouldDisplay && displayMode === "list";
148-
},
134+
}
149135

150136
@discourseComputed("shouldDisplay", "displayMode")
151137
displayGrid(shouldDisplay, displayMode) {
152138
return shouldDisplay && displayMode === "grid";
153-
},
139+
}
154140

155141
@discourseComputed("shouldDisplay", "displayMode")
156142
displayMasonry(shouldDisplay, displayMode) {
157143
return shouldDisplay && displayMode === "masonry";
158-
},
144+
}
159145

160146
@discourseComputed("shouldDisplay", "displayMode")
161147
displayBlogStyle(shouldDisplay, displayMode) {
162148
return shouldDisplay && displayMode === "blog-style";
163-
},
149+
}
164150

165151
@discourseComputed("displayMinimalGrid", "displayBlogStyle")
166152
showLikes(isMinimalGrid) {
167153
return isMinimalGrid;
168-
},
169-
});
154+
}
155+
}

0 commit comments

Comments
 (0)