Skip to content

Commit 7103819

Browse files
committed
Add comment count to task list item
1 parent 673c48e commit 7103819

File tree

6 files changed

+108
-20
lines changed

6 files changed

+108
-20
lines changed

src/data/fragments.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ fragment CreateTaskFields on Task {
4949
dueDate
5050
ethDomainId
5151
ethSkillId
52+
events {
53+
id
54+
type
55+
}
5256
finalizedAt
5357
title
5458
workRequestAddresses

src/data/generated.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ export type CreateTaskFieldsFragment = (
13731373
& { assignedWorker: Maybe<(
13741374
Pick<User, 'id'>
13751375
& { profile: Pick<UserProfile, 'avatarHash'> }
1376-
)>, colony: Pick<Colony, 'id' | 'colonyName' | 'displayName' | 'nativeTokenAddress'> }
1376+
)>, colony: Pick<Colony, 'id' | 'colonyName' | 'displayName' | 'nativeTokenAddress'>, events: Array<Pick<Event, 'id' | 'type'>> }
13771377
& PayoutsFragment
13781378
);
13791379

@@ -1892,7 +1892,7 @@ export type TaskQuery = { task: (
18921892
)>, colony: Pick<Colony, 'id' | 'colonyAddress' | 'colonyName' | 'avatarHash' | 'displayName' | 'nativeTokenAddress'>, creator: (
18931893
Pick<User, 'id'>
18941894
& { profile: Pick<UserProfile, 'avatarHash' | 'displayName' | 'username' | 'walletAddress'> }
1895-
), workInvites: Array<(
1895+
), events: Array<Pick<Event, 'id' | 'type'>>, workInvites: Array<(
18961896
Pick<User, 'id'>
18971897
& { profile: Pick<UserProfile, 'avatarHash' | 'displayName' | 'username' | 'walletAddress'> }
18981898
)>, workRequests: Array<(
@@ -1984,7 +1984,7 @@ export type UserTasksQuery = { user: (
19841984
& { assignedWorker: Maybe<(
19851985
Pick<User, 'id'>
19861986
& { profile: Pick<UserProfile, 'avatarHash'> }
1987-
)>, colony: Pick<Colony, 'id' | 'colonyName' | 'displayName' | 'nativeTokenAddress'> }
1987+
)>, colony: Pick<Colony, 'id' | 'colonyName' | 'displayName' | 'nativeTokenAddress'>, events: Array<Pick<Event, 'id' | 'type'>> }
19881988
& PayoutsFragment
19891989
)> }
19901990
) };
@@ -2100,7 +2100,7 @@ export type ColonyTasksQuery = { colony: (
21002100
& { assignedWorker: Maybe<(
21012101
Pick<User, 'id'>
21022102
& { profile: Pick<UserProfile, 'avatarHash'> }
2103-
)>, colony: Pick<Colony, 'id' | 'colonyName' | 'displayName' | 'nativeTokenAddress'> }
2103+
)>, colony: Pick<Colony, 'id' | 'colonyName' | 'displayName' | 'nativeTokenAddress'>, events: Array<Pick<Event, 'id' | 'type'>> }
21042104
& PayoutsFragment
21052105
)> }
21062106
) };
@@ -2294,6 +2294,10 @@ export const CreateTaskFieldsFragmentDoc = gql`
22942294
dueDate
22952295
ethDomainId
22962296
ethSkillId
2297+
events {
2298+
id
2299+
type
2300+
}
22972301
finalizedAt
22982302
title
22992303
workRequestAddresses
@@ -4487,6 +4491,10 @@ export const TaskDocument = gql`
44874491
ethDomainId
44884492
ethSkillId
44894493
ethPotId
4494+
events {
4495+
id
4496+
type
4497+
}
44904498
finalizedAt
44914499
title
44924500
workInvites {
@@ -4841,6 +4849,10 @@ export const UserTasksDocument = gql`
48414849
dueDate
48424850
ethDomainId
48434851
ethSkillId
4852+
events {
4853+
id
4854+
type
4855+
}
48444856
finalizedAt
48454857
title
48464858
workRequestAddresses
@@ -5316,6 +5328,10 @@ export const ColonyTasksDocument = gql`
53165328
dueDate
53175329
ethDomainId
53185330
ethSkillId
5331+
events {
5332+
id
5333+
type
5334+
}
53195335
finalizedAt
53205336
title
53215337
workRequestAddresses

src/data/queries.graphql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ query Task($id: String!) {
4040
ethDomainId
4141
ethSkillId
4242
ethPotId
43+
events {
44+
id
45+
type
46+
}
4347
finalizedAt
4448
title
4549
workInvites {
@@ -204,6 +208,10 @@ query UserTasks($address: String!) {
204208
dueDate
205209
ethDomainId
206210
ethSkillId
211+
events {
212+
id
213+
type
214+
}
207215
finalizedAt
208216
title
209217
workRequestAddresses
@@ -325,6 +333,10 @@ query ColonyTasks($address: String!) {
325333
dueDate
326334
ethDomainId
327335
ethSkillId
336+
events {
337+
id
338+
type
339+
}
328340
finalizedAt
329341
title
330342
workRequestAddresses

src/modules/dashboard/components/TaskList/TaskListItem.css

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ td.taskLoading {
1515
}
1616

1717
td.taskDetails {
18-
flex-wrap: wrap;
18+
flex-direction: column;
19+
flex-grow: 1;
20+
justify-content: center;
21+
align-items: flex-start;
1922
padding: cellPaddingVertical 0 cellPaddingVertical cellPaddingHorizontal;
20-
width: calc(85% - 74px);
2123
font-weight: var(--weight-semi);
2224
}
2325

26+
td.taskDetails > div {
27+
width: 100%;
28+
}
29+
2430
.taskDetailsTitle {
2531
composes: inlineEllipsis from '~styles/text.css';
2632
max-width: 80%;
@@ -32,18 +38,30 @@ td.taskDetails {
3238
color: var(--violet);
3339
}
3440

41+
.extraInfo {
42+
display: flex;
43+
align-items: baseline;
44+
}
45+
46+
.extraInfoItem + .extraInfoItem {
47+
margin-left: 20px;
48+
}
49+
3550
td.taskPayouts {
51+
flex-basis: 15%;
3652
justify-content: flex-end;
3753
padding: cellPaddingVertical 0;
38-
width: 15%;
3954
overflow: hidden;
4055
text-overflow: ellipsis;
4156
white-space: nowrap;
4257
}
4358

4459
td.userAvatar {
60+
flex-basis: 84px;
61+
62+
/* !important to override table styles */
63+
flex-grow: 0 !important;
4564
justify-content: center;
4665
padding: cellPaddingVertical cellPaddingHorizontal calc(cellPaddingVertical - 6px);
4766
height: 88px;
48-
width: 84px;
4967
}

src/modules/dashboard/components/TaskList/TaskListItem.css.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ export const taskLoading: string;
55
export const taskDetails: string;
66
export const taskDetailsTitle: string;
77
export const taskDetailsReputation: string;
8+
export const extraInfo: string;
9+
export const extraInfoItem: string;
810
export const taskPayouts: string;
911
export const userAvatar: string;

src/modules/dashboard/components/TaskList/TaskListItem.tsx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
2-
import React, { useCallback } from 'react';
2+
import React, { useCallback, useMemo } from 'react';
33
import { useHistory } from 'react-router-dom';
44
import BigNumber from 'bn.js';
55

6-
import { AnyTask, Payouts } from '~data/index';
7-
import { TableRow, TableCell } from '~core/Table';
6+
import { AnyTask, Payouts, EventType } from '~data/index';
7+
import { AbbreviatedNumeral } from '~core/Numeral';
88
import PayoutsList from '~core/PayoutsList';
9+
import { TableRow, TableCell } from '~core/Table';
910
import HookedUserAvatar from '~users/HookedUserAvatar';
1011

1112
import styles from './TaskListItem.css';
@@ -15,6 +16,13 @@ const MSG = defineMessages({
1516
id: 'dashboard.TaskList.TaskListItem.reputation',
1617
defaultMessage: '+{reputation} max rep',
1718
},
19+
titleCommentCount: {
20+
id: 'dashboard.TaskList.TaskListItem.titleCommentCount',
21+
defaultMessage: `{formattedCommentCount} {commentCount, plural,
22+
one {comment}
23+
other {comments}
24+
}`,
25+
},
1826
});
1927

2028
const UserAvatar = HookedUserAvatar();
@@ -27,12 +35,13 @@ const displayName = 'dashboard.TaskList.TaskListItem';
2735

2836
const TaskListItem = ({ task }: Props) => {
2937
const history = useHistory();
30-
const { formatMessage } = useIntl();
38+
const { formatMessage, formatNumber } = useIntl();
3139

3240
const defaultTitle = formatMessage({ id: 'task.untitled' });
3341
const {
3442
id: draftId,
3543
assignedWorkerAddress,
44+
events,
3645
payouts,
3746
title = defaultTitle,
3847
colony: { colonyName, nativeTokenAddress },
@@ -47,17 +56,44 @@ const TaskListItem = ({ task }: Props) => {
4756
});
4857
}, [colonyName, draftId, history]);
4958

59+
const commentCount = useMemo<number>(
60+
() => events.filter(({ type }) => type === EventType.TaskMessage).length,
61+
[events],
62+
);
63+
5064
return (
5165
<TableRow className={styles.globalLink} onClick={() => handleClick()}>
5266
<TableCell className={styles.taskDetails}>
53-
<p className={styles.taskDetailsTitle}>{title || defaultTitle}</p>
54-
{!!reputation && (
55-
<span className={styles.taskDetailsReputation}>
56-
<FormattedMessage
57-
{...MSG.reputation}
58-
values={{ reputation: reputation.toString() }}
59-
/>
60-
</span>
67+
<div>
68+
<p className={styles.taskDetailsTitle}>{title || defaultTitle}</p>
69+
</div>
70+
{!!(reputation || commentCount) && (
71+
<div className={styles.extraInfo}>
72+
{!!reputation && (
73+
<div className={styles.extraInfoItem}>
74+
<span className={styles.taskDetailsReputation}>
75+
<FormattedMessage
76+
{...MSG.reputation}
77+
values={{ reputation: reputation.toString() }}
78+
/>
79+
</span>
80+
</div>
81+
)}
82+
{commentCount && (
83+
<div className={styles.extraInfoItem}>
84+
<AbbreviatedNumeral
85+
formatOptions={{
86+
notation: 'compact',
87+
}}
88+
value={commentCount}
89+
title={formatMessage(MSG.titleCommentCount, {
90+
commentCount,
91+
formattedCommentCount: formatNumber(commentCount),
92+
})}
93+
/>
94+
</div>
95+
)}
96+
</div>
6197
)}
6298
</TableCell>
6399
<TableCell className={styles.taskPayouts}>

0 commit comments

Comments
 (0)