perf: server navigation
This commit is contained in:
@@ -42,6 +42,20 @@ function getDefaultTextChannelId(room: Room): string {
|
||||
return resolveActiveTextChannelId(enrichRoom(room).channels, 'general');
|
||||
}
|
||||
|
||||
function activateRoomView(state: RoomsState, room: Room, isConnecting: boolean): RoomsState {
|
||||
const enriched = enrichRoom(room);
|
||||
|
||||
return {
|
||||
...state,
|
||||
currentRoom: enriched,
|
||||
savedRooms: upsertRoom(state.savedRooms, enriched),
|
||||
isConnecting,
|
||||
signalServerCompatibilityError: null,
|
||||
isConnected: true,
|
||||
activeChannelId: getDefaultTextChannelId(enriched)
|
||||
};
|
||||
}
|
||||
|
||||
/** Upsert a room into a saved-rooms list (add or replace by id) */
|
||||
function upsertRoom(savedRooms: Room[], room: Room): Room[] {
|
||||
const normalizedRoom = enrichRoom(room);
|
||||
@@ -220,27 +234,24 @@ export const roomsReducer = createReducer(
|
||||
})),
|
||||
|
||||
// View server - just switch the viewed room, stay connected
|
||||
on(RoomsActions.viewServer, (state) => ({
|
||||
...state,
|
||||
isConnecting: true,
|
||||
signalServerCompatibilityError: null,
|
||||
error: null
|
||||
})),
|
||||
|
||||
on(RoomsActions.viewServerSuccess, (state, { room }) => {
|
||||
const enriched = enrichRoom(room);
|
||||
on(RoomsActions.viewServer, (state, { room, skipBanCheck }) => {
|
||||
if (skipBanCheck) {
|
||||
return {
|
||||
...activateRoomView(state, room, true),
|
||||
error: null
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
currentRoom: enriched,
|
||||
savedRooms: upsertRoom(state.savedRooms, enriched),
|
||||
isConnecting: false,
|
||||
isConnecting: true,
|
||||
signalServerCompatibilityError: null,
|
||||
isConnected: true,
|
||||
activeChannelId: getDefaultTextChannelId(enriched)
|
||||
error: null
|
||||
};
|
||||
}),
|
||||
|
||||
on(RoomsActions.viewServerSuccess, (state, { room }) => activateRoomView(state, room, false)),
|
||||
|
||||
// Update room settings
|
||||
on(RoomsActions.updateRoomSettings, (state) => ({
|
||||
...state,
|
||||
|
||||
Reference in New Issue
Block a user