This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/discovery-sortable.js.es6
Joffrey JAFFEUX a5542768ea
FIX: attempts to use params from addDiscoveryQueryParam (#8007)
This commit will for example allow this:

```
api.addDiscoveryQueryParam("my_param", { persist: true });
```

If you page is forum.foo.bar/?my_param=1, when clicking on an "unread" link for example this query string will be kept.
2019-08-14 19:56:02 +02:00

45 lines
1.4 KiB
JavaScript

import DiscourseNavigation from "discourse/components/d-navigation";
// Just add query params here to have them automatically passed to topic list filters.
export const queryParams = {
order: { replace: true, refreshModel: true },
ascending: { replace: true, refreshModel: true },
status: { replace: true, refreshModel: true },
state: { replace: true, refreshModel: true },
search: { replace: true, refreshModel: true },
max_posts: { replace: true, refreshModel: true },
q: { replace: true, refreshModel: true },
tags: { replace: true },
before: { replace: true, refreshModel: true },
bumped_before: { replace: true, refreshModel: true }
};
// Basic controller options
const controllerOpts = {
discoveryTopics: Ember.inject.controller("discovery/topics"),
queryParams: Object.keys(queryParams)
};
// Aliases for the values
controllerOpts.queryParams.forEach(
p => (controllerOpts[p] = Ember.computed.alias(`discoveryTopics.${p}`))
);
const Controller = Ember.Controller.extend(controllerOpts);
export const addDiscoveryQueryParam = function(p, opts) {
queryParams[p] = opts;
const cOpts = {};
cOpts[p] = Ember.computed.alias(`discoveryTopics.${p}`);
cOpts["queryParams"] = Object.keys(queryParams);
Controller.reopen(cOpts);
if (opts && opts.persisted) {
DiscourseNavigation.reopen({
persistedQueryParams: queryParams
});
}
};
export default Controller;