Skip to content

Commit 6d5ecdd

Browse files
authored
[Feature] Preload server list and bump to 20 results (alexjustesen#796)
1 parent c4b8d52 commit 6d5ecdd

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

app/Filament/Pages/Settings/GeneralPage.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,31 @@ public function form(Form $form): Form
8181
Forms\Components\Select::make('speedtest_server')
8282
->label('Speedtest servers')
8383
->helperText('Leave empty to let the system pick the best server.')
84-
->nullable()
85-
->multiple()
8684
->maxItems(10)
87-
->preload()
85+
->multiple()
86+
->nullable()
87+
->preload(false)
8888
->searchable()
89+
->options(function (): array {
90+
$response = Http::get(
91+
url: 'https://www.speedtest.net/api/js/servers',
92+
query: [
93+
'engine' => 'js',
94+
'https_functional' => true,
95+
'limit' => 20,
96+
]
97+
);
98+
99+
if ($response->failed()) {
100+
return [
101+
'' => 'There was an error retrieving Speedtest servers',
102+
];
103+
}
104+
105+
return $response->collect()->mapWithKeys(function (array $item, int $key) {
106+
return [$item['id'] => $item['id'].': '.$item['name'].' ('.$item['sponsor'].')'];
107+
})->toArray();
108+
})
89109
->getSearchResultsUsing(fn (string $search): array => $this->getServerSearchOptions($search))
90110
->getOptionLabelsUsing(fn (array $values): array => $this->getServerLabels($values))
91111
->columnSpan('full'),
@@ -119,7 +139,7 @@ protected function getServerSearchOptions(string $search): array
119139
'engine' => 'js',
120140
'search' => $search,
121141
'https_functional' => true,
122-
'limit' => 10,
142+
'limit' => 20,
123143
]
124144
);
125145

0 commit comments

Comments
 (0)