npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-mlsdata

v0.5.11

Published

A simple declarative data component for React

Downloads

10

Readme

React MLSData Component

A react component to simplify the use of MLS Data from the MLSListings Odata Service within an Application.

Install

npm install --save react-mlsdata

Options

  • collection - the collection you want to access example www, vow, public etc...
  • resource - the resource you are trying to access examples property, agent, media etc..
  • token - the authorization token from the mlslistings identity provider
  • link - an odata link returned within the collection request

Media

If you are accessing an item in the media resource there is some options you can pass to optimize your request

  • ListingKeyNumeric - the integer value of the media resource for the listing you want to display it must be a number example ListingKeyNumeric = {this.ListingKey} || ListingKeyNumeric = {1234456}
  • MemberKeyNumeric - the integer value of the media resource for the agent you want to display it must be a number
  • MediaType = defaults to Photo. You can pass thumbnail if you want a smaller image for display in a list

Geography

To access geography information

Stats

If you are accessing statistics for a particular widget (Market Trends, Key PerformanceIndicators, Year to Year), you can pass the following options to optimize your request

  • collection - member, office, markettrends, KPI, year-to-year
  • select - Data to be selected for stats
  • filter - criteria for selection

Media Examples

Property Thumbnail

<MLSMedia MediaType="Thumbnail" ListingKeyNumeric={265403} limit="1" token={authtoken}>
  {({ loading, error, data }) => (
    <div>
      {error && 
        <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
      }
      {data &&
        <div>
          <Values data={data} />

          { !data.value.length &&
            <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
          }

          { data.value.length !== 0 &&
            <img src={data.value[0].MediaURL} alt="Thumbnail"/>
          }
        </div>
      }
    </div>
  )}
</MLSMedia>

Agent Photo

<MLSMedia MediaType="Thumbnail" MemberKeyNumeric={150591} limit="1" token={authtoken}>
  {({ loading, error, data }) => (
    <div>
      {error && 
        <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
      }
      {data &&
        <div>
          <Values data={data} />

          { !data.value.length &&
            <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
          }

          { data.value.length !== 0 &&
            <img src={data.value[0].MediaURL} alt="Thumbnail"/>
          }
        </div>
      }
    </div>
  )}
</MLSMedia>

MLSCount

A simplified interface for retrieving the count for any query. Simply pass the same query and filters to MLSCount component. It will in a declarative form return a count for the query which can the be used to display number of results or to build a pagination element

MLSCount Example


class Pagination extends Component {
  render() {
    console.log(this.props.data["@odata.count"]);
    return <div />;
  }
}

<MLSCount collection="Property" token={authtoken}>
  {({ data }) => (
    <div>
      { data &&
      <Pagination data={data} />
    }
    </div>
  )}
</MLSCount>

Usage

Import

import MLSData from 'react-mlsdata';

Basic

import React from "react";
import MLSData from "react-mlsdata";

class Values extends React.Component {
  render() {
    console.log(this.props.data);

    return <div />;
  }
}

class Listings extends React.Component {
  render() {
    const { listings } = this.props;

    var listingCollection = listings.map(listing => (
      <li key={Math.floor(Math.random() * Date.now()) + 1}>
        {listing.ListingId}
      </li>
    ));

    return <ul>{listingCollection}</ul>;
  }
}

class Count extends React.Component {
  render() {
    return (
      <h3>
        <strong>
          {this.props.data.length} Listings Retrieved
        </strong>
      </h3>
    );
  }
}

const tempToken = "your bearer token";

const App = () => (
  <div>
    <MLSData collection="Property" token={tempToken}>
      {({ loading, error, data }) => (
        <div>

          {loading && <h2>{`${loading}`}</h2>}

          {error && <h2>{error.message}</h2>}

          {data &&
            <div>

              <Values data={data} />
              <Count data={data.value}/>

              <Listings listings={data.value} />

            </div>
          }

        </div>
      )}

    </MLSData>
  </div>
);

export default App;

Fetch Callback

You can pass functions to the onChange prop to run as the fetch is being run. Loading states, Data, Response and etc will be available to a handler function.

class App extends Component {
  constructor() {
    super()
    this.handleResponse = this.handleResponse.bind(this)
  }

  handleResponse(response){
    console.info("info response:", response);
  }

  render() {
    return (
      <div>
        <MLSData collection="Property" token={authtoken} onChange={this.handleResponse} />
      </div>
    );
  }
}