Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@peerboard/react-components

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@peerboard/react-components

peerboard.io react components

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
Source

Usage

You can find detailed tutorial at https://community.peerboard.io/post/794391758

yarn add @peerboard/react-comopnents 

or

npm install @peerboard/react-comopnents 
import { PeerboardForum } from '@peerboard/react-components';

// ...

<PeerboardForum
  style={{
     visibility: this.state.forumReady ? 'visible' : 'hidden',
     minHeight: 'calc(100vh - 10px)',
  }}
  boardId={432432432} // Your Board id from settings
  prefix='community' // Relative path at which the forum is rendered yourcustomdomain.com/community
  jwtToken={'...'} // Your integration bearer token from backend
  hideMenu={false} // Whether to hide standard menu or not
  onLoadFailed={() => {
    // Show error
  }}
  onLoadSuccess={() => {
    // Show forum. Note that in order to initialize forum should be rendered with 'display: none' for example. 
  }}
  onTitleChanged={title => window.document.title = "Forum: " + title} // Change your title accordingly
  onPathChanged={path => {
    // Browser counts iframe state changes.
    history.replaceState(null, '', path) // Update address bar. Provided prefix included.
  }}
/>

Real world mvp example of page component

class Forum extends React.Component {
  constructor(props) {
    super(props);
    this.jwtToken = null;
    this.prefix = 'community'; // assuming that this page rendered at yourcustomdomain.com/community
    this.state = {
      authReady: false,
      forumReady: false,
      error: null,
    };
  }

  componentDidMount() {
    const redirect = (document.location.pathname || "/").replace(`/${this.prefix}`, '');
    http.post('/generate-bearer-token', {
      redirect, // Pass requested sub path here
    }).then((result) => {
      this.jwtToken = result.token;
      this.setState({
        authReady: true, // Now we can render the forum component
      });
    });
  }

  renderForum() {
    return <div>
      {!(this.state.authReady && this.state.forumReady) && 'Loading forum... You can place your spinner here.'}
      {this.state.authReady && (
        <PeerboardForum
          style={{
             visibility: this.state.forumReady ? 'visible' : 'hidden',
             minHeight: 'calc(100vh - 10px)',
           }}
          boardId={1024681946} // Replace with your Board id
          prefix={this.prefix}
          jwtToken={this.jwtToken}
          hideMenu={false}
          onLoadFailed={() => {
            this.setState({
              error: "Failed to load forum",
            });
          }}
          onLoadSuccess={() => {
            this.setState({
              forumReady: true,
            });
          }}
          onTitleChanged={title => window.document.title = "Forum: " + title}
          onPathChanged={location => window.history.replaceState(null, '', location)}
        />
      )}
    </div>
  }
  render() {
    return (
      <div className="container">
        {this.state.error ? (this.state.error) : (this.renderForum())}
      </div>
    );
  }
}

Keywords

FAQs

Package last updated on 04 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc