diff --git a/app/danmu/controls.tsx b/app/danmu/controls.tsx index 812c11b..bd0de6c 100644 --- a/app/danmu/controls.tsx +++ b/app/danmu/controls.tsx @@ -1,6 +1,7 @@ "use client"; -import { useRef, useState, useEffect } from "react"; +import { useRef, useState, useEffect, useContext } from "react"; import { query } from "@/lib/actions/lyrics"; +import { DanmuContext } from "./provider"; const useLyricsRunner = (runner: (lyric: string) => void, interval: number) => { const [lyrics, setLyrics] = useState([]); @@ -70,13 +71,14 @@ interface LyricItem { export default function Controls(): JSX.Element { const ref = useRef(null); const [history, setHistory] = useState([]); + const { songId, songName, songArtist } = useContext(DanmuContext); const { start, resume, pause, setLyrics, offset, setOffset } = useLyricsRunner((line) => { setHistory((items) => [ { - content: line.slice(0, 10), - timestamp: line.slice(10), + timestamp: line.slice(0, 10), + content: line.slice(10), }, ...items, ]); @@ -128,7 +130,8 @@ export default function Controls(): JSX.Element { className="btn join-item btn-sm" onClick={() => { query({ - name: "音乐弹幕", + name: songName, + artist: songArtist, }) .then((result) => { // eslint-disable-next-line no-console -- temp @@ -146,6 +149,7 @@ export default function Controls(): JSX.Element { }); }} type="button" + disabled={!songId} > 开始 @@ -161,8 +165,8 @@ export default function Controls(): JSX.Element {
    {history.map((item, i) => (
  • -
    {item.timestamp}
    -
    +
    {item.timestamp}{item.content}
    + {/*
    -
    -
    {item.content}
    +
    */}
  • ))}