Skip to content

Commit 4bf3960

Browse files
committed
Use client resolver for task comment count
1 parent 0e0e89f commit 4bf3960

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

src/data/fragments.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fragment CreateTaskFields on Task {
4444
nativeTokenAddress
4545
}
4646
colonyAddress
47+
commentCount @client
4748
createdAt
4849
creatorAddress
4950
dueDate

src/data/generated.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ export type Task = {
12251225
events: Array<Event>,
12261226
payouts: Array<TaskPayout>,
12271227
txHash?: Maybe<Scalars['String']>,
1228+
commentCount: Scalars['Int'],
12281229
finalizedPayment?: Maybe<TaskFinalizedPayment>,
12291230
};
12301231

@@ -1369,7 +1370,7 @@ export type PersistentTaskPayoutsFragment = { payouts: Array<(
13691370
)> };
13701371

13711372
export type CreateTaskFieldsFragment = (
1372-
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'createdAt' | 'creatorAddress' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'finalizedAt' | 'title' | 'workRequestAddresses' | 'txHash'>
1373+
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'commentCount' | 'createdAt' | 'creatorAddress' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'finalizedAt' | 'title' | 'workRequestAddresses' | 'txHash'>
13731374
& { assignedWorker: Maybe<(
13741375
Pick<User, 'id'>
13751376
& { profile: Pick<UserProfile, 'avatarHash'> }
@@ -1885,7 +1886,7 @@ export type TaskQueryVariables = {
18851886

18861887

18871888
export type TaskQuery = { task: (
1888-
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'createdAt' | 'creatorAddress' | 'description' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'ethPotId' | 'finalizedAt' | 'title' | 'workInviteAddresses' | 'workRequestAddresses' | 'txHash'>
1889+
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'commentCount' | 'createdAt' | 'creatorAddress' | 'description' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'ethPotId' | 'finalizedAt' | 'title' | 'workInviteAddresses' | 'workRequestAddresses' | 'txHash'>
18891890
& { assignedWorker: Maybe<(
18901891
Pick<User, 'id'>
18911892
& { profile: Pick<UserProfile, 'avatarHash' | 'displayName' | 'username' | 'walletAddress'> }
@@ -1980,7 +1981,7 @@ export type UserTasksQueryVariables = {
19801981
export type UserTasksQuery = { user: (
19811982
Pick<User, 'id'>
19821983
& { tasks: Array<(
1983-
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'createdAt' | 'creatorAddress' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'finalizedAt' | 'title' | 'workRequestAddresses' | 'txHash'>
1984+
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'commentCount' | 'createdAt' | 'creatorAddress' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'finalizedAt' | 'title' | 'workRequestAddresses' | 'txHash'>
19841985
& { assignedWorker: Maybe<(
19851986
Pick<User, 'id'>
19861987
& { profile: Pick<UserProfile, 'avatarHash'> }
@@ -2096,7 +2097,7 @@ export type ColonyTasksQueryVariables = {
20962097
export type ColonyTasksQuery = { colony: (
20972098
Pick<Colony, 'id'>
20982099
& { tasks: Array<(
2099-
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'createdAt' | 'creatorAddress' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'finalizedAt' | 'title' | 'workRequestAddresses' | 'txHash'>
2100+
Pick<Task, 'id' | 'assignedWorkerAddress' | 'cancelledAt' | 'colonyAddress' | 'commentCount' | 'createdAt' | 'creatorAddress' | 'dueDate' | 'ethDomainId' | 'ethSkillId' | 'finalizedAt' | 'title' | 'workRequestAddresses' | 'txHash'>
21002101
& { assignedWorker: Maybe<(
21012102
Pick<User, 'id'>
21022103
& { profile: Pick<UserProfile, 'avatarHash'> }
@@ -2289,6 +2290,7 @@ export const CreateTaskFieldsFragmentDoc = gql`
22892290
nativeTokenAddress
22902291
}
22912292
colonyAddress
2293+
commentCount @client
22922294
createdAt
22932295
creatorAddress
22942296
dueDate
@@ -4475,6 +4477,7 @@ export const TaskDocument = gql`
44754477
nativeTokenAddress
44764478
}
44774479
colonyAddress
4480+
commentCount @client
44784481
createdAt
44794482
creator {
44804483
id
@@ -4844,6 +4847,7 @@ export const UserTasksDocument = gql`
48444847
nativeTokenAddress
48454848
}
48464849
colonyAddress
4850+
commentCount @client
48474851
createdAt
48484852
creatorAddress
48494853
dueDate
@@ -5323,6 +5327,7 @@ export const ColonyTasksDocument = gql`
53235327
nativeTokenAddress
53245328
}
53255329
colonyAddress
5330+
commentCount @client
53265331
createdAt
53275332
creatorAddress
53285333
dueDate

src/data/queries.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ query Task($id: String!) {
2424
nativeTokenAddress
2525
}
2626
colonyAddress
27+
commentCount @client
2728
createdAt
2829
creator {
2930
id
@@ -203,6 +204,7 @@ query UserTasks($address: String!) {
203204
nativeTokenAddress
204205
}
205206
colonyAddress
207+
commentCount @client
206208
createdAt
207209
creatorAddress
208210
dueDate
@@ -328,6 +330,7 @@ query ColonyTasks($address: String!) {
328330
nativeTokenAddress
329331
}
330332
colonyAddress
333+
commentCount @client
331334
createdAt
332335
creatorAddress
333336
dueDate

src/data/task.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { ContextType } from '~context/index';
55
import { createAddress } from '~utils/web3';
66

77
import { getToken } from './token';
8+
import { EventType } from './index';
89

910
export const taskResolvers = ({ colonyManager }: ContextType): Resolvers => ({
1011
Task: {
12+
commentCount({ events }): number {
13+
return events.filter(({ type }) => type === EventType.TaskMessage).length;
14+
},
1115
async finalizedPayment({ colonyAddress, finalizedAt, ethPotId }) {
1216
if (!finalizedAt || !ethPotId) return null;
1317
const colonyClient = await colonyManager.getColonyClient(colonyAddress);

src/data/typeDefs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default gql`
5454
}
5555
5656
extend type Task {
57+
commentCount: Int!
5758
finalizedPayment: TaskFinalizedPayment
5859
}
5960

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

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

66
import Icon from '~core/Icon';
77
import { AbbreviatedNumeral } from '~core/Numeral';
88
import PayoutsList from '~core/PayoutsList';
99
import { TableRow, TableCell } from '~core/Table';
10-
import { AnyTask, Payouts, EventType } from '~data/index';
10+
import { AnyTask, Payouts } from '~data/index';
1111
import HookedUserAvatar from '~users/HookedUserAvatar';
1212

1313
import styles from './TaskListItem.css';
@@ -42,7 +42,7 @@ const TaskListItem = ({ task }: Props) => {
4242
const {
4343
id: draftId,
4444
assignedWorkerAddress,
45-
events,
45+
commentCount,
4646
payouts,
4747
title = defaultTitle,
4848
colony: { colonyName, nativeTokenAddress },
@@ -57,11 +57,6 @@ const TaskListItem = ({ task }: Props) => {
5757
});
5858
}, [colonyName, draftId, history]);
5959

60-
const commentCount = useMemo<number>(
61-
() => events.filter(({ type }) => type === EventType.TaskMessage).length,
62-
[events],
63-
);
64-
6560
return (
6661
<TableRow className={styles.globalLink} onClick={() => handleClick()}>
6762
<TableCell className={styles.taskDetails}>

0 commit comments

Comments
 (0)