-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e4282b
commit 1cda8c4
Showing
3 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,89 @@ | ||
import axios from "axios"; | ||
import { useRouter } from "next/router"; | ||
import { useQuery } from "react-query"; | ||
import QueryString from "qs"; | ||
|
||
import styles from "../../../styles/PackagePage.module.css"; | ||
|
||
const testData = { | ||
id: "chrome", | ||
name: "Google Chrome", | ||
description: "Google Chrome is a web browser made by Google LLC", | ||
logo: "https://www.google.se/chrome/static/images/chrome-logo.svg", | ||
|
||
authour: { | ||
username: "google", | ||
name: "Google LLC", | ||
}, | ||
}; | ||
async function installPackage(id: string) { | ||
let os; | ||
if (navigator.appVersion.indexOf("Win") >= 0) os = "windows"; | ||
if (navigator.appVersion.indexOf("Mac") >= 0) os = "macos"; | ||
|
||
const About = () => { | ||
return ( | ||
<div> | ||
<p>{testData.description}</p> | ||
</div> | ||
); | ||
}; | ||
if (!os) { | ||
alert("Sorry, this browser is not supported."); | ||
return; | ||
} | ||
|
||
const PackagePage = () => { | ||
const router = useRouter(); | ||
const { id } = router.query; | ||
const params = QueryString.stringify({ | ||
package: id, | ||
platform: os, | ||
}); | ||
const { data } = await axios.get(`https://api.bytecube.tk/package/install?${params}`); | ||
const { url } = data; | ||
|
||
window.location.href = url; | ||
} | ||
|
||
const Package: React.FC<{ id: string }> = ({ id }) => { | ||
const { data: packageData } = useQuery("packageData", async () => { | ||
const params = QueryString.stringify({ | ||
package: id | ||
}); | ||
|
||
const { data } = await axios.get(`https://api.bytecube.tk/package/meta?${params}`); | ||
return data; | ||
}); | ||
|
||
if (!packageData) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className={`${styles.package}`}> | ||
<div className={`${styles.package}`}> | ||
<div className={`${styles.package__header}`}> | ||
<div className={`${styles.package__info}`}> | ||
<img className={`${styles.package__logo}`} src={testData.logo} /> | ||
<img className={`${styles.package__logo}`} src={null} /> | ||
<div className={`${styles.package__text}`}> | ||
<h2 className={`${styles.package__name}`}>{testData.name}</h2> | ||
<h3 className={`${styles.package__author}`}> | ||
by{" "} | ||
<span className={`${styles.author}`}> | ||
{testData.authour.name} | ||
</span> | ||
</h3> | ||
<h2 className={`${styles.package__name}`}>{packageData.name}</h2> | ||
{ | ||
packageData.author && | ||
<h3 className={`${styles.package__author}`}> | ||
by{" "} | ||
<span className={`${styles.author}`}> | ||
{packageData.author.name} | ||
</span> | ||
</h3> | ||
} | ||
</div> | ||
</div> | ||
<button className={`${styles.package__install}`}>Install</button> | ||
<button | ||
className={`${styles.package__install}`} | ||
onClick={() => { | ||
console.log("Install package"); | ||
installPackage(id); | ||
}} | ||
>Install</button> | ||
</div> | ||
<div> | ||
<div>About</div> | ||
<div>Blog</div> | ||
<div>Versions</div> | ||
<div className={`${styles.package__description}`}> | ||
<p>{packageData.description}</p> | ||
</div> | ||
<About /> | ||
</div> | ||
); | ||
}; | ||
|
||
const PackagePage = () => { | ||
const router = useRouter(); | ||
const { id } = router.query; | ||
|
||
if (!id) { | ||
return <div>Loading...</div> | ||
} | ||
|
||
return ( | ||
<Package id={id as string} /> | ||
); | ||
}; | ||
|
||
export default PackagePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1cda8c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: