1
1
import React , { useMemo } from 'react' ;
2
2
import { CommonSidebarWrapper } from '@/components/CommonSidebarWrapper' ;
3
- import { isValidStr , model , t , useInboxList } from 'tailchat-shared' ;
3
+ import { InboxItem , isValidStr , model , t , useInboxList } from 'tailchat-shared' ;
4
4
import clsx from 'clsx' ;
5
5
import _orderBy from 'lodash/orderBy' ;
6
6
import { GroupName } from '@/components/GroupName' ;
7
7
import { ConverseName } from '@/components/ConverseName' ;
8
8
import { getMessageRender } from '@/plugin/common' ;
9
9
import { useLocation } from 'react-router' ;
10
10
import { Link } from 'react-router-dom' ;
11
+ import { PillTabPane , PillTabs } from '@/components/PillTabs' ;
11
12
12
13
/**
13
14
* 收件箱侧边栏组件
@@ -16,33 +17,48 @@ export const InboxSidebar: React.FC = React.memo(() => {
16
17
const inbox = useInboxList ( ) ;
17
18
const list = useMemo ( ( ) => _orderBy ( inbox , 'createdAt' , 'desc' ) , [ inbox ] ) ;
18
19
19
- return (
20
- < CommonSidebarWrapper data-tc-role = "sidebar-inbox" >
21
- < div className = "overflow-auto" >
22
- { list . map ( ( item ) => {
23
- const { type } = item ;
20
+ const renderInbox = ( item : InboxItem ) => {
21
+ const { type } = item ;
22
+
23
+ if ( type === 'message' ) {
24
+ const message : Partial < model . inbox . InboxItem [ 'message' ] > =
25
+ item . message ?? { } ;
26
+ let title : React . ReactNode = '' ;
27
+ if ( isValidStr ( message . groupId ) ) {
28
+ title = < GroupName groupId = { message . groupId } /> ;
29
+ } else if ( isValidStr ( message . converseId ) ) {
30
+ title = < ConverseName converseId = { message . converseId } /> ;
31
+ }
32
+
33
+ return (
34
+ < InboxSidebarItem
35
+ key = { item . _id }
36
+ title = { title }
37
+ desc = { getMessageRender ( message . messageSnippet ?? '' ) }
38
+ source = { 'Tailchat' }
39
+ readed = { item . readed }
40
+ to = { `/main/inbox/${ item . _id } ` }
41
+ />
42
+ ) ;
43
+ }
24
44
25
- if ( type === 'message' ) {
26
- const message : Partial < model . inbox . InboxItem [ 'message' ] > =
27
- item . message ?? { } ;
28
- let title : React . ReactNode = '' ;
29
- if ( isValidStr ( message . groupId ) ) {
30
- title = < GroupName groupId = { message . groupId } /> ;
31
- } else if ( isValidStr ( message . converseId ) ) {
32
- title = < ConverseName converseId = { message . converseId } /> ;
33
- }
45
+ return null ;
46
+ } ;
34
47
35
- return (
36
- < InboxSidebarItem
37
- key = { item . _id }
38
- title = { title }
39
- desc = { getMessageRender ( message . messageSnippet ?? '' ) }
40
- source = { 'Tailchat' }
41
- to = { `/main/inbox/${ item . _id } ` }
42
- />
43
- ) ;
44
- }
45
- } ) }
48
+ const fullList = list ;
49
+ const unreadList = list . filter ( ( item ) => item . readed === false ) ;
50
+
51
+ return (
52
+ < CommonSidebarWrapper data-tc-role = "sidebar-inbox" >
53
+ < div >
54
+ < PillTabs >
55
+ < PillTabPane key = "1" tab = { `${ t ( '全部' ) } (${ fullList . length } )` } >
56
+ { fullList . map ( ( item ) => renderInbox ( item ) ) }
57
+ </ PillTabPane >
58
+ < PillTabPane key = "2" tab = { `${ t ( '未读' ) } (${ unreadList . length } )` } >
59
+ { unreadList . map ( ( item ) => renderInbox ( item ) ) }
60
+ </ PillTabPane >
61
+ </ PillTabs >
46
62
</ div >
47
63
</ CommonSidebarWrapper >
48
64
) ;
@@ -53,6 +69,7 @@ const InboxSidebarItem: React.FC<{
53
69
title : React . ReactNode ;
54
70
desc : React . ReactNode ;
55
71
source : string ;
72
+ readed : boolean ;
56
73
to : string ;
57
74
} > = React . memo ( ( props ) => {
58
75
const location = useLocation ( ) ;
@@ -62,10 +79,11 @@ const InboxSidebarItem: React.FC<{
62
79
< Link to = { props . to } >
63
80
< div
64
81
className = { clsx (
65
- 'p-2 overflow-auto cursor-pointer hover:bg-black hover:bg-opacity-10 dark:hover:bg-white dark:hover:bg-opacity-10' ,
82
+ 'p-2 overflow-auto cursor-pointer hover:bg-black hover:bg-opacity-10 dark:hover:bg-white dark:hover:bg-opacity-10 border-r-4 rounded ' ,
66
83
{
67
84
'bg-black bg-opacity-10 dark:bg-white dark:bg-opacity-10' : isActive ,
68
- }
85
+ } ,
86
+ props . readed ? 'border-transparent' : 'border-green-500'
69
87
) }
70
88
>
71
89
< div className = "text-lg overflow-ellipsis overflow-hidden text-gray-700 dark:text-white" >
0 commit comments