Skip to content

Commit

Permalink
DEV: Resolve deprecations for compatibility with latest ember
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq committed Jan 9, 2024
1 parent 652ead6 commit a6b6a9b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
Expand Up @@ -8,7 +8,10 @@ export default Component.extend({

@discourseComputed("router.currentRoute.queryParams.cards")
showingCards(cardsParam) {
return cardsParam === "yes";
return (
cardsParam === "yes" ||
(cardsParam === undefined && settings.default_view === "cards")
);
},

actions: {
Expand Down
31 changes: 13 additions & 18 deletions javascripts/discourse/initializers/user-card-directory.js
Expand Up @@ -11,6 +11,15 @@ export default {
withPluginApi("0.8.7", (api) => {
api.modifyClass("route:users", {
pluginId: "user-card-directory",

get templateName() {
if (this.modelFor("users")?.showAsCards) {
return "users-as-card-directory";
} else {
return "users";
}
},

resetController(controller, isExiting) {
this._super(...arguments);
if (isExiting) {
Expand All @@ -22,29 +31,15 @@ export default {
cards: { refreshModel: true },
},

beforeModel(transition) {
this._super(transition);
if (
settings.default_view === "cards" &&
!transition.to.queryParams.cards
) {
this.transitionTo({ queryParams: { cards: "yes" } });
}
},

model(params) {
return this._super(params).then((model) => {
model.showAsCards = params["cards"] === "yes";
model.showAsCards =
params["cards"] === "yes" ||
(params["cards"] === undefined &&
settings.default_view === "cards");
return model;
});
},

renderTemplate(controller, model) {
if (model.showAsCards) {
return this.render("users-as-card-directory");
}
return this._super();
},
});

api.modifyClass("controller:users", {
Expand Down

0 comments on commit a6b6a9b

Please sign in to comment.