updated TagFilterStore
This commit is contained in:
parent
4f8b0afc41
commit
f5a40eff4b
10 changed files with 34 additions and 34 deletions
|
@ -17,14 +17,14 @@ limitations under the License.
|
||||||
|
|
||||||
import Analytics from '../Analytics';
|
import Analytics from '../Analytics';
|
||||||
import { asyncAction } from './actionCreators';
|
import { asyncAction } from './actionCreators';
|
||||||
import TagOrderStore from '../stores/TagOrderStore';
|
import GroupFilterOrderStore from '../stores/GroupFilterOrderStore';
|
||||||
import { AsyncActionPayload } from "../dispatcher/payloads";
|
import { AsyncActionPayload } from "../dispatcher/payloads";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
|
|
||||||
export default class TagOrderActions {
|
export default class TagOrderActions {
|
||||||
/**
|
/**
|
||||||
* Creates an action thunk that will do an asynchronous request to
|
* Creates an action thunk that will do an asynchronous request to
|
||||||
* move a tag in TagOrderStore to destinationIx.
|
* move a tag in GroupFilterOrderStore to destinationIx.
|
||||||
*
|
*
|
||||||
* @param {MatrixClient} matrixClient the matrix client to set the
|
* @param {MatrixClient} matrixClient the matrix client to set the
|
||||||
* account data on.
|
* account data on.
|
||||||
|
@ -36,8 +36,8 @@ export default class TagOrderActions {
|
||||||
*/
|
*/
|
||||||
public static moveTag(matrixClient: MatrixClient, tag: string, destinationIx: number): AsyncActionPayload {
|
public static moveTag(matrixClient: MatrixClient, tag: string, destinationIx: number): AsyncActionPayload {
|
||||||
// Only commit tags if the state is ready, i.e. not null
|
// Only commit tags if the state is ready, i.e. not null
|
||||||
let tags = TagOrderStore.getOrderedTags();
|
let tags = GroupFilterOrderStore.getOrderedTags();
|
||||||
let removedTags = TagOrderStore.getRemovedTagsAccountData() || [];
|
let removedTags = GroupFilterOrderStore.getRemovedTagsAccountData() || [];
|
||||||
if (!tags) {
|
if (!tags) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ export default class TagOrderActions {
|
||||||
|
|
||||||
removedTags = removedTags.filter((t) => t !== tag);
|
removedTags = removedTags.filter((t) => t !== tag);
|
||||||
|
|
||||||
const storeId = TagOrderStore.getStoreId();
|
const storeId = GroupFilterOrderStore.getStoreId();
|
||||||
|
|
||||||
return asyncAction('TagOrderActions.moveTag', () => {
|
return asyncAction('TagOrderActions.moveTag', () => {
|
||||||
Analytics.trackEvent('TagOrderActions', 'commitTagOrdering');
|
Analytics.trackEvent('TagOrderActions', 'commitTagOrdering');
|
||||||
|
@ -83,8 +83,8 @@ export default class TagOrderActions {
|
||||||
*/
|
*/
|
||||||
public static removeTag(matrixClient: MatrixClient, tag: string): AsyncActionPayload {
|
public static removeTag(matrixClient: MatrixClient, tag: string): AsyncActionPayload {
|
||||||
// Don't change tags, just removedTags
|
// Don't change tags, just removedTags
|
||||||
const tags = TagOrderStore.getOrderedTags();
|
const tags = GroupFilterOrderStore.getOrderedTags();
|
||||||
const removedTags = TagOrderStore.getRemovedTagsAccountData() || [];
|
const removedTags = GroupFilterOrderStore.getRemovedTagsAccountData() || [];
|
||||||
|
|
||||||
if (removedTags.includes(tag)) {
|
if (removedTags.includes(tag)) {
|
||||||
// Return a thunk that doesn't do anything, we don't even need
|
// Return a thunk that doesn't do anything, we don't even need
|
||||||
|
@ -94,7 +94,7 @@ export default class TagOrderActions {
|
||||||
|
|
||||||
removedTags.push(tag);
|
removedTags.push(tag);
|
||||||
|
|
||||||
const storeId = TagOrderStore.getStoreId();
|
const storeId = GroupFilterOrderStore.getStoreId();
|
||||||
|
|
||||||
return asyncAction('TagOrderActions.removeTag', () => {
|
return asyncAction('TagOrderActions.removeTag', () => {
|
||||||
Analytics.trackEvent('TagOrderActions', 'removeTag');
|
Analytics.trackEvent('TagOrderActions', 'removeTag');
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import TagOrderStore from '../../stores/TagOrderStore';
|
import GroupFilterOrderStore from '../../stores/GroupFilterOrderStore';
|
||||||
|
|
||||||
import GroupActions from '../../actions/GroupActions';
|
import GroupActions from '../../actions/GroupActions';
|
||||||
|
|
||||||
|
@ -44,13 +44,13 @@ class GroupFilterPanel extends React.Component {
|
||||||
this.context.on("Group.myMembership", this._onGroupMyMembership);
|
this.context.on("Group.myMembership", this._onGroupMyMembership);
|
||||||
this.context.on("sync", this._onClientSync);
|
this.context.on("sync", this._onClientSync);
|
||||||
|
|
||||||
this._tagOrderStoreToken = TagOrderStore.addListener(() => {
|
this._GroupFilterOrderStoreToken = GroupFilterOrderStore.addListener(() => {
|
||||||
if (this.unmounted) {
|
if (this.unmounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
orderedTags: TagOrderStore.getOrderedTags() || [],
|
orderedTags: GroupFilterOrderStore.getOrderedTags() || [],
|
||||||
selectedTags: TagOrderStore.getSelectedTags(),
|
selectedTags: GroupFilterOrderStore.getSelectedTags(),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// This could be done by anything with a matrix client
|
// This could be done by anything with a matrix client
|
||||||
|
@ -61,8 +61,8 @@ class GroupFilterPanel extends React.Component {
|
||||||
this.unmounted = true;
|
this.unmounted = true;
|
||||||
this.context.removeListener("Group.myMembership", this._onGroupMyMembership);
|
this.context.removeListener("Group.myMembership", this._onGroupMyMembership);
|
||||||
this.context.removeListener("sync", this._onClientSync);
|
this.context.removeListener("sync", this._onClientSync);
|
||||||
if (this._tagOrderStoreToken) {
|
if (this._GroupFilterOrderStoreToken) {
|
||||||
this._tagOrderStoreToken.remove();
|
this._GroupFilterOrderStoreToken.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -519,7 +519,7 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
const draggableId = result.draggableId.split(' ').pop();
|
const draggableId = result.draggableId.split(' ').pop();
|
||||||
|
|
||||||
// Dispatch synchronously so that the GroupFilterPanel receives an
|
// Dispatch synchronously so that the GroupFilterPanel receives an
|
||||||
// optimistic update from TagOrderStore before the previous
|
// optimistic update from GroupFilterOrderStore before the previous
|
||||||
// state is shown.
|
// state is shown.
|
||||||
dis.dispatch(TagOrderActions.moveTag(
|
dis.dispatch(TagOrderActions.moveTag(
|
||||||
this._matrixClient,
|
this._matrixClient,
|
||||||
|
|
|
@ -30,7 +30,7 @@ import Analytics from '../../Analytics';
|
||||||
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
|
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
|
||||||
import {ALL_ROOMS} from "../views/directory/NetworkDropdown";
|
import {ALL_ROOMS} from "../views/directory/NetworkDropdown";
|
||||||
import SettingsStore from "../../settings/SettingsStore";
|
import SettingsStore from "../../settings/SettingsStore";
|
||||||
import TagOrderStore from "../../stores/TagOrderStore";
|
import GroupFilterOrderStore from "../../stores/GroupFilterOrderStore";
|
||||||
import GroupStore from "../../stores/GroupStore";
|
import GroupStore from "../../stores/GroupStore";
|
||||||
import FlairStore from "../../stores/FlairStore";
|
import FlairStore from "../../stores/FlairStore";
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ export default class RoomDirectory extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const selectedCommunityId = TagOrderStore.getSelectedTags()[0];
|
const selectedCommunityId = GroupFilterOrderStore.getSelectedTags()[0];
|
||||||
this.state = {
|
this.state = {
|
||||||
publicRooms: [],
|
publicRooms: [],
|
||||||
loading: true,
|
loading: true,
|
||||||
|
|
|
@ -44,7 +44,7 @@ import IconizedContextMenu, {
|
||||||
} from "../views/context_menus/IconizedContextMenu";
|
} from "../views/context_menus/IconizedContextMenu";
|
||||||
import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
|
import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
|
||||||
import * as fbEmitter from "fbemitter";
|
import * as fbEmitter from "fbemitter";
|
||||||
import TagOrderStore from "../../stores/TagOrderStore";
|
import GroupFilterOrderStore from "../../stores/GroupFilterOrderStore";
|
||||||
import { showCommunityInviteDialog } from "../../RoomInvite";
|
import { showCommunityInviteDialog } from "../../RoomInvite";
|
||||||
import dis from "../../dispatcher/dispatcher";
|
import dis from "../../dispatcher/dispatcher";
|
||||||
import { RightPanelPhases } from "../../stores/RightPanelStorePhases";
|
import { RightPanelPhases } from "../../stores/RightPanelStorePhases";
|
||||||
|
@ -87,7 +87,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
||||||
public componentDidMount() {
|
public componentDidMount() {
|
||||||
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
||||||
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
||||||
this.tagStoreRef = TagOrderStore.addListener(this.onTagStoreUpdate);
|
this.tagStoreRef = GroupFilterOrderStore.addListener(this.onTagStoreUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import * as FormattingUtils from '../../../utils/FormattingUtils';
|
||||||
|
|
||||||
import FlairStore from '../../../stores/FlairStore';
|
import FlairStore from '../../../stores/FlairStore';
|
||||||
import GroupStore from '../../../stores/GroupStore';
|
import GroupStore from '../../../stores/GroupStore';
|
||||||
import TagOrderStore from '../../../stores/TagOrderStore';
|
import GroupFilterOrderStore from '../../../stores/GroupFilterOrderStore';
|
||||||
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
||||||
import AccessibleButton from "./AccessibleButton";
|
import AccessibleButton from "./AccessibleButton";
|
||||||
import SettingsStore from "../../../settings/SettingsStore";
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
|
@ -142,7 +142,7 @@ export default class TagTile extends React.Component {
|
||||||
mx_TagTile_selected_prototype: this.props.selected && isPrototype,
|
mx_TagTile_selected_prototype: this.props.selected && isPrototype,
|
||||||
});
|
});
|
||||||
|
|
||||||
const badge = TagOrderStore.getGroupBadge(this.props.tag);
|
const badge = GroupFilterOrderStore.getGroupBadge(this.props.tag);
|
||||||
let badgeElement;
|
let badgeElement;
|
||||||
if (badge && !this.state.hover && !this.props.menuDisplayed) {
|
if (badge && !this.state.hover && !this.props.menuDisplayed) {
|
||||||
const badgeClasses = classNames({
|
const badgeClasses = classNames({
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import defaultDispatcher from "../../../dispatcher/dispatcher";
|
import defaultDispatcher from "../../../dispatcher/dispatcher";
|
||||||
import * as fbEmitter from "fbemitter";
|
import * as fbEmitter from "fbemitter";
|
||||||
import TagOrderStore from "../../../stores/TagOrderStore";
|
import GroupFilterOrderStore from "../../../stores/GroupFilterOrderStore";
|
||||||
import AccessibleTooltipButton from "./AccessibleTooltipButton";
|
import AccessibleTooltipButton from "./AccessibleTooltipButton";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { _t } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
|
@ -36,12 +36,12 @@ export default class UserTagTile extends React.PureComponent<IProps, IState> {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
selected: TagOrderStore.getSelectedTags().length === 0,
|
selected: GroupFilterOrderStore.getSelectedTags().length === 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount() {
|
public componentDidMount() {
|
||||||
this.tagStoreRef = TagOrderStore.addListener(this.onTagStoreUpdate);
|
this.tagStoreRef = GroupFilterOrderStore.addListener(this.onTagStoreUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
|
@ -49,7 +49,7 @@ export default class UserTagTile extends React.PureComponent<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onTagStoreUpdate = () => {
|
private onTagStoreUpdate = () => {
|
||||||
const selected = TagOrderStore.getSelectedTags().length === 0;
|
const selected = GroupFilterOrderStore.getSelectedTags().length === 0;
|
||||||
this.setState({selected});
|
this.setState({selected});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import SettingsStore from "../settings/SettingsStore";
|
||||||
import * as utils from "matrix-js-sdk/src/utils";
|
import * as utils from "matrix-js-sdk/src/utils";
|
||||||
import { UPDATE_EVENT } from "./AsyncStore";
|
import { UPDATE_EVENT } from "./AsyncStore";
|
||||||
import FlairStore from "./FlairStore";
|
import FlairStore from "./FlairStore";
|
||||||
import TagOrderStore from "./TagOrderStore";
|
import GroupFilterOrderStore from "./GroupFilterOrderStore";
|
||||||
import GroupStore from "./GroupStore";
|
import GroupStore from "./GroupStore";
|
||||||
import dis from "../dispatcher/dispatcher";
|
import dis from "../dispatcher/dispatcher";
|
||||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||||
|
@ -50,7 +50,7 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
|
||||||
|
|
||||||
public getSelectedCommunityId(): string {
|
public getSelectedCommunityId(): string {
|
||||||
if (SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
if (SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
||||||
return TagOrderStore.getSelectedTags()[0];
|
return GroupFilterOrderStore.getSelectedTags()[0];
|
||||||
}
|
}
|
||||||
return null; // no selection as far as this function is concerned
|
return null; // no selection as far as this function is concerned
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ const INITIAL_STATE = {
|
||||||
/**
|
/**
|
||||||
* A class for storing application state for ordering tags in the GroupFilterPanel.
|
* A class for storing application state for ordering tags in the GroupFilterPanel.
|
||||||
*/
|
*/
|
||||||
class TagOrderStore extends Store {
|
class GroupFilterOrderStore extends Store {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(dis);
|
super(dis);
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ class TagOrderStore extends Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.singletonTagOrderStore === undefined) {
|
if (global.singletonGroupFilterOrderStore === undefined) {
|
||||||
global.singletonTagOrderStore = new TagOrderStore();
|
global.singletonGroupFilterOrderStore = new GroupFilterOrderStore();
|
||||||
}
|
}
|
||||||
export default global.singletonTagOrderStore;
|
export default global.singletonGroupFilterOrderStore;
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { RoomListStoreClass } from "./RoomListStore";
|
import { RoomListStoreClass } from "./RoomListStore";
|
||||||
import TagOrderStore from "../TagOrderStore";
|
import GroupFilterOrderStore from "../GroupFilterOrderStore";
|
||||||
import { CommunityFilterCondition } from "./filters/CommunityFilterCondition";
|
import { CommunityFilterCondition } from "./filters/CommunityFilterCondition";
|
||||||
import { arrayDiff, arrayHasDiff } from "../../utils/arrays";
|
import { arrayDiff, arrayHasDiff } from "../../utils/arrays";
|
||||||
|
|
||||||
|
@ -26,12 +26,12 @@ export class TagWatcher {
|
||||||
private filters = new Map<string, CommunityFilterCondition>();
|
private filters = new Map<string, CommunityFilterCondition>();
|
||||||
|
|
||||||
constructor(private store: RoomListStoreClass) {
|
constructor(private store: RoomListStoreClass) {
|
||||||
TagOrderStore.addListener(this.onTagsUpdated);
|
GroupFilterOrderStore.addListener(this.onTagsUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onTagsUpdated = () => {
|
private onTagsUpdated = () => {
|
||||||
const lastTags = Array.from(this.filters.keys());
|
const lastTags = Array.from(this.filters.keys());
|
||||||
const newTags = TagOrderStore.getSelectedTags();
|
const newTags = GroupFilterOrderStore.getSelectedTags();
|
||||||
|
|
||||||
if (arrayHasDiff(lastTags, newTags)) {
|
if (arrayHasDiff(lastTags, newTags)) {
|
||||||
// Selected tags changed, do some filtering
|
// Selected tags changed, do some filtering
|
||||||
|
|
Loading…
Reference in a new issue