|
1 | 1 | import React, { Component } from 'react';
|
| 2 | +import bytes from 'bytes'; |
2 | 3 | import algoliasearch from 'algoliasearch/lite';
|
3 | 4 |
|
4 | 5 | import Aside from './Aside';
|
@@ -55,7 +56,7 @@ class Details extends Component {
|
55 | 56 | };
|
56 | 57 | }
|
57 | 58 |
|
58 |
| - componentWillMount() { |
| 59 | + componentDidMount() { |
59 | 60 | index
|
60 | 61 | .getObject(this.props.objectID)
|
61 | 62 | .then(content => {
|
@@ -118,17 +119,37 @@ class Details extends Component {
|
118 | 119 | }
|
119 | 120 |
|
120 | 121 | this.getGithub({
|
121 |
| - url: `repos/${this.state.githubRepo.user}/${this.state.githubRepo |
122 |
| - .project}/stats/commit_activity`, |
| 122 | + url: `repos/${this.state.githubRepo.user}/${ |
| 123 | + this.state.githubRepo.project |
| 124 | + }/stats/commit_activity`, |
123 | 125 | state: 'activity',
|
124 | 126 | });
|
125 | 127 |
|
126 | 128 | this.getGithub({
|
127 |
| - url: `repos/${this.state.githubRepo.user}/${this.state.githubRepo |
128 |
| - .project}`, |
| 129 | + url: `repos/${this.state.githubRepo.user}/${ |
| 130 | + this.state.githubRepo.project |
| 131 | + }`, |
129 | 132 | state: 'github',
|
130 | 133 | });
|
131 | 134 | }
|
| 135 | + |
| 136 | + const { name, version } = this.state; |
| 137 | + |
| 138 | + get({ |
| 139 | + url: `https://bundlephobia.com/api/size?package=${name}@${version}`, |
| 140 | + type: 'json', |
| 141 | + headers: { |
| 142 | + 'X-Bundlephobia-User': 'yarn website', |
| 143 | + }, |
| 144 | + }).then(res => |
| 145 | + this.setState({ |
| 146 | + bundlesize: { |
| 147 | + href: `https://bundlephobia.com/result?p=${name}@${version}`, |
| 148 | + size: bytes(res.size), |
| 149 | + gzip: bytes(res.gzip), |
| 150 | + }, |
| 151 | + }) |
| 152 | + ); |
132 | 153 | }
|
133 | 154 |
|
134 | 155 | maybeRenderReadme() {
|
@@ -252,6 +273,7 @@ class Details extends Component {
|
252 | 273 | versions={this.state.versions}
|
253 | 274 | version={this.state.version}
|
254 | 275 | tags={this.state.tags}
|
| 276 | + bundlesize={this.state.bundlesize} |
255 | 277 | onOpenFileBrowser={this._openFileBrowser}
|
256 | 278 | />
|
257 | 279 | );
|
|
0 commit comments