Merge PR #6 from XlebyllleK/master

feat: Filter out unused repositories
This commit is contained in:
Eshan Roy
2025-01-11 23:02:18 +05:30
committed by GitHub
2 changed files with 44 additions and 31 deletions

View File

@@ -9,26 +9,43 @@ import {
Repository Repository
} from '../types'; } from '../types';
import {
MIRRORS
} from '../services/api';
interface HeaderProps { interface HeaderProps {
onRepositoryChange: (repo: Repository) => void; onRepositoryChange: (repo: Repository) => void;
} }
export function Header({ onRepositoryChange }: HeaderProps): JSX.Element { export function Header({
onRepositoryChange
}: HeaderProps): JSX.Element {
const usedRepositories = new Set(Object.values(MIRRORS).map(mirror => mirror.repository));
const filteredRepository = Object.keys(Repository).reduce((acc, key) => {
// This code is flawed because it explicitly checks for 'ALL', reducing flexibility.
// A more generic approach should be used to filter unused repositories while preserving 'ALL'.
if ((key === 'ALL') || usedRepositories.has(Repository[key as keyof typeof Repository])) acc[key] = Repository[key as keyof typeof Repository];
return acc;
}, {} as Record<string, string>);
return ( return (
<header className="bg-gradient-to-r from-nord-9 to-nord-8 via-nord-10 text-nord-6 shadow-lg"> <header className="bg-gradient-to-r from-nord-9 to-nord-8 via-nord-10 text-nord-6 shadow-lg">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4"> <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
{/* Logo Section */} {/* Logo Section */}
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<Logo /> <Logo />
</div> </div>
{/* Repository Filter Dropdown */} {/* Repository Filter Dropdown */}
<div> <div>
<select onChange={ <select onChange={
(e) => onRepositoryChange(e.target.value as Repository) (e) => onRepositoryChange(e.target.value as Repository)
} defaultValue="all" className="bg-nord-5 dark:bg-nord-1 text-black dark:text-white border-2 border-nord-4 dark:border-nord-2 rounded-lg py-2 px-4 focus:ring-2 focus:ring-nord-8"> } defaultValue="all" className="bg-nord-5 dark:bg-nord-1 text-black dark:text-white border-2 border-nord-4 dark:border-nord-2 rounded-lg py-2 px-4 focus:ring-2 focus:ring-nord-8">
{Object.values(Repository).map((repository) => ( {Object.values(filteredRepository).map((repository) => (
<option key={repository} value={repository}>{((repository === Repository.ALL) ? 'All Repositories' : repository.charAt(0).toUpperCase() + repository.slice(1))}</option> <option key={repository} value={repository}>{((repository === Repository.ALL) ? 'All Repositories' : repository.charAt(0).toUpperCase() + repository.slice(1))}</option>
))} ))}
</select> </select>

View File

@@ -4,14 +4,10 @@ import {
} from '../types'; } from '../types';
// Define the mirrors from which packages will be fetched // Define the mirrors from which packages will be fetched
const MIRRORS: Record<string, { export const MIRRORS: Record<string, {
url: string; url: string;
repository: Repository; repository: Repository;
}> = { }> = {
/**
* Сейчас данный код будет удобным вариантом,
* чтобы убрать убирать пустые (неиспользуемые) репозитории из главной страницы
*/
'core': { 'core': {
url: 'https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-core/refs/heads/master/packages.txt', url: 'https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-core/refs/heads/master/packages.txt',
repository: ('core' as Repository) repository: ('core' as Repository)