2022-08-27 08:45:32 +00:00
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
|
|
|
|
import CompatBtn from "../compatbtn";
|
2022-09-14 10:08:52 +00:00
|
|
|
import { GoVerified } from "react-icons/go";
|
2022-08-26 13:46:21 +00:00
|
|
|
|
2022-09-18 10:07:07 +00:00
|
|
|
function installRepo(url) {
|
|
|
|
if (window.AdbConnection !== undefined) {
|
|
|
|
window.AdbConnection.subprocess.shell(`am start -a android.intent.action.VIEW -d "cloudstreamrepo://${url.replace(/^https?:\/\//, "")}"`)
|
|
|
|
} else if (window.RepoApi !== undefined) {
|
|
|
|
window.RepoApi.installRepo(url)
|
|
|
|
} else {
|
|
|
|
window.open(`cloudstreamrepo://${url.replace(/^https?:\/\//, "")}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 10:11:34 +00:00
|
|
|
const RepoCard = ({ repoData, isFirst }) => {
|
2022-08-26 13:46:21 +00:00
|
|
|
const [data, setData] = useState(null)
|
|
|
|
|
2022-09-14 10:11:34 +00:00
|
|
|
const url = (typeof repoData === 'string') ? repoData : repoData.url
|
|
|
|
const isVerified = (typeof repoData === 'object' && repoData.verified)
|
2022-09-14 10:08:52 +00:00
|
|
|
|
2022-08-26 13:46:21 +00:00
|
|
|
useEffect(() => {
|
|
|
|
fetch(url)
|
|
|
|
.then(r => r.json())
|
|
|
|
.then(dat => {
|
|
|
|
setData(dat)
|
|
|
|
})
|
|
|
|
}, [setData])
|
|
|
|
|
|
|
|
if (data == null) {
|
|
|
|
return <progress className="progress progress-primary w-full mx-10 md:w-2/3 mb-5"></progress>
|
|
|
|
}
|
|
|
|
|
2022-09-01 07:56:43 +00:00
|
|
|
return <article className="card bg-base-200 shadow-xl w-full mx-10 md:w-2/3 mb-5">
|
2022-09-14 10:11:34 +00:00
|
|
|
<div className="card-body">
|
|
|
|
<h2 className="card-title flex flex-row">
|
2022-09-14 10:08:52 +00:00
|
|
|
{isVerified &&
|
|
|
|
<div class="tooltip" data-tip="Verified safe">
|
|
|
|
<GoVerified class="stroke-current flex-shrink-0 h-6 w-6 success" />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
{data.name || "Unnamed"}
|
|
|
|
</h2>
|
2022-08-26 13:46:21 +00:00
|
|
|
<p>
|
|
|
|
{data.description || "No description provided"}
|
|
|
|
</p>
|
|
|
|
<div className="card-actions justify-end">
|
|
|
|
<div className="btn-group">
|
2022-08-27 08:45:32 +00:00
|
|
|
<CompatBtn
|
|
|
|
autoFocus={isFirst}
|
|
|
|
group={true}
|
|
|
|
className="btn-primary"
|
2022-09-10 17:36:53 +00:00
|
|
|
onClick={() => {
|
2022-09-18 10:07:07 +00:00
|
|
|
installRepo(url)
|
2022-09-10 17:36:53 +00:00
|
|
|
}}
|
2022-08-27 08:45:32 +00:00
|
|
|
>Install</CompatBtn>
|
|
|
|
<CompatBtn group={true}
|
|
|
|
onClick={() => {
|
|
|
|
if (navigator.clipboard) {
|
|
|
|
navigator.clipboard.writeText(url);
|
|
|
|
} else {
|
|
|
|
var tempInput = document.createElement("input");
|
|
|
|
tempInput.value = url;
|
|
|
|
document.body.appendChild(tempInput);
|
|
|
|
tempInput.select();
|
|
|
|
document.execCommand("copy");
|
|
|
|
document.body.removeChild(tempInput);
|
|
|
|
}
|
|
|
|
}}>Copy URL</CompatBtn>
|
2022-08-26 13:46:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
}
|
|
|
|
|
2022-09-10 17:36:53 +00:00
|
|
|
export default RepoCard
|