diff --git a/app/songs/actions.tsx b/app/songs/actions.tsx new file mode 100644 index 0000000..d2f3f0e --- /dev/null +++ b/app/songs/actions.tsx @@ -0,0 +1,17 @@ +import { + InternetProviderLyricSearchResponse, + getSearchResults, +} from "@/lib/actions/lyrics"; + +export async function searchSongs( + _currentState: InternetProviderLyricSearchResponse[], + formData: FormData +): Promise { + const list = await getSearchResults({ + name: formData.get("name") as string, + }); + if (list) { + return list; + } + return []; +} diff --git a/app/songs/page.tsx b/app/songs/page.tsx index 24b99a8..839defe 100644 --- a/app/songs/page.tsx +++ b/app/songs/page.tsx @@ -1,37 +1,32 @@ +import SearchForm from "./search-form"; + export default function Page() { return (
-

My Collection

+

已收藏

  • - Song 1 + 冬天的秘密 - 周传雄
  • - Song 2 + 其实都没有 - 张盼盼
-

Search Songs

-
- -
- -
+

搜索

+ + {/*
Song 3
-
+
*/}
diff --git a/app/songs/search-form.tsx b/app/songs/search-form.tsx new file mode 100644 index 0000000..cdbaa2f --- /dev/null +++ b/app/songs/search-form.tsx @@ -0,0 +1,39 @@ +"use client"; + +import { useFormState } from "react-dom"; +import { searchSongs } from "./actions"; + +export default function SearchForm({ + className, +}: { + className?: string | undefined; +}) { + const [items, dispatch] = useFormState(searchSongs, []); + return ( +
+ + {items ? ( +
+ {items.map((item) => ( +
+ + {item.name} - {item.artist} + + +
+ ))} +
+ ) : null} +
+ ); +} diff --git a/lib/actions/lyrics.ts b/lib/actions/lyrics.ts index 28f9681..b39d0ee 100644 --- a/lib/actions/lyrics.ts +++ b/lib/actions/lyrics.ts @@ -12,7 +12,7 @@ enum LyricSource { NETEASE = "NetEase", } -interface InternetProviderLyricSearchResponse { +export interface InternetProviderLyricSearchResponse { artist: string; id: string; name: string;