Build thread previews with detailed data about all threads in a location
import { thread } from '@cord-sdk/react';
const { threads, loading, hasMore, fetchMore } = thread.useLocationData({
page: 'document_details',
});
return (
<div>
{threads.map((threadSummary) => (
<div key={threadSummary.id}>
Thread ID {threadSummary.id} has {threadSummary.total} messages!
</div>
))}
{loading ? (
<div>Loading...</div>
) : hasMore ? (
<div onClick={() => fetchMore(10)}>Fetch 10 more</div>
) : null}
</div>
);
The API provides an object which has the following fields:
true
, Cord is in the process of fetching additional data from its backend. Once the fetch is complete, the additional items will be appended to the result list, and loading
will become false
.fetchMore
will start a fetch and cause loading
to become true
.loading
will become true
while the data is fetched. Once the fetch is complete, the additional items will be appended to the result list, and loading
will return to false
.true
, then the list of results is incomplete, and you need to call fetchMore
to continue paginating through them. Once this becomes false
, all results are available, and calls to fetchMore
won't do anything.fetchMore
will cause further thread summaries to be appended to the array.This is an array of objects, each of which has the following fields:
null
if the thread is empty.This is an object with the following fields:
action_message
messages; other messages show the avatar of the author. If an action_message
does not have an icon set, no icon is shown.user_message
is a message that the author sent. An action_message
is a message about something that happened, such as the thread being resolved. The default value is user_message
.This is an array of objects, each of which has the following fields:
null
if the thread is empty.This is an object with the following fields:
action_message
messages; other messages show the avatar of the author. If an action_message
does not have an icon set, no icon is shown.user_message
is a message that the author sent. An action_message
is a message about something that happened, such as the thread being resolved. The default value is user_message
.This is an array of objects, each of which has the following fields:
resolvedTimestamp
is null.null
if this thread is not resolved.This is an array of objects, each of which has the following fields:
null
if this participant has never viewed this thread.This is an object with the following fields:
sortDirection
, it determines which threads are "first".first_message_timestamp
: sort threads by the timestamp of the first message in the thread. In other words, threads will be sorted based on how recently they were created.most_recent_message_timestamp
: sort threads by the timestamp of the most recent message in the thread. In other words, threads will be sorted based on how recently they were responded to.first_message_timestamp
.sortBy
sorts. Combined with sortBy
, it determines which threads are "first".ascending
: sort older threads in front of newer threads.descending
: sort newer threads in front of older threads.descending
(since people usually care about the most recent things).true
, perform partial matching on the specified location. If false
, fetch information for only exactly the location specified.false
.This is an object with the following fields:
metadata
entry should be an object representing the metadata key/value to filter on. For example, to show only threads with the metadata key of "category"
set to "sales"
, set the filter to { metadata: { category: "sales" } }
.resolved
, only resolved threads will be returned. If set to unresolved
, only unresolved threads will be returned. If set to any
, both resolved and unresolved threads will be returned.unresolved
.