-
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.
wallet sidebar: add ongoing task card
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useEffect, useState } from "react" | ||
|
||
import { Task, useTaskHistoryWebSocket } from "@renegade-fi/react" | ||
|
||
import { | ||
Card, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card" | ||
|
||
import { | ||
generateCompletionToastMessage, | ||
generateStartToastMessage, | ||
} from "@/lib/constants/task" | ||
|
||
export function RunningTaskCard() { | ||
const [visibleTask, setVisibleTask] = useState<Task | null>(null) | ||
useTaskHistoryWebSocket({ | ||
onUpdate(task) { | ||
if (task.state !== "Queued") { | ||
setVisibleTask(task) | ||
} | ||
}, | ||
}) | ||
|
||
useEffect(() => { | ||
if (!visibleTask) return | ||
|
||
if (visibleTask.state === "Completed" || visibleTask.state === "Failed") { | ||
const timer = setTimeout(() => { | ||
setVisibleTask(null) | ||
}, 60000) | ||
|
||
return () => clearTimeout(timer) | ||
} | ||
}, [visibleTask]) | ||
|
||
if (!visibleTask) return null | ||
|
||
const status = visibleTask.state | ||
const isRunning = status !== "Completed" && status !== "Failed" | ||
const description = isRunning | ||
? generateStartToastMessage(visibleTask) | ||
: generateCompletionToastMessage(visibleTask) | ||
|
||
return ( | ||
<div className="p-1"> | ||
<Card className="rounded-none shadow-none"> | ||
<form> | ||
<CardHeader className="p-3"> | ||
<CardTitle className="text-sm font-normal"> | ||
{isRunning ? ( | ||
<span className="inline-flex animate-text-gradient bg-gradient-to-r from-[#ACACAC] via-[#363636] to-[#ACACAC] bg-[200%_auto] bg-clip-text text-transparent"> | ||
{status} | ||
</span> | ||
) : ( | ||
<span>{status}</span> | ||
)} | ||
</CardTitle> | ||
<CardDescription>{description}</CardDescription> | ||
</CardHeader> | ||
</form> | ||
</Card> | ||
</div> | ||
) | ||
} |
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