Skip to content

Commit

Permalink
preload server list and bump to 20 results
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen committed Sep 20, 2023
1 parent c4b8d52 commit c1475e1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions app/Filament/Pages/Settings/GeneralPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,31 @@ public function form(Form $form): Form
Forms\Components\Select::make('speedtest_server')
->label('Speedtest servers')
->helperText('Leave empty to let the system pick the best server.')
->nullable()
->multiple()
->maxItems(10)
->preload()
->multiple()
->nullable()
->preload(false)
->searchable()
->options(function (): array {
$response = Http::get(
url: 'https://www.speedtest.net/api/js/servers',
query: [
'engine' => 'js',
'https_functional' => true,
'limit' => 20,
]
);

if ($response->failed()) {
return [
'' => 'There was an error retrieving Speedtest servers',
];
}

return $response->collect()->mapWithKeys(function (array $item, int $key) {
return [$item['id'] => $item['id'].': '.$item['name'].' ('.$item['sponsor'].')'];
})->toArray();
})
->getSearchResultsUsing(fn (string $search): array => $this->getServerSearchOptions($search))
->getOptionLabelsUsing(fn (array $values): array => $this->getServerLabels($values))
->columnSpan('full'),
Expand Down Expand Up @@ -119,7 +139,7 @@ protected function getServerSearchOptions(string $search): array
'engine' => 'js',
'search' => $search,
'https_functional' => true,
'limit' => 10,
'limit' => 20,
]
);

Expand Down

0 comments on commit c1475e1

Please sign in to comment.