Skip to content
Snippets Groups Projects
Commit 41f77701 authored by Štěpán Šonovský's avatar Štěpán Šonovský
Browse files

fix: two step downloading

parent 3606af6c
No related branches found
No related tags found
No related merge requests found
import React, { useState, useEffect } from 'react'; import React, { useState } from 'react';
import useCommits from "@/app/hooks/useCommits"; import useCommits from "@/app/hooks/useCommits";
import CsvDownloadPositivity from "@/app/csvDownload/CsvDownload"; import CsvDownloadPositivity from "@/app/csvDownload/CsvDownload";
import CsvDownloadSize from "@/app/csvDownload/CsvDownloadSize"; import CsvDownloadSize from "@/app/csvDownload/CsvDownloadSize";
...@@ -8,16 +8,6 @@ const CommitList = ({ projectId, token, host, onCommitClick }) => { ...@@ -8,16 +8,6 @@ const CommitList = ({ projectId, token, host, onCommitClick }) => {
const [showCsvDownloadPositivity, setShowCsvDownloadPositivity] = useState(false); const [showCsvDownloadPositivity, setShowCsvDownloadPositivity] = useState(false);
const [showCsvDownloadSize, setShowCsvDownloadSize] = useState(false); const [showCsvDownloadSize, setShowCsvDownloadSize] = useState(false);
useEffect(() => {
let timer;
if (showCsvDownloadPositivity) {
timer = setTimeout(() => setShowCsvDownloadPositivity(false), 2000);
} else if (showCsvDownloadSize) {
timer = setTimeout(() => setShowCsvDownloadSize(false), 2000);
}
return () => clearTimeout(timer);
}, [showCsvDownloadPositivity, showCsvDownloadSize]);
if (loading) return <p>Loading...</p>; if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>; if (error) return <p>Error: {error.message}</p>;
...@@ -38,29 +28,36 @@ const CommitList = ({ projectId, token, host, onCommitClick }) => { ...@@ -38,29 +28,36 @@ const CommitList = ({ projectId, token, host, onCommitClick }) => {
) : ( ) : (
<p>No commits found</p> <p>No commits found</p>
)} )}
<button {
onClick={() => setShowCsvDownloadSize(true)} !showCsvDownloadSize ? (
className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700 m-2" <button
> onClick={() => setShowCsvDownloadSize(prev => !prev)}
Download CSV commits size className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700 m-2"
</button> >
{showCsvDownloadSize && ( {"Fetch CSV commits size"}
<div className="mt-4"> </button>
<CsvDownloadSize commits={commits} projectId={projectId} token={token} /> )
</div> :
)} (
<button
onClick={() => setShowCsvDownloadPositivity(true)}
className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700 m-2"
>
Download CSV commits positivity
</button>
{showCsvDownloadPositivity && (
<div className="mt-4"> <div className="mt-4">
<CsvDownloadPositivity commits={commits} projectId={projectId} token={token} /> <CsvDownloadSize commits={commits} projectId={projectId} token={token}/>
</div> </div>
)} )
}
{
!showCsvDownloadPositivity ? (
<button
onClick={() => setShowCsvDownloadPositivity(true)}
className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700 m-2"
>
Fetch CSV commits positivity
</button>
) : (
<div className="mt-4">
<CsvDownloadPositivity commits={commits} projectId={projectId} token={token}/>
</div>
)
}
</div> </div>
); );
}; };
......
import {useState, useEffect, createRef} from 'react'; import { useState, useEffect, createRef } from 'react';
import useCommitDetails, { useCommitsPositivity} from "@/app/hooks/useCommitDetails";
import { CSVLink } from "react-csv"; import { CSVLink } from "react-csv";
import useCommitDetails, { useCommitsPositivity } from "@/app/hooks/useCommitDetails";
type CommitDetails = {
author: string;
createdAt: string;
projectId: string;
};
const CsvDownloadPositivity = ({ commits, projectId, token }) => { const CsvDownloadPositivity = ({ commits, projectId, token }) => {
const {data, isLoading} = useCommitsPositivity(projectId, commits, token); const { data, isLoading } = useCommitsPositivity(projectId, commits, token);
const csvlink = createRef(); const csvlink = createRef();
// useEffect(() => {
// if (!isLoading && data) {
// console.log("das");
// csvlink.current.link.click();
// }
// }, [csvlink, data, isLoading]);
//
// console.log(data);
return ( return (
<div> <div>
{!isLoading && data ? ( {!isLoading && data ? (
<div> <CSVLink
<CSVLink data={data}
data={data} ref={csvlink}
ref={csvlink} target="_blank"
target="_blank" enclosingCharacter={``}
enclosingCharacter={``} className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700"
>lol</CSVLink> >
Download CSV commits positivity
</div> </CSVLink>
) : ( ) : (
<p>Loading...</p> <p>Loading...</p>
)} )}
</div> </div>
); );
}; };
export default CsvDownloadPositivity; export default CsvDownloadPositivity;
...@@ -33,11 +33,13 @@ const CsvDownloadSize = ({ commits, projectId, token }) => { ...@@ -33,11 +33,13 @@ const CsvDownloadSize = ({ commits, projectId, token }) => {
ref={csvlink} ref={csvlink}
target="_blank" target="_blank"
enclosingCharacter={``} enclosingCharacter={``}
>lol</CSVLink> className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700"
>Download CSV size</CSVLink>
</div> </div>
) : ( ) : (
<p>Loading...</p> <p className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700"
>Loading...</p>
)} )}
</div> </div>
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment