Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app"></div>

<link href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css" rel="stylesheet">

              
            
!

CSS

              
                html, body, #app {
  height: 100vh;
}

.loader {
    border: 3px solid #f3f3f3; /* Light grey */
    border-top: 3px solid #3498db; /* Blue */
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

              
            
!

JS

              
                const { createStore, combineReducers, applyMiddleware } = window.Redux; //  from 'redux'
const thunk = window.ReduxThunk.default; // from 'redux-thunk';
const { Provider, connect } = window.ReactRedux; // from 'react-redux';
const { apiMiddleware } = window.ReduxApiMiddleware; // from 'redux-api-middleware';
const api = window.ReduxCachedApiMiddleware; // from 'redux-cached-api-middleware';

// Setup the redux store
const store = createStore(
  combineReducers({
    [api.constants.NAME]: api.reducer,
  }),
  applyMiddleware(thunk, apiMiddleware)
);

// Component that fetches GitHub users repositories
class RepositorySearchApp extends React.Component {
  state = {
    userName: 'buz-zard'
  }

  componentDidMount() {
    const { userName } = this.state;
    this.props.fetchUserData(userName);
  }
        
  handleSubmit = (event) => {
    event.preventDefault();
    const userName = event.target.text.value;
    this.setState({ userName });
    this.props.fetchUserData(userName);
  }

  render() {
    const { getResult } = this.props;
    const { userName } = this.state;
    
    return (
      <div className='bg-indigo w-full h-full overflow-y-scroll'>
        <div className="w-1/3 mx-auto my-8">
         <form onSubmit={this.handleSubmit} className='my-6 p-2 bg-white rounded'>
            <label htmlFor='username-input'>Type in GutHub user name and press ENTER</label>
            <input
              id='username-input'
              name="text"
              className="w-full p-2 mt-1 border-gray border-2 rounded"
              defaultValue={userName}
              type="text"
            />
          </form>
          {userName && <RepositoryList data={getResult(userName)} />}
        </div>
      </div>
    );
  }
}

// HOC that helps fetch, cache and retrieve API response from redux state
const enhance = connect(
  state => ({ getResult: userName => api.selectors.getResult(state, userName), }),
  dispatch => ({
    fetchUserData(userName) {
      return dispatch(
        api.actions.invoke({
          method: 'GET',
          headers: { Accept: 'application/json' },
          endpoint: `https://api.github.com/users/${userName}/repos`,
          cache: {
            key: userName,
            strategy: api.cache
              .get(api.constants.CACHE_TYPES.TTL_SUCCESS)
              .buildStrategy({ ttl: 10 * 60 * 1000 }), // 10 minutes
          },
        })
      );
    },
  })
);

const CachedRepositorySearchApp = enhance(RepositorySearchApp);

function RepositoryList({ data }) {
  console.log(data);
  if (!data) return null;
  if (data.fetching)  {
    return (
      <div className='bg-white rounded px-2 pt-2 pb-5'>
        Fetching <div className='loader mx-auto' />
      </div>
    );
  }
  if (data.error) {
    return (
      <div className='bg-white rounded p-2'>
        <h3>Error occurred</h3>
        <div style={{ whiteSpace: 'pre' }}>{JSON.stringify(data.errorPayload, null, 2)}</div>
      </div>
    );
  }
  if (data.successPayload) {
    return (
      <div className='bg-white rounded p-2'>
        {!data.successPayload.length && 'No repositories'}
        {data.successPayload.map((item, index) => <RepositoryItem item={item} isFirst={index === 0} />)}
      </div>
    );
  }
  return null;
}

function RepositoryItem ({ item, isFirst }) {
  return (
    <div className={"border border-grey p-2 " + (isFirst ? "" : "border-t-0")}>
      <div className="flex justify-between">
        <h5 className="mb-1">{item.name}</h5>
        <small>{new Date(Date.parse(item.created_at)).toLocaleDateString()}</small>
      </div>
      <p className="mb-1">{item.description}</p>
      <small>{item.html_url}</small>
    </div>
  )
}


//Render the app to the DOM
ReactDOM.render(
  <Provider store={store}>
    <CachedRepositorySearchApp />
  </Provider>,
  document.getElementById('app')
);
              
            
!
999px

Console