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

FEATURE: Apply category filters when filtered by tag #37

Merged
merged 1 commit into from
Nov 16, 2023
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
2 changes: 1 addition & 1 deletion .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
< 3.2.0.beta4-dev: b3c727286bdad3661d6cb2b83e369588e91b458f

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into compatibility problems when using an unreleased version previously because 3.2.0.beta4-dev can represent a wide range of Discourse core commits. Does the feature being introduced here rely on a Discourse core change that has yet to be released? If so, we might need to be more careful here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discovery service was included in the 3.2.0.beta3 release, so we should be safe 👌

3.1.999: a69770189aa2146d29ee57465ffb1c7d7e84795f

13 changes: 1 addition & 12 deletions javascripts/discourse/initializers/topic-thumbnails-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,9 @@ import { htmlSafe } from "@ember/template";
export default {
name: "topic-thumbnails-init",
initialize() {
this.applyViewClassWorkaround();
withPluginApi("0.8.7", (api) => this.initWithApi(api));
},

applyViewClassWorkaround() {
// Workaround for https://github.com/discourse/discourse/pull/12685
// Can be removed once that has been merged, and sites have had time to update
const viewClassKey = Object.keys(requirejs.entries).find((k) =>
k.endsWith("raw-views/topic-list-thumbnail")
);
requirejs.entries["discourse/raw-views/topic-list-thumbnail"] =
requirejs.entries[viewClassKey];
},

initWithApi(api) {
api.modifyClass("component:topic-list", {
pluginId: "topic-thumbnails",
Expand All @@ -44,7 +33,7 @@ export default {
isBlogStyleGrid: readOnly("topicThumbnailsService.displayBlogStyle"),
});

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

if (settings.docs_thumbnail_mode !== "none" && siteSettings.docs_enabled) {
api.modifyClass("component:docs-topic-list", {
Expand Down
72 changes: 29 additions & 43 deletions javascripts/discourse/services/topic-thumbnails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Service, { inject as service } from "@ember/service";
import discourseComputed from "discourse-common/utils/decorators";
import Site from "discourse/models/site";
import { dependentKeyCompat } from "@ember/object/compat";

const minimalGridCategories = settings.minimal_grid_categories
.split("|")
Expand Down Expand Up @@ -28,49 +29,34 @@ const gridTags = settings.grid_tags.split("|");
const masonryTags = settings.masonry_tags.split("|");
const blogStyleTags = settings.blog_style_tags.split("|");

export default Service.extend({
router: service("router"),
export default class TopicThumbnailService extends Service {
@service router;
@service discovery;

@discourseComputed("router.currentRouteName")
isTopicListRoute(currentRouteName) {
return (
currentRouteName.match(/^discovery\./) ||
currentRouteName.match(/^tags?\.show/)
);
},
@dependentKeyCompat
get isTopicListRoute() {
return this.discovery.onDiscoveryRoute;
}

@discourseComputed("router.currentRouteName")
isTopicRoute(currentRouteName) {
return currentRouteName.match(/^topic\./);
},
}

@discourseComputed("router.currentRouteName")
isDocsRoute(currentRouteName) {
return currentRouteName.match(/^docs\./);
},
}

@discourseComputed(
"router.currentRouteName",
"router.currentRoute.attributes.category.id"
)
viewingCategoryId(currentRouteName, categoryId) {
if (!currentRouteName.match(/^discovery\./)) {
return;
}
return categoryId;
},
@dependentKeyCompat
get viewingCategoryId() {
return this.discovery.category?.id;
}

@discourseComputed(
"router.currentRouteName",
"router.currentRoute.attributes.id", // For discourse instances earlier than https://github.com/discourse/discourse/commit/f7b5ff39cf
"router.currentRoute.attributes.tag.id"
)
viewingTagId(currentRouteName, legacyTagId, tagId) {
if (!currentRouteName.match(/^tags?\.show/)) {
return;
}
return tagId || legacyTagId;
},
@dependentKeyCompat
get viewingTagId() {
return this.discovery.tag?.id;
}

@discourseComputed(
"viewingCategoryId",
Expand Down Expand Up @@ -120,50 +106,50 @@ export default Service.extend({
} else {
return "none";
}
},
}

@discourseComputed("displayMode")
enabledForRoute(displayMode) {
return displayMode !== "none";
},
}

@discourseComputed()
enabledForDevice() {
return Site.current().mobileView ? settings.mobile_thumbnails : true;
},
}

@discourseComputed("enabledForRoute", "enabledForDevice")
shouldDisplay(enabledForRoute, enabledForDevice) {
return enabledForRoute && enabledForDevice;
},
}

@discourseComputed("shouldDisplay", "displayMode")
displayMinimalGrid(shouldDisplay, displayMode) {
return shouldDisplay && displayMode === "minimal-grid";
},
}

@discourseComputed("shouldDisplay", "displayMode")
displayList(shouldDisplay, displayMode) {
return shouldDisplay && displayMode === "list";
},
}

@discourseComputed("shouldDisplay", "displayMode")
displayGrid(shouldDisplay, displayMode) {
return shouldDisplay && displayMode === "grid";
},
}

@discourseComputed("shouldDisplay", "displayMode")
displayMasonry(shouldDisplay, displayMode) {
return shouldDisplay && displayMode === "masonry";
},
}

@discourseComputed("shouldDisplay", "displayMode")
displayBlogStyle(shouldDisplay, displayMode) {
return shouldDisplay && displayMode === "blog-style";
},
}

@discourseComputed("displayMinimalGrid", "displayBlogStyle")
showLikes(isMinimalGrid) {
return isMinimalGrid;
},
});
}
}