Skip to content

Commit acfa86c

Browse files
committed
update on searching for community stores
1 parent b482966 commit acfa86c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

app/Filament/Forms/CommunityStoresForm.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public static function configure()
6363
->options(array_combine(range('A', 'Z'), range('A', 'Z')))
6464
->default(-1)
6565
->inline()
66-
->required()
6766
->reactive(),
6867

6968
// Visual store selection using image checkboxes

app/Helpers/StoreHelper.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ public static function search_community_stores($search, $letter): array
1212
{
1313

1414
// validate that search is not empty and only english alphabetic characters
15-
if ((blank($search) || ! preg_match('/^[a-zA-Z]+$/', $search)) && blank($letter)) return [];
15+
if (blank($search) && (blank($letter) || $letter == "-1")) return [];
1616

17-
$to_search = strtolower($search ?? $letter);
17+
if (strlen($search) > 1)
18+
$letter = substr($search, 0, 1);
1819

19-
if ($to_search == '-1') return [];
2020

2121
// check the github repo for the first letter of the search
2222
$github_link = config('settings.github_community_store_repo');
2323

24-
$stores_available = Http::get($github_link.$to_search)
24+
$stores_available = Http::get($github_link. strtolower($letter))
2525
->json();
2626

2727
if (array_key_exists('message', $stores_available)) {
@@ -34,6 +34,11 @@ public static function search_community_stores($search, $letter): array
3434
return [];
3535
}
3636

37+
// filter store by search
38+
if (strlen($search) > 1) {
39+
$stores_available = array_filter($stores_available, fn ($store) => Str::contains($store['name'], $search, true));
40+
}
41+
3742
$formatted_stores = array_map(fn ($store) => [
3843
'name' => $store['name'],
3944
'image' => config('settings.github_community_store_gist_base').$store['path'].'/logo.png',

0 commit comments

Comments
 (0)