Combine forward dialog room and DM lists

Signed-off-by: Robin Townsend <robin@robin.town>
This commit is contained in:
Robin Townsend 2021-05-19 13:33:48 -04:00
parent 83224dc7b6
commit 6cb6c7f3d0
2 changed files with 9 additions and 39 deletions

View file

@ -63,7 +63,7 @@ limitations under the License.
margin-top: 24px; margin-top: 24px;
} }
.mx_ForwardList_section { .mx_ForwardList_results {
margin-right: 6px; margin-right: 6px;
&:not(:first-child) { &:not(:first-child) {

View file

@ -34,7 +34,6 @@ import DecoratedRoomAvatar from "../avatars/DecoratedRoomAvatar";
import AccessibleButton from "../elements/AccessibleButton"; import AccessibleButton from "../elements/AccessibleButton";
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
import AutoHideScrollbar from "../../structures/AutoHideScrollbar"; import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
import DMRoomMap from "../../../utils/DMRoomMap";
import {RoomPermalinkCreator} from "../../../utils/permalinks/Permalinks"; import {RoomPermalinkCreator} from "../../../utils/permalinks/Permalinks";
import {sortRooms} from "../../../stores/room-list/algorithms/tag-sorting/RecentAlgorithm"; import {sortRooms} from "../../../stores/room-list/algorithms/tag-sorting/RecentAlgorithm";
@ -162,26 +161,15 @@ const ForwardDialog: React.FC<IProps> = ({ cli, event, permalinkCreator, onFinis
getMxcAvatarUrl: () => profileInfo.avatar_url, getMxcAvatarUrl: () => profileInfo.avatar_url,
}; };
const visibleRooms = useMemo(() => sortRooms( const [query, setQuery] = useState("");
const lcQuery = query.toLowerCase();
const rooms = useMemo(() => sortRooms(
cli.getVisibleRooms().filter( cli.getVisibleRooms().filter(
room => room.getMyMembership() === "join" && room => room.getMyMembership() === "join" &&
!(SettingsStore.getValue("feature_spaces") && room.isSpaceRoom()), !(SettingsStore.getValue("feature_spaces") && room.isSpaceRoom()),
), ),
), [cli]); ), [cli]).filter(room => room.name.toLowerCase().includes(lcQuery));
const [query, setQuery] = useState("");
const lcQuery = query.toLowerCase();
const [rooms, dms] = visibleRooms.reduce((arr, room) => {
if (room.name.toLowerCase().includes(lcQuery)) {
if (DMRoomMap.shared().getUserIdForRoomId(room.roomId)) {
arr[1].push(room);
} else {
arr[0].push(room);
}
}
return arr;
}, [[], []]);
const previewLayout = SettingsStore.getValue("layout"); const previewLayout = SettingsStore.getValue("layout");
@ -214,8 +202,7 @@ const ForwardDialog: React.FC<IProps> = ({ cli, event, permalinkCreator, onFinis
/> />
<AutoHideScrollbar className="mx_ForwardList_content" id="mx_ForwardList"> <AutoHideScrollbar className="mx_ForwardList_content" id="mx_ForwardList">
{ rooms.length > 0 ? ( { rooms.length > 0 ? (
<div className="mx_ForwardList_section"> <div className="mx_ForwardList_results">
<h3>{ _t("Rooms") }</h3>
{ rooms.map(room => { rooms.map(room =>
<Entry <Entry
key={room.roomId} key={room.roomId}
@ -226,26 +213,9 @@ const ForwardDialog: React.FC<IProps> = ({ cli, event, permalinkCreator, onFinis
/>, />,
) } ) }
</div> </div>
) : undefined } ) : <span className="mx_ForwardList_noResults">
{ dms.length > 0 ? (
<div className="mx_ForwardList_section">
<h3>{ _t("Direct Messages") }</h3>
{ dms.map(room =>
<Entry
key={room.roomId}
room={room}
event={event}
cli={cli}
onFinished={onFinished}
/>,
) }
</div>
) : undefined }
{ rooms.length + dms.length < 1 ? <span className="mx_ForwardList_noResults">
{ _t("No results") } { _t("No results") }
</span> : undefined } </span> }
</AutoHideScrollbar> </AutoHideScrollbar>
</div> </div>
</BaseDialog>; </BaseDialog>;