Home Manual Reference Source
import Comments from '@pageproof/sdk/src/api/Comments.js'
public class | source

Comments

Extends:

API → Comments

Method Summary

Public Methods
public

Loads a proof's comments.

Inherited Summary

From class API
public

Public Methods

public load(options: object | string): Promise<Array<Comment>> source

Loads a proof's comments.

Params:

NameTypeAttributeDescription
options object | string

The options or proof id

options.proofId string

The proof id

options.pageNumber number
  • optional

The page number (if you only need a single page's comments)

options.sinceDate Date
  • optional

Return comments which have only been created since this date

options.async boolean
  • optional
  • default: false

Whether to decrypt the comments separately (must provide the onDecryptComment option)

options.decrypt boolean
  • optional
  • default: true

Whether to decrypt the comments at all. Comment text will be unreadable if this option is disabled. The promise will immediately resolve once the comment metadata has been obtained.

options.onDecryptComment function
  • optional

Invoked every time a comment has finished decrypting

Return:

Promise<Array<Comment>>

Example:

Basic usage
const comments = await client.comments.load('PO1CD95SOTBJQ99A');
console.log(comments);
Load all of the comments on page 7
const comments = await client.comments.load({
  proofId: 'PO1CD95SOTBJQ99A',
  pageNumber: 7,
});
console.log(comments); // [Comment, Comment, Comment, ...]
Async decryption (with React)
class CommentsList extends React.Component {
  state = {
    comments: [],
  };
  componentWillMount() {
    const comments = await client.comments.load({
      proofId: 'PO1CD95SOTBJQ99A',
      async: true,
      onDecryptComment(comment) {
        console.log(`Comment ${comment.id} has been decrypted, updating bindings...`);
        this.forceUpdate(); // tell React to re-render
      }
    });
    this.setState({ comments });
  }
  render() {
    return (
      <ul>
        {this.state.comments.map(comment => (
          <li key={comment.id}>
            <strong>{comment.user.email}</strong><br />
            {comment.html
              ? <div dangerouslySetInnerHTML={{__html: comment.html}} />
              : <div>Loading...</div>}
          </li>
        ))}
      </ul>
    );
  }
}