summaryrefslogtreecommitdiffstats
path: root/webapp/reducers/views/rhs.js
blob: 1e648074308caa7a6f4e65530bd00b3e012d5ed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import {combineReducers} from 'redux';
import {ActionTypes} from 'utils/constants.jsx';
import {PostTypes} from 'mattermost-redux/action_types';

function selectedPostId(state = '', action) {
    switch (action.type) {
    case ActionTypes.SELECT_POST:
        return action.postId;
    case PostTypes.REMOVE_POST:
        if (action.data && action.data.id === state) {
            return '';
        }
        return state;
    default:
        return state;
    }
}

function fromSearch(state = '', action) {
    switch (action.type) {
    case ActionTypes.SELECT_POST:
        if (action.from_search) {
            return action.from_search;
        }
        return '';
    default:
        return state;
    }
}

function fromFlaggedPosts(state = false, action) {
    switch (action.type) {
    case ActionTypes.SELECT_POST:
        if (action.from_flagged_posts) {
            return action.from_flagged_posts;
        }
        return false;
    default:
        return state;
    }
}

function fromPinnedPosts(state = false, action) {
    switch (action.type) {
    case ActionTypes.SELECT_POST:
        if (action.from_pinned_posts) {
            return action.from_pinned_posts;
        }
        return false;
    default:
        return state;
    }
}

export default combineReducers({
    selectedPostId,
    fromSearch,
    fromFlaggedPosts,
    fromPinnedPosts
});