Skip to content

Commit 456e361

Browse files
committed
Use named route to have a single place of truth
1 parent 128f77e commit 456e361

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

resources/js/components/Card.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
methods: {
6666
getTime() {
6767
Nova.request()
68-
.post('/nova-vendor/worldclock/timezones', {
68+
.post(this.card.refreshRoute, {
6969
timezones: this.card.timezones,
7070
timeFormat: this.card.timeFormat,
7171
nightHours: this.card.nightHours,

routes/api.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@
1414
|
1515
*/
1616

17-
// Route::get('/endpoint', function (Request $request) {
18-
// //
19-
// });
20-
21-
Route::post('/timezones', [WorldClockController::class, 'timezones']);
17+
Route::post('/timezones', [WorldClockController::class, 'timezones'])->name('nova.cards.worldClock.refresh');

src/WorldClock.php

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
namespace InteractionDesignFoundation\WorldClockCard;
44

5-
use Illuminate\Support\Carbon;
65
use Laravel\Nova\Card;
76

87
class WorldClock extends Card
98
{
109
/**
1110
* The width of the card (1/3, 1/2, or full).
12-
*
1311
* @var string
1412
*/
1513
public $width = '1/3';
@@ -27,12 +25,12 @@ public function __construct($component = null)
2725
$this->withMeta([
2826
'timezoneDescriptions' => [],
2927
'nightHours' => [19, 6],
28+
'refreshRoute' => route('nova.cards.worldClock.refresh')
3029
]);
3130
}
3231

3332
/**
3433
* Get the component name for the element.
35-
*
3634
* @return string
3735
*/
3836
public function component()
@@ -41,23 +39,21 @@ public function component()
4139
}
4240

4341
/**
44-
* @param array $timezones
42+
* @param list<string> $timezones
4543
* @return $this
4644
*/
47-
public function timezones(array $timezones)
45+
public function timezones(array $timezones): static
4846
{
4947
return $this->withMeta([
5048
'timezones' => $timezones,
5149
]);
5250
}
5351

5452
/**
55-
* @see https://www.php.net/manual/en/function.date.php
56-
*
57-
* @param string $timeFormat
53+
* @param string $timeFormat Time, compatiable with date()function, {@see https://www.php.net/manual/en/function.date.php}
5854
* @return $this
5955
*/
60-
public function timeFormat(string $timeFormat)
56+
public function timeFormat(string $timeFormat): static
6157
{
6258
return $this->withMeta([
6359
'timeFormat' => $timeFormat,
@@ -66,12 +62,11 @@ public function timeFormat(string $timeFormat)
6662

6763
/**
6864
* Specify hours range: when a night starts and ends
69-
*
7065
* @param int $nightStart
7166
* @param int $nightEnd
7267
* @return $this
7368
*/
74-
public function nightRange(int $nightStart, int $nightEnd)
69+
public function nightRange(int $nightStart, int $nightEnd): static
7570
{
7671
return $this->withMeta([
7772
'nightHours' => [$nightStart, $nightEnd],
@@ -84,20 +79,15 @@ public function nightRange(int $nightStart, int $nightEnd)
8479
* @param bool $hideContinents
8580
* @return $this
8681
*/
87-
public function hideContinents(bool $hideContinents = true)
82+
public function hideContinents(bool $hideContinents = true): static
8883
{
8984
return $this->withMeta([
9085
'hideContinents' => $hideContinents,
9186
]);
9287
}
9388

94-
/**
95-
* How often to fetch new data from server
96-
*
97-
* @param int $ms
98-
* @return $this
99-
*/
100-
public function updatePeriod(int $ms = 1000)
89+
/** How often to fetch new data from server */
90+
public function updatePeriod(int $ms = 1000): static
10191
{
10292
return $this->withMeta([
10393
'ms' => $ms,
@@ -106,11 +96,10 @@ public function updatePeriod(int $ms = 1000)
10696

10797
/**
10898
* Add text description to timezones. Format: ['tzName' => 'Text description']
109-
*
110-
* @param array $descriptions
99+
* @param array<string, string> $descriptions
111100
* @return $this
112101
*/
113-
public function timezoneDescriptions(array $descriptions)
102+
public function timezoneDescriptions(array $descriptions): static
114103
{
115104
return $this->withMeta([
116105
'timezoneDescriptions' => $descriptions,

0 commit comments

Comments
 (0)