Skip to content

Commit

Permalink
Feat/copy w to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ishiko732 committed Apr 6, 2024
1 parent fc24897 commit f6bd665
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/train/display.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
"use client";

import { useTrainContext } from "@/context/TrainContext";
import { useState } from "react";

export default function TrainDisplay() {
const { loading, loadTime, trainTime, totalTime, w } = useTrainContext();
const [ok, setOk] = useState(false);
const handleClick = async () => {
// copy w to chipboard
if (navigator.clipboard) {
await navigator.clipboard.writeText(JSON.stringify(w));
setOk(true);
setTimeout(() => {
setOk(false);
}, 1000);
}
};
return (
!loading &&
loadTime &&
trainTime && (
<div className="flex justify-center">
<div className="label flex flex-col gap-2">
<p className="label-text w-full text-left">W: {JSON.stringify(w)}</p>
<p className="label-text w-full text-left">
<button className="btn" onClick={handleClick}>
Copy w
</button>
{ok && <span className="label-text">Copied!</span>}
</p>
<p className="label-text w-full text-left">Load time: {loadTime}</p>
<p className="label-text w-full text-left">Train time: {trainTime}</p>
<p className="label-text w-full text-left">Total time: {totalTime}</p>
Expand Down

1 comment on commit f6bd665

@vercel
Copy link

@vercel vercel bot commented on f6bd665 Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.