Can filter to show only unread rooms

This commit is contained in:
2025-12-03 08:53:44 +01:00
parent ab136ef6d0
commit 1a5a021711

View File

@@ -6,6 +6,7 @@ import {
ListItemIcon, ListItemIcon,
ListItemText, ListItemText,
} from "@mui/material"; } from "@mui/material";
import React from "react";
import type { UsersMap } from "../../api/matrix/MatrixApiProfile"; import type { UsersMap } from "../../api/matrix/MatrixApiProfile";
import { roomName, type Room } from "../../api/matrix/MatrixApiRoom"; import { roomName, type Room } from "../../api/matrix/MatrixApiRoom";
import { useUserInfo } from "../dashboard/BaseAuthenticatedPage"; import { useUserInfo } from "../dashboard/BaseAuthenticatedPage";
@@ -21,6 +22,13 @@ export function RoomSelector(p: {
}): React.ReactElement { }): React.ReactElement {
const user = useUserInfo(); const user = useUserInfo();
const [unread, setUnread] = React.useState(false);
const shownRooms = React.useMemo(
() => p.rooms.filter((r) => !unread || r.number_unread_messages > 0),
[p.rooms, unread]
);
if (p.rooms.length === 0) if (p.rooms.length === 0)
return ( return (
<div <div
@@ -36,12 +44,28 @@ export function RoomSelector(p: {
); );
return ( return (
<div style={{ display: "flex", flexDirection: "column" }}>
{/** Chip bar */}
<div style={{ padding: "5px 10px", marginTop: "5px" }}>
<span onClick={() => setUnread(!unread)} style={{ cursor: "pointer" }}>
<Chip
label="Unread"
size="medium"
color={unread ? "success" : undefined}
variant="outlined"
/>
</span>
</div>
{/** Rooms list */}
<List <List
style={{ style={{
flex: 1,
width: ROOM_SELECTOR_WIDTH, width: ROOM_SELECTOR_WIDTH,
overflow: "scroll",
}} }}
> >
{p.rooms.map((r) => ( {shownRooms.map((r) => (
<ListItem <ListItem
key={r.id} key={r.id}
secondaryAction={ secondaryAction={
@@ -76,5 +100,6 @@ export function RoomSelector(p: {
</ListItem> </ListItem>
))} ))}
</List> </List>
</div>
); );
} }