refactor: use renderDownloadsBadge helper in remaining classes (#7211)

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
Caleb Cartwright
2021-10-31 11:10:05 -05:00
committed by GitHub
parent c3d213c65c
commit 8fcde9de85
15 changed files with 149 additions and 233 deletions

View File

@@ -1,5 +1,4 @@
import { metric } from '../text-formatters.js'
import { downloadCount } from '../color-formatters.js'
import { renderDownloadsBadge } from '../downloads.js'
import { BaseOreService, documentation, keywords } from './ore-base.js'
export default class OreDownloads extends BaseOreService {
@@ -13,30 +12,17 @@ export default class OreDownloads extends BaseOreService {
static examples = [
{
title: 'Ore Downloads',
namedParams: {
pluginId: 'nucleus',
},
staticPreview: this.render({ downloads: 560891 }),
namedParams: { pluginId: 'nucleus' },
staticPreview: renderDownloadsBadge({ downloads: 560891 }),
documentation,
keywords,
},
]
static defaultBadgeData = {
label: 'downloads',
}
static render({ downloads }) {
return {
message: metric(downloads),
color: downloadCount(downloads),
}
}
static defaultBadgeData = { label: 'downloads' }
async handle({ pluginId }) {
const {
stats: { downloads },
} = await this.fetch({ pluginId })
return this.constructor.render({ downloads })
const { stats } = await this.fetch({ pluginId })
return renderDownloadsBadge({ downloads: stats.downloads })
}
}