webamp/src
2018-12-14 17:18:13 -08:00
..
redux Fix back button going to the home/search page 2018-12-08 15:46:39 -08:00
algolia.js Use algolia for search 2018-11-29 12:43:45 -08:00
App.css Black background 2018-12-03 20:55:02 -08:00
App.js Don't animate the overlay on page load 2018-12-02 20:20:30 -08:00
App.test.js Initial commit 2018-05-30 13:14:53 -07:00
constants.js Add the notion of a focused skin 2018-11-25 19:13:18 -08:00
Disposable.js Improve fade in of Webamp 2018-12-02 18:19:40 -08:00
FocusedSkin.js Start to add readme 2018-12-14 17:18:13 -08:00
Head.js Fix preview size 2018-12-02 18:53:55 -08:00
Header.js Zoom on hover 2018-12-02 22:04:49 -08:00
index.js Unregister service workers 2018-12-10 17:36:14 -08:00
logo.svg Initial commit 2018-05-30 13:14:53 -07:00
Overlay.js Don't animate the overlay on page load 2018-12-02 20:20:30 -08:00
Readme.js Start to add readme 2018-12-14 17:18:13 -08:00
registerServiceWorker.js Initial commit 2018-05-30 13:14:53 -07:00
Skin.js Pixelate skins if we ever show them full size or greater 2018-12-03 21:24:02 -08:00
skins.json Add filename 2018-11-26 19:32:41 -08:00
SkinTable.js Ensure horizontal scrollbar is not shown 2018-12-14 13:06:49 -08:00
utils.js Ensure horizontal scrollbar is not shown 2018-12-14 13:06:49 -08:00
WebampComponent.js Upgrade Webamp to support disposal 2018-12-03 17:37:40 -08:00

import React from "react";
import JSZip from "jszip";
import { switchMap } from "rxjs/operators";
import { from, empty } from "rxjs";
import Disposable from "./Disposable";

export default class Readme extends React.Component {
  constructor(props) {
    super(props);
    this._disposable = new Disposable();
    this.state = { readmeText: null };
  }

  componentDidMount() {
    this._fetchReadme();
  }

  componentDidUpdate(_, oldState) {
    if (this.state.skinUrl != oldState.skinUrl) {
      this._fetchReadme();
    }
  }

  componentWillUnmount() {
    this._disposable.dispose();
  }

  _fetchReadme() {
    this._disposable.add(
      from(fetch(this.props.skinUrl))
        .pipe(
          switchMap(response => response.blob()),
          switchMap(blob => JSZip.loadAsync(blob)),
          switchMap(zip => {
            const readme = zip.file("readme.txt");
            if (readme == null) {
              return empty();
            }
            return readme.async("string");
          })
        )
        .subscribe(text => {
          console.log(text);
          // this.setState({ readmeText: text });
        })
    );
  }

  render() {
    return (
      this.state.readmeText && (
        <pre
          style={{
            backgroundColor: "white",
            color: "black",
            position: "absolute",
            width: "500px",
            right: 0
          }}
        >
          {this.state.readmeText}
        </pre>
      )
    );
  }
}