Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Modernise and fix behavior when used with loading-slider (#243)
- Loading branch information
1 parent
62fe282
commit 9087034
Showing
2 changed files
with
45 additions
and
38 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
assets/javascripts/discourse/connectors/bread-crumbs-right/solved-status-filter.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{{#if siteSettings.solved_enabled}} | ||
{{#if this.siteSettings.solved_enabled}} | ||
<ComboBox | ||
@class="solved-status-filter" | ||
@content={{statuses}} | ||
@value={{status}} | ||
@content={{this.statuses}} | ||
@value={{this.status}} | ||
@valueProperty="value" | ||
@options={{hash caretDownIcon="caret-right" caretUpIcon="caret-down"}} | ||
@onChange={{(action "changeStatus")}} | ||
@onChange={{this.changeStatus}} | ||
/> | ||
{{/if}} |
75 changes: 41 additions & 34 deletions
75
assets/javascripts/discourse/connectors/bread-crumbs-right/solved-status-filter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,58 @@ | ||
import I18n from "I18n"; | ||
import { getOwner } from "discourse-common/lib/get-owner"; | ||
import Component from "@glimmer/component"; | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
|
||
export default { | ||
shouldRender(args, component) { | ||
const router = getOwner(this).lookup("router:main"); | ||
const QUERY_PARAM_VALUES = { | ||
solved: "yes", | ||
unsolved: "no", | ||
all: null, | ||
}; | ||
|
||
const UX_VALUES = { | ||
yes: "solved", | ||
no: "unsolved", | ||
}; | ||
|
||
export default class SolvedStatusFilter extends Component { | ||
static shouldRender(args, helper) { | ||
const router = getOwner(this).lookup("service:router"); | ||
|
||
if ( | ||
!component.siteSettings.show_filter_by_solved_status || | ||
router.currentPath === "discovery.categories" | ||
!helper.siteSettings.show_filter_by_solved_status || | ||
router.currentRouteName === "discovery.categories" | ||
) { | ||
return false; | ||
} else if (component.siteSettings.allow_solved_on_all_topics) { | ||
} else if (helper.siteSettings.allow_solved_on_all_topics) { | ||
return true; | ||
} else { | ||
const controller = getOwner(this).lookup( | ||
"controller:navigation/category" | ||
); | ||
return controller && controller.get("category.enable_accepted_answers"); | ||
return args.currentCategory?.enable_accepted_answers; | ||
} | ||
}, | ||
} | ||
|
||
@service router; | ||
@service siteSettings; | ||
|
||
setupComponent(args, component) { | ||
const statuses = ["all", "solved", "unsolved"].map((status) => { | ||
get statuses() { | ||
return ["all", "solved", "unsolved"].map((status) => { | ||
return { | ||
name: I18n.t(`solved.topic_status_filter.${status}`), | ||
value: status, | ||
}; | ||
}); | ||
component.set("statuses", statuses); | ||
} | ||
|
||
const queryStrings = window.location.search; | ||
if (queryStrings.match(/solved=yes/)) { | ||
component.set("status", "solved"); | ||
} else if (queryStrings.match(/solved=no/)) { | ||
component.set("status", "unsolved"); | ||
} else { | ||
component.set("status", "all"); | ||
} | ||
}, | ||
|
||
actions: { | ||
changeStatus(newStatus) { | ||
const router = getOwner(this).lookup("router:main"); | ||
if (newStatus && newStatus !== "all") { | ||
newStatus = newStatus === "solved" ? "yes" : "no"; | ||
} | ||
router.transitionTo({ queryParams: { solved: newStatus } }); | ||
}, | ||
}, | ||
}; | ||
get status() { | ||
const queryParamValue = | ||
this.router.currentRoute.attributes?.modelParams?.solved; | ||
return UX_VALUES[queryParamValue] || "all"; | ||
} | ||
|
||
@action | ||
changeStatus(newStatus) { | ||
this.router.transitionTo({ | ||
queryParams: { solved: QUERY_PARAM_VALUES[newStatus] }, | ||
}); | ||
} | ||
} |