added the starred item button to the left panel

This commit is contained in:
yaya-usman 2022-07-21 15:53:09 +03:00
parent 38a913488f
commit c5e982f5b0
4 changed files with 46 additions and 2 deletions

View file

@ -77,10 +77,12 @@ interface IState {
sublists: ITagMap;
currentRoomId?: string;
suggestedRooms: ISuggestedRoom[];
feature_favourite_messages: boolean;
}
export const TAG_ORDER: TagID[] = [
DefaultTagID.Invite,
DefaultTagID.SavedItems,
DefaultTagID.Favourite,
DefaultTagID.DM,
DefaultTagID.Untagged,
@ -351,6 +353,11 @@ const TAG_AESTHETICS: ITagAestheticsMap = {
isInvite: false,
defaultHidden: false,
},
[DefaultTagID.SavedItems]: {
sectionLabel: _td("Saved Items"),
isInvite: false,
defaultHidden: false,
},
[DefaultTagID.DM]: {
sectionLabel: _td("People"),
isInvite: false,
@ -392,6 +399,7 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
private dispatcherRef;
private roomStoreToken: fbEmitter.EventSubscription;
private treeRef = createRef<HTMLDivElement>();
private favouriteMessageWatcher: string;
static contextType = MatrixClientContext;
public context!: React.ContextType<typeof MatrixClientContext>;
@ -402,6 +410,7 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
this.state = {
sublists: {},
suggestedRooms: SpaceStore.instance.suggestedRooms,
feature_favourite_messages: SettingsStore.getValue("feature_favourite_messages"),
};
}
@ -410,12 +419,17 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
this.roomStoreToken = RoomViewStore.instance.addListener(this.onRoomViewStoreUpdate);
SpaceStore.instance.on(UPDATE_SUGGESTED_ROOMS, this.updateSuggestedRooms);
RoomListStore.instance.on(LISTS_UPDATE_EVENT, this.updateLists);
this.favouriteMessageWatcher =
SettingsStore.watchSetting("feature_favourite_messages", null, (...[,,, value]) => {
this.setState({ feature_favourite_messages: value });
});
this.updateLists(); // trigger the first update
}
public componentWillUnmount() {
SpaceStore.instance.off(UPDATE_SUGGESTED_ROOMS, this.updateSuggestedRooms);
RoomListStore.instance.off(LISTS_UPDATE_EVENT, this.updateLists);
SettingsStore.unwatchSetting(this.favouriteMessageWatcher);
defaultDispatcher.unregister(this.dispatcherRef);
if (this.roomStoreToken) this.roomStoreToken.remove();
}
@ -545,6 +559,28 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
);
});
}
private renderFavoriteMessagesList(): ReactComponentElement<typeof ExtraTile>[] {
const avatar = (
<RoomAvatar
oobData={{
name: "Favourites",
}}
width={32}
height={32}
resizeMethod="crop"
/>);
return [
<ExtraTile
isMinimized={this.props.isMinimized}
isSelected={false}
displayName="Favourite Messages"
avatar={avatar}
onClick={() => ""}
key="favMessagesTile_key"
/>,
];
}
private renderSublists(): React.ReactElement[] {
// show a skeleton UI if the user is in no rooms and they are not filtering and have no suggested rooms
@ -558,6 +594,12 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
extraTiles = this.renderSuggestedRooms();
}
if (this.state.feature_favourite_messages && orderedTagId === DefaultTagID.SavedItems) {
extraTiles = this.renderFavoriteMessagesList();
} else {
extraTiles = null;
}
const aesthetics = TAG_AESTHETICS[orderedTagId];
if (!aesthetics) throw new Error(`Tag ${orderedTagId} does not have aesthetics`);
@ -582,7 +624,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
) {
forceExpanded = true;
}
// The cost of mounting/unmounting this component offsets the cost
// of keeping it in the DOM and hiding it when it is not required
return <RoomSublist