* Enable import order * Add new order groups and add consistent-type-imports * Remove types group, move react to top and fix issues * Add store and reducers to the redux group and move imports from types folder to the end * Fix tsc * Remove react rule * Fix test * Fix eslint disable
55 строки
2.0 KiB
TypeScript
55 строки
2.0 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import type {Post} from '@mattermost/types/posts';
|
|
|
|
import {createSelector} from 'mattermost-redux/selectors/create_selector';
|
|
import {getPost} from 'mattermost-redux/selectors/entities/posts';
|
|
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
|
|
|
|
import {arePreviewsCollapsed} from 'selectors/preferences';
|
|
import {getGlobalItem} from 'selectors/storage';
|
|
|
|
import {StoragePrefixes} from 'utils/constants';
|
|
|
|
import type {GlobalState} from 'types/store';
|
|
|
|
export function getIsPostBeingEdited(state: GlobalState, postId: string) {
|
|
return state.views.posts.editingPost.postId === postId && state.views.posts.editingPost.show;
|
|
}
|
|
export function getIsPostBeingEditedInRHS(state: GlobalState, postId: string) {
|
|
const editingPost = getEditingPost(state);
|
|
|
|
return editingPost.isRHS && editingPost.postId === postId && state.views.posts.editingPost.show;
|
|
}
|
|
|
|
export function getPostEditHistory(state: GlobalState): Post[] {
|
|
return state.entities.posts.postEditHistory;
|
|
}
|
|
|
|
export const getEditingPost = createSelector(
|
|
'getEditingPost',
|
|
(state: GlobalState) => state.views.posts.editingPost,
|
|
(state: GlobalState) => getPost(state, state.views.posts.editingPost.postId),
|
|
(editingPost, post) => {
|
|
return {
|
|
...editingPost,
|
|
post,
|
|
};
|
|
},
|
|
);
|
|
|
|
export function isEmbedVisible(state: GlobalState, postId: string) {
|
|
const currentUserId = getCurrentUserId(state);
|
|
const previewCollapsed = arePreviewsCollapsed(state);
|
|
|
|
return getGlobalItem(state, StoragePrefixes.EMBED_VISIBLE + currentUserId + '_' + postId, !previewCollapsed);
|
|
}
|
|
|
|
export function isInlineImageVisible(state: GlobalState, postId: string, imageKey: string) {
|
|
const currentUserId = getCurrentUserId(state);
|
|
const imageCollapsed = arePreviewsCollapsed(state);
|
|
|
|
return getGlobalItem(state, StoragePrefixes.INLINE_IMAGE_VISIBLE + currentUserId + '_' + postId + '_' + imageKey, !imageCollapsed);
|
|
}
|