Add the Voted On Topic matcher.
This commit is contained in:
parent
3008bdc9ab
commit
1222ec4f13
|
@ -11,6 +11,7 @@ import {
|
||||||
pluralize,
|
pluralize,
|
||||||
querySelector,
|
querySelector,
|
||||||
querySelectorAll,
|
querySelectorAll,
|
||||||
|
userIsLoggedIn,
|
||||||
} from "../../utilities/exports.js";
|
} from "../../utilities/exports.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,6 +59,7 @@ function hideTopic(topic: HTMLElement) {
|
||||||
export async function runHideTopicsFeature(
|
export async function runHideTopicsFeature(
|
||||||
userLabels: UserLabelsData,
|
userLabels: UserLabelsData,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const isLoggedIn = userIsLoggedIn();
|
||||||
const predicates = await fromStorage(Feature.HideTopics);
|
const predicates = await fromStorage(Feature.HideTopics);
|
||||||
|
|
||||||
// Select all topics not already handled by TRX.
|
// Select all topics not already handled by TRX.
|
||||||
|
@ -70,6 +72,7 @@ export async function runHideTopicsFeature(
|
||||||
const domainPredicates = [];
|
const domainPredicates = [];
|
||||||
const titlePredicates = [];
|
const titlePredicates = [];
|
||||||
const userPredicates = new Set();
|
const userPredicates = new Set();
|
||||||
|
let votedOnTopicEnabled = false;
|
||||||
|
|
||||||
for (const predicate of predicates) {
|
for (const predicate of predicates) {
|
||||||
const {matcher, value} = predicate.value;
|
const {matcher, value} = predicate.value;
|
||||||
|
@ -99,6 +102,11 @@ export async function runHideTopicsFeature(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Matcher.VotedOnTopic: {
|
||||||
|
votedOnTopicEnabled = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
console.warn(`Unknown HideTopicMatcher: ${matcher as string}`);
|
console.warn(`Unknown HideTopicMatcher: ${matcher as string}`);
|
||||||
}
|
}
|
||||||
|
@ -139,6 +147,16 @@ export async function runHideTopicsFeature(
|
||||||
hide(topic);
|
hide(topic);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fourth check whether the topic has been voted on.
|
||||||
|
if (
|
||||||
|
isLoggedIn &&
|
||||||
|
votedOnTopicEnabled &&
|
||||||
|
topic.querySelector(".btn-used.topic-voting") !== null
|
||||||
|
) {
|
||||||
|
hide(topic);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only add the Hide Topics button if any topics have been hidden and if the
|
// Only add the Hide Topics button if any topics have been hidden and if the
|
||||||
|
|
|
@ -144,14 +144,21 @@ export class HideTopicsSetting extends Component<SettingProps, State> {
|
||||||
? "unsaved-changes"
|
? "unsaved-changes"
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
|
const disableValueInput = [HideTopicMatcher.VotedOnTopic].includes(
|
||||||
|
predicate.matcher,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={`has-save-status hide-topics-editor ${hasUnsavedChanges}`}>
|
<div class={`has-save-status hide-topics-editor ${hasUnsavedChanges}`}>
|
||||||
<select class="styled-select" onChange={matcherHandler}>
|
<select class="styled-select" onChange={matcherHandler}>
|
||||||
{matcherOptions}
|
{matcherOptions}
|
||||||
</select>
|
</select>
|
||||||
<input
|
<input
|
||||||
|
disabled={disableValueInput}
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Value to match"
|
placeholder={
|
||||||
|
disableValueInput ? "No value needed" : "Value to match"
|
||||||
|
}
|
||||||
value={predicate.value}
|
value={predicate.value}
|
||||||
onInput={valueHandler}
|
onInput={valueHandler}
|
||||||
/>
|
/>
|
||||||
|
@ -214,6 +221,11 @@ export class HideTopicsSetting extends Component<SettingProps, State> {
|
||||||
Topics" user labels matcher and then add a user label to someone
|
Topics" user labels matcher and then add a user label to someone
|
||||||
with "Hide Topics" as the text, their topics will be hidden.
|
with "Hide Topics" as the text, their topics will be hidden.
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<b>Voted On Topic</b> will match any topic that you have voted on
|
||||||
|
and hide it. You do not have to put in a value for this matcher.
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,10 @@
|
||||||
border: 1px solid var(--save-status-color);
|
border: 1px solid var(--save-status-color);
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
|
||||||
|
&[disabled] {
|
||||||
|
filter: grayscale(100%);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
|
@ -10,6 +10,7 @@ export enum HideTopicMatcher {
|
||||||
TildesUsernameEquals = "tildes-username-equals",
|
TildesUsernameEquals = "tildes-username-equals",
|
||||||
TitleIncludes = "title-includes",
|
TitleIncludes = "title-includes",
|
||||||
UserLabelEquals = "user-label-equals",
|
UserLabelEquals = "user-label-equals",
|
||||||
|
VotedOnTopic = "voted-on-topic",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue