feat: update SearchForm to use project display names
Add Project interface with name and displayName fields to support project aliases. Update SWR hook to type projects as Project[]. Display project.displayName in dropdown while using project.name as the option value for API compatibility. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// app/download/SearchForm.tsx
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
@@ -13,6 +12,11 @@ const fetcher = async (url: string) => {
|
||||
return res.json();
|
||||
};
|
||||
|
||||
interface Project {
|
||||
name: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
interface SearchFormProps {
|
||||
onSearch: (project: string, version: string, commitId: string) => void;
|
||||
}
|
||||
@@ -23,13 +27,13 @@ export default function SearchForm({ onSearch }: SearchFormProps) {
|
||||
const [commitId, setCommitId] = useState('');
|
||||
|
||||
// 获取项目列表
|
||||
const { data: projects, isLoading: loadingProjects } = useSWR(
|
||||
const { data: projects, isLoading: loadingProjects } = useSWR<Project[]>(
|
||||
'/api/projects',
|
||||
fetcher
|
||||
);
|
||||
|
||||
// 获取版本列表
|
||||
const { data: versions, isLoading: loadingVersions } = useSWR(
|
||||
const { data: versions, isLoading: loadingVersions } = useSWR<string[]>(
|
||||
selectedProject ? `/api/versions?project=${selectedProject}` : null,
|
||||
fetcher
|
||||
);
|
||||
@@ -61,9 +65,9 @@ export default function SearchForm({ onSearch }: SearchFormProps) {
|
||||
{loadingProjects ? (
|
||||
<option disabled>加载中...</option>
|
||||
) : (
|
||||
projects?.map((project: string) => (
|
||||
<option key={project} value={project}>
|
||||
{project}
|
||||
projects?.map((project) => (
|
||||
<option key={project.name} value={project.name}>
|
||||
{project.displayName}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
@@ -86,7 +90,7 @@ export default function SearchForm({ onSearch }: SearchFormProps) {
|
||||
{loadingVersions ? (
|
||||
<option disabled>加载中...</option>
|
||||
) : (
|
||||
versions?.map((version: string) => (
|
||||
versions?.map((version) => (
|
||||
<option key={version} value={version}>
|
||||
{formatVersion(version)}
|
||||
</option>
|
||||
|
||||
Reference in New Issue
Block a user