mattermost-mobile/app/actions/websocket/categories.ts
Shaz Amjad 64223efafe
MM-28474: Custom Sidebar Categories (#5460)
* Further cleanup and fixes

Tests clean-up

Tests fixed?

Plays nicely with threads

Tests fixed

Fixes ESR and show experimental flags

Failing test fixed

DM Fix

WIP: Bottom bar UX

Fixes for unreads

Failing test

Always show current channel

Create a channel in a category!

* Unreads on top

* Various fixes

* Improves category collapsing

* Passes correct ID through

* Tests cleanup

* Redo unreads and unread-button

* Reverts to just using ids

* More unreads back to using ids

* Uses appropriate selectors for pref updates

* Unreads sorted by recency

* Fixes test for recency

* Fixes re-rendering bug

* Code review updates, websocket event debounced
2021-09-20 14:11:57 -04:00

67 lines
2.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {debounce} from 'underscore';
import {fetchMyCategories, receivedCategoryOrder} from '@mm-redux/actions/channel_categories';
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
import {ActionResult, DispatchFunc, GetStateFunc} from '@mm-redux/types/actions';
import {WebSocketMessage} from '@mm-redux/types/websocket';
const fetchCats = debounce((dispatch: DispatchFunc, teamId: string) => dispatch(fetchMyCategories(teamId)), 1000);
export function handleSidebarCategoryCreated(msg: WebSocketMessage) {
return async (dispatch: DispatchFunc, getState: GetStateFunc): Promise<ActionResult> => {
const state = getState();
const currentTeamId = getCurrentTeamId(state);
if (msg.broadcast.team_id !== currentTeamId) {
// The new category will be loaded when we switch teams.
return {data: false};
}
// Fetch all categories, including ones that weren't explicitly updated, in case any other categories had channels
// moved out of them.
dispatch(fetchMyCategories(msg.broadcast.team_id));
return {data: true};
};
}
export function handleSidebarCategoryUpdated(msg: WebSocketMessage) {
return async (dispatch: DispatchFunc, getState: GetStateFunc): Promise<ActionResult> => {
const state = getState();
if (msg.broadcast.team_id !== getCurrentTeamId(state)) {
// The updated categories will be loaded when we switch teams.
return {data: false};
}
// Fetch all categories in case any other categories had channels moved out of them.
// dispatch(fetchMyCategories(msg.broadcast.team_id));
fetchCats(dispatch, msg.broadcast.team_id);
return {data: true};
};
}
export function handleSidebarCategoryDeleted(msg: WebSocketMessage) {
return async (dispatch: DispatchFunc, getState: GetStateFunc): Promise<ActionResult> => {
const state = getState();
if (msg.broadcast.team_id !== getCurrentTeamId(state)) {
// The category will be removed when we switch teams.
return {data: false};
}
// Fetch all categories since any channels that were in the deleted category were moved to other categories.
dispatch(fetchMyCategories(msg.broadcast.team_id));
return {data: true};
};
}
export function handleSidebarCategoryOrderUpdated(msg: WebSocketMessage) {
return receivedCategoryOrder(msg.broadcast.team_id, msg.data.order);
}