From 29ed8025edceec9532349a26b1b4a3e2dab4cb2b Mon Sep 17 00:00:00 2001 From: sealday Date: Sat, 6 Apr 2024 15:57:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=92=A8=E8=AF=A2=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E6=AD=8C=E6=89=8B=E7=9A=84=E6=AD=8C=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/songs/actions.tsx | 17 +++++++++++++++++ app/songs/page.tsx | 27 +++++++++++---------------- app/songs/search-form.tsx | 39 +++++++++++++++++++++++++++++++++++++++ lib/actions/lyrics.ts | 2 +- 4 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 app/songs/actions.tsx create mode 100644 app/songs/search-form.tsx 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;