diff --git a/app/danmu/current-input.tsx b/app/danmu/current-input.tsx
new file mode 100644
index 0000000..6534679
--- /dev/null
+++ b/app/danmu/current-input.tsx
@@ -0,0 +1,13 @@
+"use client";
+
+import { useContext } from "react";
+import { DanmuContext } from "./provider";
+
+export default function CurrentInput() {
+ const state = useContext(DanmuContext);
+ return (
+
+ {state.songName ?? ""} {state.songId ? "-" : ""} {state.songArtist ?? ""}
+
+ );
+}
diff --git a/app/danmu/live-check.tsx b/app/danmu/live-check.tsx
new file mode 100644
index 0000000..a7dbd04
--- /dev/null
+++ b/app/danmu/live-check.tsx
@@ -0,0 +1,34 @@
+"use client";
+
+import { useContext } from "react";
+import { DanmuContext } from "./provider";
+
+export default function LiveCheck({ lives }: { lives: any[] }) {
+ const { dispatch, ...state } = useContext(DanmuContext);
+ return (
+
+ );
+}
diff --git a/app/danmu/page.tsx b/app/danmu/page.tsx
index 4a1e42b..0b3613c 100644
--- a/app/danmu/page.tsx
+++ b/app/danmu/page.tsx
@@ -3,6 +3,10 @@ import Controls from "./controls";
import Danmu from "./danmu";
import { listLives } from "@/lib/actions/live";
import { listSongs } from "../songs/actions";
+import DanmuProvider from "./provider";
+import LiveCheck from "./live-check";
+import SongCheck from "./song-check";
+import CurrentInput from "./current-input";
export default async function Page() {
const token = await getToken();
@@ -10,61 +14,37 @@ export default async function Page() {
const songs = await listSongs();
return (
-
-
-
-
-
);
}
diff --git a/app/danmu/provider.tsx b/app/danmu/provider.tsx
new file mode 100644
index 0000000..f9617de
--- /dev/null
+++ b/app/danmu/provider.tsx
@@ -0,0 +1,45 @@
+"use client";
+import { createContext, useReducer } from "react";
+
+export interface DanmuPayload {
+ liveName?: string;
+ liveId?: string;
+ songId?: string;
+ songName?: string;
+ songArtist?: string;
+}
+
+export interface DanmuAction {
+ type: string;
+ payload: DanmuPayload;
+}
+
+export const DanmuContext = createContext
(
+ {}
+);
+
+const reducer = (state: DanmuPayload, action: DanmuAction): DanmuPayload => {
+ const payload = action.payload;
+ switch (action.type) {
+ case "songs":
+ return {
+ ...state,
+ songId: payload.songId,
+ songName: payload.songName,
+ songArtist: payload.songArtist,
+ };
+ case "lives":
+ return { ...state, liveId: payload.liveId, liveName: payload.liveName };
+ default:
+ throw new Error("not support action");
+ }
+};
+
+export default function DanmuProvider(props: any) {
+ const [state, dispatch] = useReducer(reducer, {});
+ return (
+
+ {props.children}
+
+ );
+}
diff --git a/app/danmu/song-check.tsx b/app/danmu/song-check.tsx
new file mode 100644
index 0000000..d60850c
--- /dev/null
+++ b/app/danmu/song-check.tsx
@@ -0,0 +1,35 @@
+"use client";
+
+import { useContext } from "react";
+import { DanmuContext } from "./provider";
+
+export default function SongCheck({ songs }: { songs: any[] }) {
+ const { dispatch, ...state } = useContext(DanmuContext);
+ return (
+
+ );
+}