tenho o seguinte código react import { useEffect, useState } from "react"; import {…
- User
tenho o seguinte código react
import { useEffect, useState } from "react"; import { listen } from "@tauri-apps/api/event"; import { invoke } from "@tauri-apps/api/core";
function formatBytes(bytes: number) { if (bytes === 0) return '0 B'; const k = 1024; const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); const value = bytes / Math.pow(k, i); return
${value.toFixed(2)} ${units[i]}; }enum DownloadStatusType { Connecting = 'Connecting', Connected = 'Connected', Downloading = 'Downloading', Completed = 'Completed', Error = 'Error', }
interface DownloadStatus { status: DownloadStatusType; additional_info?: string; }
interface DownloadInfo { current_file: number; total_files: number; file_name: string; downloaded_bytes: number; total_bytes: number; }
const DownloadManager = () => { const [message, setMessage] = useState(""); const [currentFile, setCurrentFile] = useState(0); const [totalFiles, setTotalFiles] = useState(0); const [fileName, setFileName] = useState(""); const [downloadedBytes, setDownloadedBytes] = useState(0); const [totalBytes, setTotalBytes] = useState(0); const [isDownloading, setIsDownloading] = useState(false); const [downloadSpeed, setDownloadSpeed] = useState(0);
useEffect(() => { let unlistenStatus: (() => void) | null = null; let unlistenInfo: (() => void) | null = null; let unlistenSpeed: (() => void) | null = null;
code - Assistant
Para fazer com que a mensagem seja exibida apenas se
messagefor diferente de'Baixando'ou seisDownloadingfortrue, você pode ajustar a renderização no JSX do componente. Envolva o parágrafo que exibe a mensagem com uma condição que verifica esse critério.Aqui está como você pode modificar o código:
jsx