Skip to content

Commit f35dcee

Browse files
authored
Feat show all rooms (#866)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description Adds toggle for showing all rooms, allow routing rooms through home when so desired, and list the rooms by activity (basically this) <img width="599" height="463" alt="image" src="https://github.com/user-attachments/assets/bed8017a-3475-4dec-9c3b-1b3386b3637f" /> Fixes #862 #### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. --> Written with the dread of having to touch the router and fearing breaking sth that we'll only find out about months after this feature becomes mundane
2 parents f134ee9 + d448c75 commit f35dcee

6 files changed

Lines changed: 40 additions & 10 deletions

File tree

.changeset/add_show_all_rooms.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: minor
3+
---
4+
5+
Add toggle to list all rooms inside of the home sidebar.

src/app/pages/client/home/Home.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ type HomeMenuProps = {
7171
const HomeMenu = forwardRef<HTMLDivElement, HomeMenuProps>(({ requestClose }, ref) => {
7272
const orphanRooms = useHomeRooms();
7373
const [hideReads] = useSetting(settingsAtom, 'hideReads');
74+
const [isShowingAllRoomsInHome, setIsShowingAllRoomsInHome] = useSetting(
75+
settingsAtom,
76+
'isShowingAllRoomsInHome'
77+
);
7478
const unread = useRoomsUnread(orphanRooms, roomToUnreadAtom);
7579
const mx = useMatrixClient();
7680

@@ -94,6 +98,16 @@ const HomeMenu = forwardRef<HTMLDivElement, HomeMenuProps>(({ requestClose }, re
9498
Mark as Read
9599
</Text>
96100
</MenuItem>
101+
<MenuItem
102+
onClick={() => setIsShowingAllRoomsInHome(!isShowingAllRoomsInHome)}
103+
size="300"
104+
after={<Icon size="100" src={isShowingAllRoomsInHome ? Icons.Home : Icons.Globe} />}
105+
radii="300"
106+
>
107+
<Text style={{ flexGrow: 1 }} as="span" size="T300" truncate>
108+
{isShowingAllRoomsInHome ? 'Show Home Rooms' : 'Show All Rooms'}
109+
</Text>
110+
</MenuItem>
97111
</Box>
98112
</Menu>
99113
);
@@ -205,7 +219,8 @@ export function Home() {
205219
const mx = useMatrixClient();
206220
useNavToActivePathMapper('home');
207221
const scrollRef = useRef<HTMLDivElement>(null);
208-
const rooms = useHomeRooms();
222+
const [isShowingAllRoomsInHome] = useSetting(settingsAtom, 'isShowingAllRoomsInHome');
223+
const rooms = useHomeRooms(isShowingAllRoomsInHome);
209224
const notificationPreferences = useRoomsNotificationPreferencesContext();
210225
const roomToUnread = useAtomValue(roomToUnreadAtom);
211226
const navigate = useNavigate();
@@ -236,7 +251,7 @@ export function Home() {
236251

237252
const sortedRooms = useMemo(() => {
238253
const items = Array.from(rooms).toSorted(
239-
closedCategories.has(DEFAULT_CATEGORY_ID)
254+
closedCategories.has(DEFAULT_CATEGORY_ID) || isShowingAllRoomsInHome
240255
? factoryRoomIdByActivity(mx)
241256
: factoryRoomIdByAtoZ(mx)
242257
);
@@ -248,7 +263,7 @@ export function Home() {
248263
return items.filter((rId) => hasUnread(rId) || rId === selectedRoomId);
249264
}
250265
return items;
251-
}, [mx, rooms, closedCategories, roomToUnread, selectedRoomId]);
266+
}, [mx, rooms, closedCategories, roomToUnread, selectedRoomId, isShowingAllRoomsInHome]);
252267

253268
const virtualizer = useVirtualizer({
254269
count: sortedRooms.length,
@@ -411,6 +426,7 @@ export function Home() {
411426
const room = mx.getRoom(roomId);
412427
if (!room) return null;
413428
const selected = selectedRoomId === roomId;
429+
const canonicalName = getCanonicalAliasOrRoomId(mx, roomId);
414430

415431
return (
416432
<VirtualTile
@@ -436,7 +452,7 @@ export function Home() {
436452
selected={selected}
437453
showAvatar={showIcons()}
438454
hideText={hideText}
439-
linkPath={getHomeRoomPath(getCanonicalAliasOrRoomId(mx, roomId))}
455+
linkPath={getHomeRoomPath(canonicalName)}
440456
notificationMode={getRoomNotificationMode(
441457
notificationPreferences,
442458
room.roomId

src/app/pages/client/home/RoomProvider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import { useMatrixClient } from '$hooks/useMatrixClient';
66
import { JoinBeforeNavigate } from '$features/join-before-navigate';
77
import { useSearchParamsViaServers } from '$hooks/router/useSearchParamsViaServers';
88
import { useHomeRooms } from './useHomeRooms';
9+
import { useSetting } from '$state/hooks/settings';
10+
import { settingsAtom } from '$state/settings';
911

1012
export function HomeRouteRoomProvider({ children }: { children: ReactNode }) {
1113
const mx = useMatrixClient();
14+
const [isShowingAllRoomsInHome] = useSetting(settingsAtom, 'isShowingAllRoomsInHome');
1215
const rooms = useHomeRooms();
1316

1417
const { roomIdOrAlias: encodedRoomIdOrAlias, eventId: encodedEventId } = useParams();
@@ -18,7 +21,7 @@ export function HomeRouteRoomProvider({ children }: { children: ReactNode }) {
1821
const roomId = useSelectedRoom();
1922
const room = mx.getRoom(roomId);
2023

21-
if (!room || !rooms.includes(room.roomId)) {
24+
if (!room || (!isShowingAllRoomsInHome && !rooms.includes(room.roomId))) {
2225
return (
2326
<JoinBeforeNavigate
2427
roomIdOrAlias={roomIdOrAlias!}

src/app/pages/client/home/useHomeRooms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { roomToParentsAtom } from '$state/room/roomToParents';
55
import { allRoomsAtom } from '$state/room-list/roomList';
66
import { useOrphanRooms } from '$state/hooks/roomList';
77

8-
export const useHomeRooms = () => {
8+
export const useHomeRooms = (isShowingAllRoomsInHome?: boolean) => {
99
const mx = useMatrixClient();
1010
const mDirects = useAtomValue(mDirectAtom);
1111
const roomToParents = useAtomValue(roomToParentsAtom);
12-
const rooms = useOrphanRooms(mx, allRoomsAtom, mDirects, roomToParents);
12+
const rooms = useOrphanRooms(mx, allRoomsAtom, mDirects, roomToParents, isShowingAllRoomsInHome);
1313
return rooms;
1414
};

src/app/state/hooks/roomList.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ export const useOrphanRooms = (
152152
mx: MatrixClient,
153153
roomsAtom: RoomsAtom,
154154
mDirects: Set<string>,
155-
roomToParents: RoomToParents
155+
roomToParents: RoomToParents,
156+
isShowingAllRoomsInHome?: boolean
156157
) => {
157158
const selector: RoomSelector = useCallback(
158-
(roomId) => isRoom(mx.getRoom(roomId)) && !mDirects.has(roomId) && !roomToParents.has(roomId),
159-
[mx, mDirects, roomToParents]
159+
(roomId) =>
160+
isRoom(mx.getRoom(roomId)) &&
161+
!mDirects.has(roomId) &&
162+
(isShowingAllRoomsInHome || !roomToParents.has(roomId)),
163+
[mx, mDirects, roomToParents, isShowingAllRoomsInHome]
160164
);
161165
return useSelectedRooms(roomsAtom, selector);
162166
};

src/app/state/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export interface Settings {
187187
threadRootHeight: number;
188188
vcmsgSidebarWidth: number;
189189
widgetSidebarWidth: number;
190+
isShowingAllRoomsInHome: boolean;
190191

191192
// furry stuff
192193
renderAnimals: boolean;
@@ -321,6 +322,7 @@ export const defaultSettings: Settings = {
321322
threadRootHeight: 220,
322323
vcmsgSidebarWidth: 399,
323324
widgetSidebarWidth: 420,
325+
isShowingAllRoomsInHome: false,
324326
// furry stuff
325327
renderAnimals: true,
326328

0 commit comments

Comments
 (0)