Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show download button only for the OS of the client-device. #254

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@mdi/react": "^1.3.0",
"axios": "^0.19.2",
"next": "^9.3.5",
"platform": "^1.3.6",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-ga": "^2.7.0",
Expand Down
86 changes: 67 additions & 19 deletions website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import React from "react";
import { IParticlesParams } from "react-particles-js";
import dynamic from "next/dynamic";
import Icon from "@mdi/react";
import { mdiApple, mdiGithub, mdiLinux, mdiMicrosoftWindows } from "@mdi/js";
import {
mdiApple,
mdiConsoleNetworkOutline,
mdiGithub,
mdiLinux,
mdiMicrosoftWindows,
} from "@mdi/js";
import Head from "next/head";
import ProgressiveImage from "react-progressive-image";
import platform from "platform";
import axios from "axios";

const Particles = dynamic(() => import("react-particles-js"), {
Expand Down Expand Up @@ -44,6 +51,29 @@ export async function getStaticProps() {
}

export default ({ macUrl, linuxUrl }) => {
// Download-button React Component
function DownloadButton(props) {
return !props.disabled ? (
<a href={props.url} target="_blank">
<button className="download-button">
<Icon path={props.logo} size={1.2} />
</button>
</a>
) : (
<button title="Coming soon" disabled className="download-button">
<Icon path={props.logo} size={1.2} />
</button>
);
}

var platformOs = platform.os.toString();
// Client OS is other than Windows, Mac and Linux
var flag =
!platformOs.match(/Mac OS/i) &&
!platformOs.match(/Win/i) &&
!platformOs.match(/Linux/i);
console.log(flag);

return (
<div className="wrapper">
<Head>
Expand Down Expand Up @@ -74,24 +104,42 @@ export default ({ macUrl, linuxUrl }) => {
<span>A torrent client to download, stream and cast torrents.</span>

<div className="downloads">
<a href={macUrl} target="_blank">
<button className="download-button">
<Icon path={mdiApple} size={1.2} />
</button>
</a>
<button title="Coming soon" disabled className="download-button">
<Icon path={mdiMicrosoftWindows} size={1.2} />
</button>
<a href={linuxUrl} target="_blank">
<button className="download-button">
<Icon path={mdiLinux} size={1.2} />
</button>
</a>
<a href="https://github.com/ritz078/moose" target="_blank">
<button className="download-button">
<Icon path={mdiGithub} size={1.2} />
</button>
</a>
{/* Display appropriate Download-button for the client */}
{platformOs.match(/Mac OS/i) && (
<DownloadButton url={macUrl} logo={mdiApple} disabled={false} />
)}
{platformOs.match(/Win/i) && (
<DownloadButton logo={mdiMicrosoftWindows} disabled={true} />
)}
{platformOs.match(/Linux/i) && (
<DownloadButton
url={linuxUrl}
logo={mdiLinux}
disabled={false}
/>
)}

{/* If the OS doesn't match any of the three, display all the buttons */}
{flag && (
<DownloadButton url={macUrl} logo={mdiApple} disabled={false} />
)}
{flag && (
<DownloadButton logo={mdiMicrosoftWindows} disabled={true} />
)}
{flag && (
<DownloadButton
url={linuxUrl}
logo={mdiLinux}
disabled={false}
/>
)}
{
<DownloadButton
url="https://github.com/ritz078/moose"
logo={mdiGithub}
disabled={false}
/>
Copy link
Owner

Choose a reason for hiding this comment

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

{
  flag && (
    <>
      <DownloadButton url={macUrl} logo={mdiApple} disabled={false} />
      <DownloadButton logo={mdiMicrosoftWindows} disabled={true} />
      <DownloadButton url={linuxUrl} logo={mdiLinux} disabled={false} />
      <DownloadButton
        url="https://github.com/ritz078/moose"
        logo={mdiGithub}
        disabled={false}
      />
    </>
  );
}

}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion website/src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ body {
.downloads {
display: flex;
flex-direction: row;
justify-content: space-between;
justify-content: space-around;
width: 300px;
margin-top: 40px;
}
Expand Down