mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 10:36:07 +00:00
refactor: make type and repository filters Debian/Ubuntu specific
- Removed type and repository filters from non-Debian/Ubuntu platforms (Arch, Fedora, macOS, Windows) - Conditionally render type filter UI only for Debian/Ubuntu platforms - Set type and repository to null in package fetchers for platforms that don't support these classifications
This commit is contained in:
@@ -31,7 +31,10 @@ export function PackageBrowserV2({
|
||||
const [totalCount, setTotalCount] = useState(0)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [typeFilter, setTypeFilter] = useState<string>('')
|
||||
const [repositoryFilter, setRepositoryFilter] = useState<string>('')
|
||||
const isDebianUbuntu = useMemo(() => {
|
||||
const id = selectedPlatform?.id || ''
|
||||
return id === 'debian' || id === 'ubuntu'
|
||||
}, [selectedPlatform])
|
||||
const [scrollPosition, setScrollPosition] = useState(0)
|
||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
@@ -60,14 +63,10 @@ export function PackageBrowserV2({
|
||||
params.search = searchQuery.trim()
|
||||
}
|
||||
|
||||
if (typeFilter && typeFilter !== 'all') {
|
||||
if (isDebianUbuntu && typeFilter && typeFilter !== 'all') {
|
||||
params.type = typeFilter as 'gui' | 'cli'
|
||||
}
|
||||
|
||||
if (repositoryFilter && repositoryFilter !== 'all') {
|
||||
params.repository = repositoryFilter as 'official' | 'third-party'
|
||||
}
|
||||
|
||||
console.log('🔍 Frontend: API params:', params)
|
||||
const result = await apiClient.getPackages(params)
|
||||
console.log('📦 Frontend: Received initial packages:', {
|
||||
@@ -87,7 +86,7 @@ export function PackageBrowserV2({
|
||||
}
|
||||
|
||||
loadPackages()
|
||||
}, [selectedPlatform, typeFilter, repositoryFilter])
|
||||
}, [selectedPlatform, typeFilter, isDebianUbuntu])
|
||||
|
||||
// Debounced search to prevent focus loss
|
||||
useEffect(() => {
|
||||
@@ -109,14 +108,10 @@ export function PackageBrowserV2({
|
||||
params.search = searchQuery.trim()
|
||||
}
|
||||
|
||||
if (typeFilter && typeFilter !== 'all') {
|
||||
if (isDebianUbuntu && typeFilter && typeFilter !== 'all') {
|
||||
params.type = typeFilter as 'gui' | 'cli'
|
||||
}
|
||||
|
||||
if (repositoryFilter && repositoryFilter !== 'all') {
|
||||
params.repository = repositoryFilter as 'official' | 'third-party'
|
||||
}
|
||||
|
||||
console.log('🔍 Frontend: Debounced API params:', params)
|
||||
const result = await apiClient.getPackages(params)
|
||||
console.log('📦 Frontend: Debounced result:', result.packages.length)
|
||||
@@ -135,7 +130,7 @@ export function PackageBrowserV2({
|
||||
}, 300) // 300ms debounce
|
||||
|
||||
return () => clearTimeout(timeoutId)
|
||||
}, [searchQuery])
|
||||
}, [searchQuery, isDebianUbuntu, typeFilter, selectedPlatform])
|
||||
|
||||
// Load more packages
|
||||
const loadMore = async () => {
|
||||
@@ -153,14 +148,10 @@ export function PackageBrowserV2({
|
||||
params.search = searchQuery.trim()
|
||||
}
|
||||
|
||||
if (typeFilter && typeFilter !== 'all') {
|
||||
if (isDebianUbuntu && typeFilter && typeFilter !== 'all') {
|
||||
params.type = typeFilter as 'gui' | 'cli'
|
||||
}
|
||||
|
||||
if (repositoryFilter && repositoryFilter !== 'all') {
|
||||
params.repository = repositoryFilter as 'official' | 'third-party'
|
||||
}
|
||||
|
||||
const result = await apiClient.getPackages(params)
|
||||
setPackages(prev => [...prev, ...result.packages])
|
||||
setHasMore(packages.length + result.packages.length < result.total)
|
||||
@@ -253,7 +244,8 @@ export function PackageBrowserV2({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Type Filter */}
|
||||
{/* Type Filter (Debian/Ubuntu only) */}
|
||||
{isDebianUbuntu && (
|
||||
<Select value={typeFilter || "all"} onValueChange={(value) => setTypeFilter(value === "all" ? "" : value)}>
|
||||
<SelectTrigger className="w-full sm:w-40">
|
||||
<SelectValue placeholder="Type" />
|
||||
@@ -264,18 +256,7 @@ export function PackageBrowserV2({
|
||||
<SelectItem value="cli">CLI</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{/* Repository Filter */}
|
||||
<Select value={repositoryFilter || "all"} onValueChange={(value) => setRepositoryFilter(value === "all" ? "" : value)}>
|
||||
<SelectTrigger className="w-full sm:w-40">
|
||||
<SelectValue placeholder="Repository" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Repositories</SelectItem>
|
||||
<SelectItem value="official">Official</SelectItem>
|
||||
<SelectItem value="third-party">Third Party</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Package List */}
|
||||
@@ -312,7 +293,7 @@ export function PackageBrowserV2({
|
||||
/>
|
||||
<div className="flex items-start space-x-2 flex-1">
|
||||
<div className="mt-0.5">
|
||||
{getPackageIcon(pkg.type || 'cli')}
|
||||
{isDebianUbuntu ? getPackageIcon(pkg.type || 'cli') : <PackageIcon className="h-4 w-4" />}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -325,12 +306,16 @@ export function PackageBrowserV2({
|
||||
{pkg.description || 'No description available'}
|
||||
</p>
|
||||
<div className="flex items-center gap-2 mt-2">
|
||||
{isDebianUbuntu && pkg.type && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{pkg.type?.toUpperCase() || 'CLI'}
|
||||
{pkg.type.toUpperCase()}
|
||||
</span>
|
||||
)}
|
||||
{pkg.repository === 'third-party' && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{pkg.repository || 'official'}
|
||||
third-party
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -172,16 +172,12 @@ export class ArchPackageFetcher {
|
||||
[pkg.name, 'arch']
|
||||
)
|
||||
|
||||
const repository = (pkg.repository === 'core' || pkg.repository === 'extra')
|
||||
? 'official'
|
||||
: 'third-party'
|
||||
|
||||
if (existingResult.rows.length === 0) {
|
||||
// Insert new package (id will be auto-generated by SERIAL)
|
||||
await query(
|
||||
`INSERT INTO packages (id, name, description, version, platform_id, type, repository, popularity_score, is_active)
|
||||
VALUES (gen_random_uuid(), $1, $2, $3, $4, $5, $6, $7, $8)`,
|
||||
[pkg.name, pkg.description, pkg.version, 'arch', 'cli', repository, 0, true]
|
||||
[pkg.name, pkg.description, pkg.version, 'arch', null, null, 0, true]
|
||||
)
|
||||
stored++
|
||||
} else if (existingResult.rows[0].version !== pkg.version) {
|
||||
@@ -190,7 +186,7 @@ export class ArchPackageFetcher {
|
||||
`UPDATE packages
|
||||
SET version = $1, description = $2, repository = $3, updated_at = NOW()
|
||||
WHERE id = $4`,
|
||||
[pkg.version, pkg.description, repository, existingResult.rows[0].id]
|
||||
[pkg.version, pkg.description, null, existingResult.rows[0].id]
|
||||
)
|
||||
updated++
|
||||
} else {
|
||||
|
||||
@@ -146,7 +146,7 @@ export class FedoraPackageFetcher {
|
||||
await query(
|
||||
`INSERT INTO packages (id, name, description, version, platform_id, type, repository, popularity_score, is_active)
|
||||
VALUES (gen_random_uuid(), $1, $2, $3, $4, $5, $6, $7, $8)`,
|
||||
[pkg.name, pkg.description, pkg.version, 'fedora', 'cli', pkg.repository, 0, true]
|
||||
[pkg.name, pkg.description, pkg.version, 'fedora', null, null, 0, true]
|
||||
)
|
||||
stored++
|
||||
} else if (existingResult.rows[0].version !== pkg.version) {
|
||||
@@ -155,7 +155,7 @@ export class FedoraPackageFetcher {
|
||||
`UPDATE packages
|
||||
SET version = $1, description = $2, repository = $3, updated_at = NOW()
|
||||
WHERE id = $4`,
|
||||
[pkg.version, pkg.description, pkg.repository, existingResult.rows[0].id]
|
||||
[pkg.version, pkg.description, null, existingResult.rows[0].id]
|
||||
)
|
||||
updated++
|
||||
} else {
|
||||
|
||||
@@ -145,7 +145,7 @@ export class HomebrewPackageFetcher {
|
||||
await query(
|
||||
`INSERT INTO packages (id, name, description, version, platform_id, type, repository, popularity_score, is_active)
|
||||
VALUES (gen_random_uuid(), $1, $2, $3, $4, $5, $6, $7, $8)`,
|
||||
[pkg.name, pkg.description, pkg.version, 'macos', 'cli', 'official', 0, true]
|
||||
[pkg.name, pkg.description, pkg.version, 'macos', null, null, 0, true]
|
||||
)
|
||||
stored++
|
||||
} else if (existingResult.rows[0].version !== pkg.version) {
|
||||
|
||||
@@ -232,7 +232,7 @@ export class WingetPackageFetcher {
|
||||
await query(
|
||||
`INSERT INTO packages (id, name, description, version, platform_id, type, repository, popularity_score, is_active)
|
||||
VALUES (gen_random_uuid(), $1, $2, $3, $4, $5, $6, $7, $8)`,
|
||||
[pkg.name, pkg.description, pkg.version, 'windows', 'gui', 'official', 0, true]
|
||||
[pkg.name, pkg.description, pkg.version, 'windows', null, null, 0, true]
|
||||
)
|
||||
stored++
|
||||
} else if (existingResult.rows[0].version !== pkg.version) {
|
||||
|
||||
Reference in New Issue
Block a user