From 7c393f0541725b4816da1630314e8a42e35f0786 Mon Sep 17 00:00:00 2001 From: sealday Date: Sun, 7 Apr 2024 04:40:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=B3=E8=81=94=E6=AD=8C=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/danmu/controls.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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}
    +
    */}
  • ))}