1
- import { IconButton } from "@fluentui/react/lib/Button" ;
2
- import { DocumentCard , DocumentCardDetails } from "@fluentui/react/lib/DocumentCard" ;
3
- import { Stack } from "@fluentui/react/lib/Stack" ;
4
- import * as React from "react" ;
5
- import { useCallback } from "react" ;
6
- import { useContext } from "react" ;
7
- import { ConfirmDelete } from "../ConfirmDelete/ConfirmDelete" ;
8
- import { EListItemCommentsStateTypes , ListItemCommentsStateContext } from "../ListItemCommentsStateProvider" ;
9
- import { CommentItem } from "./CommentItem" ;
10
- import { IComment } from "./IComment" ;
11
- import { RenderSpinner } from "./RenderSpinner" ;
12
- import { useListItemCommentsStyles } from "./useListItemCommentsStyles" ;
13
- import { useBoolean } from "@fluentui/react-hooks" ;
14
- import { List } from "@fluentui/react/lib/List" ;
15
- import { AppContext , ECommentAction } from "../.." ;
1
+ import { IconButton } from '@fluentui/react/lib/Button' ;
2
+ import {
3
+ DocumentCard ,
4
+ DocumentCardDetails ,
5
+ } from '@fluentui/react/lib/DocumentCard' ;
6
+ import { Stack } from '@fluentui/react/lib/Stack' ;
7
+ import * as React from 'react' ;
8
+ import { useCallback } from 'react' ;
9
+ import { useContext } from 'react' ;
10
+ import { ConfirmDelete } from '../ConfirmDelete/ConfirmDelete' ;
11
+ import {
12
+ EListItemCommentsStateTypes ,
13
+ ListItemCommentsStateContext ,
14
+ } from '../ListItemCommentsStateProvider' ;
15
+ import { CommentItem } from './CommentItem' ;
16
+ import { IComment } from './IComment' ;
17
+ import { RenderSpinner } from './RenderSpinner' ;
18
+ import { useListItemCommentsStyles } from './useListItemCommentsStyles' ;
19
+ import { useBoolean } from '@fluentui/react-hooks' ;
20
+ import { List , Text } from '@fluentui/react' ;
21
+ import { AppContext , ECommentAction } from '../..' ;
16
22
17
- export interface IRenderCommentsProps { }
23
+ export interface IRenderCommentsProps { }
18
24
19
- export const RenderComments : React . FunctionComponent < IRenderCommentsProps > = ( ) => {
25
+ export const RenderComments : React . FunctionComponent <
26
+ IRenderCommentsProps
27
+ > = ( ) => {
20
28
const { highlightedCommentId } = useContext ( AppContext ) ;
21
- const { listItemCommentsState, setlistItemCommentsState } = useContext ( ListItemCommentsStateContext ) ;
22
- const { documentCardStyles, documentCardHighlightedStyles, itemContainerStyles, deleteButtonContainerStyles } = useListItemCommentsStyles ( ) ;
29
+ const { listItemCommentsState, setlistItemCommentsState } = useContext (
30
+ ListItemCommentsStateContext
31
+ ) ;
32
+ const {
33
+ documentCardStyles,
34
+ documentCardHighlightedStyles,
35
+ itemContainerStyles,
36
+ buttonsContainerStyles,
37
+ } = useListItemCommentsStyles ( ) ;
23
38
const { comments, isLoading } = listItemCommentsState ;
24
39
25
40
const [ hideDialog , { toggle : setHideDialog } ] = useBoolean ( true ) ;
26
41
42
+ const _likeComment = useCallback ( ( ) => {
43
+ setlistItemCommentsState ( {
44
+ type : EListItemCommentsStateTypes . SET_COMMENT_ACTION ,
45
+ payload : ECommentAction . LIKE ,
46
+ } ) ;
47
+ } , [ ] ) ;
48
+
49
+ const _unLikeComment = useCallback ( ( ) => {
50
+ setlistItemCommentsState ( {
51
+ type : EListItemCommentsStateTypes . SET_COMMENT_ACTION ,
52
+ payload : ECommentAction . UNLIKE ,
53
+ } ) ;
54
+ } , [ ] ) ;
55
+
27
56
const onRenderCell = useCallback (
28
57
( comment : IComment , index : number ) : JSX . Element => {
29
58
return (
30
- < DocumentCard styles = { highlightedCommentId && comment . id === highlightedCommentId ? documentCardHighlightedStyles : documentCardStyles } key = { index } >
31
- < Stack horizontal horizontalAlign = "end" styles = { deleteButtonContainerStyles } >
59
+ < DocumentCard
60
+ styles = {
61
+ highlightedCommentId && comment . id === highlightedCommentId
62
+ ? documentCardHighlightedStyles
63
+ : documentCardStyles
64
+ }
65
+ key = { index }
66
+ >
67
+ < Stack
68
+ horizontal
69
+ horizontalAlign = "end"
70
+ styles = { buttonsContainerStyles }
71
+ >
72
+ < div style = { { display : 'flex' , alignItems : 'center' } } >
73
+ < Text > { comment . likeCount } </ Text >
74
+ < IconButton
75
+ iconProps = { {
76
+ iconName : `${ comment . isLikedByUser ? 'LikeSolid' : 'Like' } ` ,
77
+ } }
78
+ style = { { fontSize : 10 } }
79
+ onClick = { ( ) => {
80
+ setlistItemCommentsState ( {
81
+ type : EListItemCommentsStateTypes . SET_SELECTED_COMMENT ,
82
+ payload : comment ,
83
+ } ) ;
84
+ if ( ! comment . isLikedByUser ) {
85
+ _likeComment ( ) ;
86
+ } else {
87
+ _unLikeComment ( ) ;
88
+ }
89
+ } }
90
+ />
91
+ </ div >
32
92
< IconButton
33
- iconProps = { { iconName : " Delete" } }
93
+ iconProps = { { iconName : ' Delete' } }
34
94
style = { { fontSize : 10 } }
35
95
onClick = { async ( ) => {
36
96
setlistItemCommentsState ( {
@@ -57,10 +117,13 @@ export const RenderComments: React.FunctionComponent<IRenderCommentsProps> = ()
57
117
} ,
58
118
[ comments ]
59
119
) ;
60
-
61
120
return (
62
121
< >
63
- { isLoading ? < RenderSpinner /> : < List items = { comments } onRenderCell = { onRenderCell } /> }
122
+ { isLoading ? (
123
+ < RenderSpinner />
124
+ ) : (
125
+ < List items = { comments } onRenderCell = { onRenderCell } />
126
+ ) }
64
127
< ConfirmDelete
65
128
hideDialog = { hideDialog }
66
129
onDismiss = { ( deleteComment : boolean ) => {
0 commit comments