Skip to content

Commit

Permalink
fix: use chalk and log on debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Sep 13, 2023
1 parent c000140 commit 95680eb
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Image from "next/image";
import Badges from "./json/badges/index.json";
import Tippy from "@tippyjs/react";
import moment from "moment";
import chalk from "chalk";
import emojis from "./json/demo/emojis.json";
import Utils from "./utils";
import Highcharts from "highcharts";
Expand Down Expand Up @@ -1092,12 +1093,25 @@ const statIcons = {
};

async function copyToClipboard(value: string) : Promise<boolean> {
const isDebug = localStorage.getItem("debug") === "true";
try {
await navigator.clipboard.writeText(value);
console.log('Content copied to clipboard');
if (isDebug) {
console.log(
chalk.bold.blue(`[DEBUG] `) +
chalk.bold.cyan(`[${moment(Date.now()).format("h:mm:ss a")}]`) +
` ${chalk.yellow(`Content copied to clipboard`)}`
);
}
return true;
} catch (err) {
console.error('Failed to copy: ', err);
if (isDebug) {
console.error(
chalk.bold.blue(`[DEBUG] `) +
chalk.bold.cyan(`[${moment(Date.now()).format("h:mm:ss a")}]`) +
` ${chalk.yellow(`Failed to copy: ${err}`)}`
);
}
return false;
}
}
Expand Down

0 comments on commit 95680eb

Please sign in to comment.