diff --git a/Website/app/Releases.js b/Website/app/Releases.js index 870141584..0699480a4 100644 --- a/Website/app/Releases.js +++ b/Website/app/Releases.js @@ -1,195 +1,370 @@ "use client"; -import {useEffect, useMemo, useState} from "react" -import { remark } from 'remark'; -import html from 'remark-html'; +import { useEffect, useMemo, useState } from "react"; +import { remark } from "remark"; +import html from "remark-html"; function downloadLatestRelease(OSName, applicationType) { - if (applicationType === "CLI") { - if (OSName === "Windows") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI.exe"); - } else if (OSName === "Linux") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI_linux"); - } else { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI_macos"); - } + if (applicationType === "CLI") { + if (OSName === "Windows") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI.exe" + ); + } else if (OSName === "Linux") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI_linux" + ); } else { - if (OSName === "Windows exe") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI.exe"); - } else if (OSName === "Windows msi") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI.msi"); - } else if (OSName === "Linux") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI_linux"); - } else { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI.pkg"); - } + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-CLI_macos" + ); } + } else { + if (OSName === "Windows exe") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI.exe" + ); + } else if (OSName === "Windows msi") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI.msi" + ); + } else if (OSName === "Linux") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI_linux" + ); + } else { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/latest/download/Drifty-GUI.pkg" + ); + } + } } function downloadOlderReleases(OSName, applicationType, version) { - if (applicationType === "CLI") { - if (OSName === "Windows") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + version + "/Drifty-CLI.exe"); - } else if (OSName === "Linux") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + version + "/Drifty-CLI_linux"); - } else { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + version + "/Drifty-CLI_macos"); - } + if (applicationType === "CLI") { + if (OSName === "Windows") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + + version + + "/Drifty-CLI.exe" + ); + } else if (OSName === "Linux") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + + version + + "/Drifty-CLI_linux" + ); } else { - if (OSName === "Windows exe") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + version + "/Drifty-GUI.exe"); - } else if (OSName === "Windows msi") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + version + "/Drifty-GUI.msi"); - } else if (OSName === "Linux") { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + version + "/Drifty-GUI_linux"); - } else { - window.open("https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + version + "/Drifty-GUI.pkg"); - } + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + + version + + "/Drifty-CLI_macos" + ); + } + } else { + if (OSName === "Windows exe") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + + version + + "/Drifty-GUI.exe" + ); + } else if (OSName === "Windows msi") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + + version + + "/Drifty-GUI.msi" + ); + } else if (OSName === "Linux") { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + + version + + "/Drifty-GUI_linux" + ); + } else { + window.open( + "https://github.com/SaptarshiSarkar12/Drifty/releases/download/" + + version + + "/Drifty-GUI.pkg" + ); } + } } -export default function Releases({props}) { - const [buttonStates, setButtonStates] = useState({}); - const [content,setContent]=useState([]); - const [applicationType, setApplicationType] = useState("GUI"); - const maxReleasesToDisplay = 3; - const filteredReleases = useMemo(() => { - const releases = []; - props.release.map((item, index) => { - if (index !== 0) { - if (item.tag_name.startsWith("v2") && releases.length <= maxReleasesToDisplay) { - releases.push(item); - } - } - }); - return releases; - }, [props.release]); - const filterOlderReleases = useMemo(() => { - const releases = []; - let noOfReleases = filteredReleases.length; - props.release.map((item, index) => { - if (releases.length <= maxReleasesToDisplay && noOfReleases < maxReleasesToDisplay && index !== 0) { - if (!item.tag_name.startsWith("v2")) { - releases.push(item); - noOfReleases++; - } - } - }); - return releases; - }, [filteredReleases.length, props.release]); +export default function Releases({ props }) { + const [buttonStates, setButtonStates] = useState({}); + const [content, setContent] = useState([]); + const [applicationType, setApplicationType] = useState("GUI"); + const maxReleasesToDisplay = 3; + const filteredReleases = useMemo(() => { + const releases = []; + props.release.map((item, index) => { + if (index !== 0) { + if ( + item.tag_name.startsWith("v2") && + releases.length <= maxReleasesToDisplay + ) { + releases.push(item); + } + } + }); + return releases; + }, [props.release]); + const filterOlderReleases = useMemo(() => { + const releases = []; + let noOfReleases = filteredReleases.length; + props.release.map((item, index) => { + if ( + releases.length <= maxReleasesToDisplay && + noOfReleases < maxReleasesToDisplay && + index !== 0 + ) { + if (!item.tag_name.startsWith("v2")) { + releases.push(item); + noOfReleases++; + } + } + }); + return releases; + }, [filteredReleases.length, props.release]); - const handleButtonClick = (index) => { - setButtonStates((prevState) => ({ - ...prevState, - [index]: !prevState[index], - })); - }; - const markerToHtml = async (itemBody, i) => { - const cont = await remark().use(html).process(itemBody); - setContent((prev)=> {prev[i]=cont.toString(); return prev}); - } - useEffect(() => { - filteredReleases.forEach(async (item, index) => { - await markerToHtml(item.body, index); - }); - filterOlderReleases.forEach(async (item, index) => { - await markerToHtml(item.body, index + filteredReleases.length); - }); - }, [filteredReleases, filterOlderReleases]); + const handleButtonClick = (index) => { + setButtonStates((prevState) => ({ + ...prevState, + [index]: !prevState[index], + })); + }; + const markerToHtml = async (itemBody, i) => { + const cont = await remark().use(html).process(itemBody); + setContent((prev) => { + prev[i] = cont.toString(); + return prev; + }); + }; + useEffect(() => { + filteredReleases.forEach(async (item, index) => { + await markerToHtml(item.body, index); + }); + filterOlderReleases.forEach(async (item, index) => { + await markerToHtml(item.body, index + filteredReleases.length); + }); + }, [filteredReleases, filterOlderReleases]); - const handleApplicationTypeChange = (applicationType) => { - setApplicationType(applicationType.target.value); - } - - return ( -
+ {new Date(item.published_at).toString()} with{" "} + {item.assets[0].download_count + + item.assets[1].download_count + + item.assets[2].download_count + + item.assets[3].download_count + + item.assets[4].download_count + + item.assets[5].download_count}{" "} + Downloads +
+ + {buttonStates[index] && ( + + )} + +{new Date(item.published_at).toString()} with {item.assets[0].download_count + item.assets[1].download_count + item.assets[2].download_count + item.assets[3].download_count + item.assets[4].download_count + item.assets[5].download_count} Downloads
- - {buttonStates[index] && } -+ {new Date(item.published_at).toString()} with{" "} + {item.assets[0].download_count + + item.assets[1].download_count}{" "} + Downloads +
+ + {buttonStates[index] && ( + )} - {filterOlderReleases.map((item, index) => { - index = index + filteredReleases.length; - if (filterOlderReleases.length !== 0) { - return ( -{new Date(item.published_at).toString()} with {item.assets[0].download_count + item.assets[1].download_count} Downloads
- - {buttonStates[index] && } -