Skip to content

Commit dc6e111

Browse files
committed
working on component
1 parent 57bb611 commit dc6e111

File tree

8 files changed

+41
-77
lines changed

8 files changed

+41
-77
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"extra": {
3939
"laravel": {
4040
"providers": [
41-
"Skydiver\\LaravelDashboardpackagist\\PackagistTileServiceProvider"
41+
"Skydiver\\LaravelDashboardPackagist\\PackagistTileServiceProvider"
4242
]
4343
}
4444
},

resources/views/header-type.blade.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

resources/views/npm-logo.blade.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

resources/views/package-tile.blade.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<x-dashboard-tile :position="$position">
2-
@includeWhen($showLogo, 'dashboard-npm-tile::npm-logo')
2+
@includeWhen($showLogo, 'dashboard-packagist-tile::packagist-logo')
33
<div class="relative h-full flex items-center">
44
<div class="w-full text-center text-gray-800">
5-
<div class="text-gray-600">{{ $package }}</div>
6-
<div class="text-xs text-gray-500" style="font-size: 0.5rem">
7-
@include('dashboard-npm-tile::header-type', ['type' => $type])
5+
<div class="text-gray-600" style="font-size: 0.7rem">{{ $package }}</div>
6+
<div class="my-3">
7+
<div class="text-3xl font-semibold">{{ number_format($packageInfo['package']['downloads']['total']) }}</div>
8+
<div class="text-xs text-gray-500" style="font-size: 0.6rem">Total</div>
89
</div>
9-
<div class="my-3 font-semibold text-3xl tracking-wide leading-none">{{ number_format($packageInfo['downloads']) }}</div>
10-
<div class="text-xs text-gray-600" style="font-size: 0.6rem">
11-
@if ($packageInfo['start'] !== $packageInfo['end'])
12-
<span>{{ $packageInfo['start'] }} ~ {{ $packageInfo['end'] }}</span>
13-
@else
14-
<span>{{ $packageInfo['start'] }}</span>
15-
@endif
10+
<div class="flex flex-row text-xs text-gray-600" style="font-size: 0.6rem">
11+
@foreach (['monthly', 'daily'] as $value)
12+
<div class="w-1/2 flex flex-col">
13+
<div class="flex justify-center font-semibold">{{ number_format($packageInfo['package']['downloads'][$value]) }}</div>
14+
<div class="font-semibold text-gray-500">{{ ucfirst($value) }}</div>
15+
</div>
16+
@endforeach
1617
</div>
1718
</div>
1819
<div class="absolute bottom-0 right-0 text-xs text-gray-500 text-right" style="font-size: 0.5rem">Updated at: {{ $packageInfo['updated_at'] }}</div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="absolute top-0 right-0 mt-4 mr-4">
2+
<svg class="w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 764.05 629.67">
3+
<g>
4+
<path d="M76.62,357.52v68.42a4.58,4.58,0,0,1-6.73,4L5.45,395.78a4.58,4.58,0,0,1,0-8.09l64.44-34.21a4.58,4.58,0,0,1,6.73,4Z" fill="#e1743f" stroke="#e1743f" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
5+
<path d="M488,596.62V355.35l-5.32-1.28L439,374.3v230h41.3a7.67,7.67,0,0,0,7.7-7.64S488,596.63,488,596.62Z" fill="#c25934" stroke="#c25934" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
6+
<path d="M761,332c.27.8-32.74-60.77-32.74-60.77L683,322.89Z" fill="#e1743f" stroke="#e1743f" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
7+
<path d="M251.59,104.92h-38a11.72,11.72,0,0,0-6.43,1.92L75.87,193a11.72,11.72,0,0,0-5.29,9.79V614.93A11.72,11.72,0,0,0,82.3,626.65h78.2a11.72,11.72,0,0,0,8.28-3.43L250,542,87.16,296.46a11.72,11.72,0,0,1,3.3-16.24q.37-.24.75-.46l101.15-56.5a11.72,11.72,0,0,0,6-10.23V168a11.72,11.72,0,0,1,3-7.88Z" fill="#c25934" stroke="#c25934" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
8+
<path d="M431.85,626.65H318.32a7.67,7.67,0,0,1-6.32-3.33L84.94,292.86a7.67,7.67,0,0,1,2-10.66q.27-.18.55-.34l110.84-61.91V365.6a7.67,7.67,0,0,0,7.64,7.67l233,1V619.51a7.14,7.14,0,0,1-7.14,7.14Z" fill="#e1743f" stroke="#e1743f" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
9+
<path d="M336.35,79.33a3,3,0,0,1-3-3V6a3,3,0,0,1,4.45-2.66l131,70.27a3,3,0,0,1-1.43,5.68Z" fill="#c25934"/>
10+
<path d="M336.35,6l131,70.27h-131V6m0-6a6,6,0,0,0-6,6V76.31a6,6,0,0,0,6,6h131A6,6,0,0,0,470.17,71L339.2.72A6,6,0,0,0,336.35,0Z" fill="#c25934"/><polygon points="728.34 271.11 631.18 259.04 581.6 306.21 583.8 318.93 627.18 386.74 728.34 271.11" fill="#c25934" stroke="#c25934" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
11+
<path d="M626.39,387.08,583.8,318.93l-30-173.58a14.08,14.08,0,0,0-5.13-8.64L470.94,75.1H321.41a12.9,12.9,0,0,0-5.24,1.11l-64.58,28.7L439,374.3l43.66-20.23Z" fill="#e1743f" stroke="#e1743f" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
12+
<path d="M198.36,365.6V168.5a13,13,0,0,1,3.38-8.74l49.86-54.85L439,374.3l-233-1a7.67,7.67,0,0,1-7.64-7.7Z" fill="#e68c59" stroke="#e68c59" stroke-linecap="round" stroke-linejoin="round" stroke-width="6.04"/>
13+
</g>
14+
</svg>
15+
</div>

src/BaseComponent.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Skydiver\LaravelDashboardNpm;
3+
namespace Skydiver\LaravelDashboardPackagist;
44

55
use Carbon\Carbon;
66
use Livewire\Component;
@@ -9,36 +9,30 @@
99

1010
class BaseComponent extends Component
1111
{
12-
const API_BASE_URL = 'https://api.npmjs.org';
12+
const API_BASE_URL = 'https://packagist.org';
1313
const DEFAULT_CACHE_TIMEOUT = 600;
14-
const DEFAULT_TYPE = 'last-month';
15-
const VALID_TYPES = [
16-
'last-day',
17-
'last-week',
18-
'last-month',
19-
];
20-
21-
public function fetchPackageDownloads(string $package = null) :array
14+
15+
public function fetchPackageInfo(string $package = null) :array
2216
{
2317
$package = $package ?? $this->package;
24-
$type = in_array($this->type, self::VALID_TYPES) ? $this->type : self::DEFAULT_TYPE;
2518

26-
$cacheKey = sprintf('dashboard-npm-tile-%s-%s', $this->type, $package);
19+
$cacheKey = sprintf('dashboard-packagist-tile-%s', $package);
2720
$cacheTimeout = $this->cacheTimeout ?? self::DEFAULT_CACHE_TIMEOUT;
2821

2922
if ($this->forceRefresh === true) {
3023
Cache::forget($cacheKey);
3124
}
3225

33-
$downloads = Cache::remember($cacheKey, $cacheTimeout, function () use ($type, $package) {
34-
$apiUrl = sprintf('%s/downloads/point/%s/%s', self::API_BASE_URL, $type, $package);
26+
$packageInfo = Cache::remember($cacheKey, $cacheTimeout, function () use ($package) {
27+
$apiUrl = sprintf('%s/packages/%s.json', self::API_BASE_URL, $package);
3528

3629
$response = Http::get($apiUrl);
3730
$packageInfo = $response->json();
31+
3832
$packageInfo['updated_at'] = Carbon::now()->toDateTimeString();
3933
return $packageInfo;
4034
});
4135

42-
return $downloads;
36+
return $packageInfo;
4337
}
4438
}

src/MyStore.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/PackagistPackageTileComponent.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class PackagistPackageTileComponent extends BaseComponent
66
{
77
public $position;
88
public $package;
9-
public $type;
109
public $cacheTimeout;
1110
public $forceRefresh;
1211
public $showLogo;
@@ -16,19 +15,20 @@ class PackagistPackageTileComponent extends BaseComponent
1615
public function mount(
1716
string $position,
1817
string $package,
19-
string $type = null,
2018
int $cacheTimeout = null,
2119
bool $forceRefresh = false,
2220
bool $showLogo = true
2321
) {
2422
$this->position = $position;
2523
$this->package = $package;
26-
$this->type = $type;
2724
$this->cacheTimeout = $cacheTimeout;
2825
$this->forceRefresh = $forceRefresh;
2926
$this->showLogo = $showLogo;
3027

31-
$this->packageInfo = $this->fetchPackageDownloads();
28+
$this->packageInfo = $this->fetchPackageInfo();
29+
30+
dd($this->packageInfo);
31+
3232
}
3333

3434
public function render()

0 commit comments

Comments
 (0)