forked from all-in-aigc/melodisco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
10,740 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 67 additions & 34 deletions
101
app/[locale]/(default)/_components/generator/describe.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,74 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
|
||
import Describe from "./describe"; | ||
import Info from "./info"; | ||
import Preview from "./preview"; | ||
import Sign from "../sign"; | ||
import Steps from "./steps"; | ||
import { useAppContext } from "@/contexts/app"; | ||
import { useState } from "react"; | ||
import { useSearchParams } from "next/navigation"; | ||
|
||
export default function () { | ||
const searchParams = useSearchParams(); | ||
const { user } = useAppContext(); | ||
const [step, setStep] = useState("describe"); | ||
const { | ||
songTaskStep: step, | ||
setSongTaskStep: setStep, | ||
setSongTask, | ||
} = useAppContext(); | ||
|
||
const fetchTask = async function (taskid: string) { | ||
try { | ||
const params = { | ||
task_uuid: taskid, | ||
}; | ||
const resp = await fetch("/api/get-song-task", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(params), | ||
}); | ||
const { code, message, data } = await resp.json(); | ||
if (data) { | ||
setSongTask(data); | ||
if (data.song_uuids) { | ||
setStep(3); | ||
} else if (data.lyrics) { | ||
setStep(2); | ||
} else { | ||
setStep(1); | ||
} | ||
} | ||
} catch (e) { | ||
console.log("fetch task failed:", e); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const taskid = searchParams.get("taskid") as string; | ||
if (taskid) { | ||
fetchTask(taskid); | ||
} | ||
}, [searchParams]); | ||
|
||
return ( | ||
<> | ||
{user ? ( | ||
<div className="mt-8"> | ||
<Steps /> | ||
|
||
return <>{user ? <div>coming soon...</div> : <Sign />}</>; | ||
<div className="max-w-xl mt-8"> | ||
{step === 1 && <Describe />} | ||
{step === 2 && <Info />} | ||
{step === 3 && <Preview />} | ||
</div> | ||
</div> | ||
) : ( | ||
<Sign /> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.