(options: UseMarketPackagesOptions = {})
| 33 | * Composable for market packages filtering and search functionality |
| 34 | */ |
| 35 | export function useMarketPackages(options: UseMarketPackagesOptions = {}) { |
| 36 | const packages = ref<QuickStartPackages[]>([]); |
| 37 | const { onlyDockerTemplate = false } = options; |
| 38 | |
| 39 | // Search form state |
| 40 | const searchForm = reactive<SearchForm>({ |
| 41 | language: getCurrentLang(), |
| 42 | category: SEARCH_ALL_KEY, |
| 43 | gameType: SEARCH_ALL_KEY, |
| 44 | platform: SEARCH_ALL_KEY, |
| 45 | keyword: "", |
| 46 | isSupportDocker: false, |
| 47 | system: "linux" |
| 48 | }); |
| 49 | |
| 50 | // Generic filter condition checker function |
| 51 | const matchesFilterCondition = ( |
| 52 | item: QuickStartPackages, |
| 53 | field: keyof QuickStartPackages, |
| 54 | filterValue: string |
| 55 | ): boolean => { |
| 56 | return ( |
| 57 | filterValue === SEARCH_ALL_KEY || |
| 58 | item[field] === filterValue || |
| 59 | item[field] === SEARCH_ALL_KEY |
| 60 | ); |
| 61 | }; |
| 62 | |
| 63 | // Specific filter functions |
| 64 | const matchesLanguageFilter = (item: QuickStartPackages): boolean => { |
| 65 | return item.language === searchForm.language || item.language === "en_us"; |
| 66 | }; |
| 67 | |
| 68 | const matchesGameTypeFilter = (item: QuickStartPackages): boolean => { |
| 69 | return matchesFilterCondition(item, "gameType", searchForm.gameType); |
| 70 | }; |
| 71 | |
| 72 | const matchesCategoryFilter = (item: QuickStartPackages): boolean => { |
| 73 | return matchesFilterCondition(item, "category", searchForm.category); |
| 74 | }; |
| 75 | |
| 76 | const matchesPlatformFilter = (item: QuickStartPackages): boolean => { |
| 77 | console.debug("matchesFilterCondition", item.platform, "platform", searchForm.platform); |
| 78 | return matchesFilterCondition(item, "platform", searchForm.platform); |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * Checks if item matches the keyword filter (fuzzy match on title and description). |
| 83 | * Empty keyword matches all items. Matching is case-insensitive. |
| 84 | */ |
| 85 | const matchesKeywordFilter = (item: QuickStartPackages): boolean => { |
| 86 | const k = searchForm.keyword?.trim() ?? ""; |
| 87 | if (!k) return true; |
| 88 | const lower = k.toLowerCase(); |
| 89 | const record = item as unknown as Record<string, unknown>; |
| 90 | const textFields: string[] = [item.title ?? "", item.description ?? ""]; |
| 91 | return textFields.some((t) => t.toLowerCase().includes(lower)); |
| 92 | }; |
nothing calls this directly
no test coverage detected