From 1f6a500b2155f358631d7f3cb94f0a27f8d308e7 Mon Sep 17 00:00:00 2001 From: Benjamin Cooke Date: Tue, 7 Mar 2023 15:05:01 -0500 Subject: [PATCH] adding some selectors to the create new cards modal --- webapp/src/components/cardDialog.tsx | 9 +++++---- webapp/src/store/attachments.ts | 9 ++++++++- webapp/src/store/comments.ts | 8 ++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/webapp/src/components/cardDialog.tsx b/webapp/src/components/cardDialog.tsx index da13e035d..d999d59de 100644 --- a/webapp/src/components/cardDialog.tsx +++ b/webapp/src/components/cardDialog.tsx @@ -9,10 +9,10 @@ import {Card} from '../blocks/card' import octoClient from '../octoClient' import mutator from '../mutator' import {getCard} from '../store/cards' -import {getCardComments} from '../store/comments' +import {getCardComments, getCardComments1} from '../store/comments' import {getCardContents} from '../store/contents' import {useAppDispatch, useAppSelector} from '../store/hooks' -import {getCardAttachments, updateAttachments, updateUploadPrecent} from '../store/attachments' +import {getCardAttachments, getCardAttachments1, updateAttachments, updateUploadPrecent} from '../store/attachments' import TelemetryClient, {TelemetryActions, TelemetryCategory} from '../telemetry/telemetryClient' import {Utils} from '../utils' import CompassIcon from '../widgets/icons/compassIcon' @@ -39,6 +39,7 @@ import Dialog from './dialog' import './cardDialog.scss' import CardActionsMenu from './cardActionsMenu/cardActionsMenu' +import {RootState} from '../store' type Props = { board: Board @@ -55,8 +56,8 @@ const CardDialog = (props: Props): JSX.Element => { const {board, activeView, cards, views} = props const card = useAppSelector(getCard(props.cardId)) const contents = useAppSelector(getCardContents(props.cardId)) - const comments = useAppSelector(getCardComments(props.cardId)) - const attachments = useAppSelector(getCardAttachments(props.cardId)) + const comments = useAppSelector((state: RootState) => getCardComments1(state, props.cardId)) + const attachments = useAppSelector((state: RootState) => getCardAttachments1(state, props.cardId)) const clientConfig = useAppSelector(getClientConfig) const intl = useIntl() const dispatch = useAppDispatch() diff --git a/webapp/src/store/attachments.ts b/webapp/src/store/attachments.ts index 879e364e3..2a3b55553 100644 --- a/webapp/src/store/attachments.ts +++ b/webapp/src/store/attachments.ts @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {createSlice, PayloadAction} from '@reduxjs/toolkit' +import {createSelector, createSlice, PayloadAction} from '@reduxjs/toolkit' import {AttachmentBlock} from '../blocks/attachmentBlock' @@ -90,3 +90,10 @@ export function getUploadPercent(blockId: string): (state: RootState) => number return (state.attachments.attachments[blockId].uploadingPercent) } } + +export const getCardAttachments1: (state: RootState, cardId: string) => AttachmentBlock[] = createSelector( + (state: RootState, cardId: string) => state.attachments.attachmentsByCard[cardId], + (attachments) => { + return attachments || [] + }, +) diff --git a/webapp/src/store/comments.ts b/webapp/src/store/comments.ts index 325d804ab..5b44bea5d 100644 --- a/webapp/src/store/comments.ts +++ b/webapp/src/store/comments.ts @@ -86,6 +86,14 @@ export function getCardComments(cardId: string): (state: RootState) => CommentBl } } +export const getCardComments1: (state: RootState, cardId: string) => CommentBlock[] = createSelector( + (state: RootState, cardId: string) => state.comments?.commentsByCard[cardId], + (comments) => { + console.log(comments) + return comments || [] + }, +) + export function getLastCardComment(cardId: string): (state: RootState) => CommentBlock|undefined { return (state: RootState): CommentBlock|undefined => { const comments = state.comments?.commentsByCard && state.comments.commentsByCard[cardId]