-
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
275f209
commit 498ea5e
Showing
16 changed files
with
264 additions
and
27 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use thunder_manager_common::utils::thunderstore::package::{self, FetchPackageResult}; | ||
|
||
#[tauri::command] | ||
pub async fn fetch_package(name: &str, namespace: &str) -> Result<FetchPackageResult, String> { | ||
let data = package::fetch_package(name, namespace).await; | ||
|
||
if let Ok(data) = data { | ||
Ok(data) | ||
} else { | ||
data.map_err(|e| e.to_string()) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Paper, Table, TableBody, TableCell, TableContainer, TableRow } from "@mui/material" | ||
|
||
export type Row = { | ||
name: string | ||
value?: string | number | ||
} | ||
|
||
export type InfoRowProps = { | ||
rows: Row[], | ||
} | ||
|
||
export default function InfoRow(props: InfoRowProps) { | ||
return <TableContainer component={Paper}> | ||
<Table sx={{ minWidth: 345 }}> | ||
<TableBody> | ||
{props.rows.map((row) => <TableRow> | ||
<TableCell>{row.name}</TableCell> | ||
<TableCell>{row.value}</TableCell> | ||
</TableRow>)} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,65 @@ | ||
import { Container } from "@mui/material"; | ||
import { Box, Button, Card, CardContent, Container, Skeleton, Typography } from "@mui/material"; | ||
import { FetchPackage } from "../utils"; | ||
import { useParams } from "react-router-dom"; | ||
import { useEffect, useState } from "react"; | ||
import { ThunderstorePackage } from "../utils/package"; | ||
import { copyToClipboard } from "../utils/clipboard"; | ||
import InfoRow from "../components/InfoRow"; | ||
|
||
export default function Package() { | ||
return <Container> | ||
const { name, namespace } = useParams(); | ||
const [packageData, setPackageData] = useState<ThunderstorePackage | null>(null); | ||
|
||
useEffect(() => { | ||
async function fetchPackageData() { | ||
try { | ||
if (!name || !namespace) { | ||
console.error("no name or namespace", name, namespace); | ||
return; | ||
} | ||
|
||
const data = await FetchPackage(name, namespace); | ||
|
||
console.log(data); | ||
|
||
setPackageData(data); | ||
} catch (e) { | ||
console.error("couldn't fetch pacakge:", e); | ||
} | ||
} | ||
|
||
if (!packageData) fetchPackageData(); | ||
}); | ||
|
||
const tableRows = [{ | ||
name: "Last updated", | ||
value: packageData?.date_updated, | ||
}, { | ||
name: "Total downloads", | ||
value: packageData?.total_downloads, | ||
}, { | ||
name: "Rating", | ||
value: packageData?.rating_score, | ||
}, { | ||
name: "Dependency string", | ||
value: packageData?.full_name, | ||
}] | ||
|
||
return <Container maxWidth="sm"> | ||
{packageData ? <Box> | ||
<Card sx={{ minWidth: 345, maxWidth: 650 }}> | ||
<CardContent> | ||
<Typography gutterBottom variant="h5" component="div">{packageData.name}</Typography> | ||
<Typography variant="body2" color="text.secondary">{packageData.latest.description}</Typography> | ||
<Typography variant="body1">By </Typography> | ||
<Typography variant="body1" color="turquoise">{packageData.owner}</Typography> | ||
<InfoRow rows={tableRows} /> | ||
<Button>Add</Button> | ||
{packageData.package_url ? <Button | ||
onClick={() => copyToClipboard(packageData.package_url ?? "")} | ||
>Copy link</Button> : <></>} | ||
</CardContent> | ||
</Card> | ||
</Box> : <Skeleton variant="rectangular" height={250} width={345} />} | ||
</Container> | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const copyToClipboard = (text: string) => navigator.clipboard.writeText(text) |
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
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 +1,2 @@ | ||
pub mod manifest; | ||
pub mod package; |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
#[serde(untagged)] | ||
pub enum StringOri32 { | ||
String(String), | ||
I32(i32) | ||
} | ||
|
||
pub type RatingScore = StringOri32; | ||
pub type DownloadCount = StringOri32; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct PackageVersionExperimental { | ||
namespace: Option<String>, | ||
name: String, | ||
version_number: String, | ||
full_name: Option<String>, | ||
description: String, | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct ExperimentalPackage { | ||
pub namespace: Option<String>, | ||
pub name: String, | ||
pub full_name: Option<String>, | ||
pub owner: Option<String>, | ||
pub package_url: Option<String>, | ||
pub date_created: Option<String>, | ||
pub date_updated: Option<String>, | ||
pub rating_score: Option<RatingScore>, | ||
pub is_pinned: Option<bool>, | ||
pub is_deprecated: Option<bool>, | ||
pub total_downloads: Option<DownloadCount>, | ||
pub latest: PackageVersionExperimental, | ||
} |
Oops, something went wrong.