mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-21 10:03:56 +00:00
fix: fixing download sources import status
This commit is contained in:
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { Button, Modal, TextField } from "@renderer/components";
|
||||
import { settingsContext } from "@renderer/context";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { logger } from "@renderer/logger";
|
||||
|
||||
import * as yup from "yup";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
@@ -55,10 +56,10 @@ export function AddDownloadSourceModal({
|
||||
onClose();
|
||||
onAddDownloadSource();
|
||||
} catch (error) {
|
||||
console.error("Failed to add download source:", error);
|
||||
logger.error("Failed to add download source:", error);
|
||||
setError("url", {
|
||||
type: "server",
|
||||
message: "Failed to add download source. Please try again.",
|
||||
message: t("failed_add_download_source"),
|
||||
});
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
|
||||
@@ -201,7 +201,7 @@ export function SettingsAccount() {
|
||||
</section>
|
||||
|
||||
<section className="settings-account__section">
|
||||
<h3>Hydra Cloud</h3>
|
||||
<h3>{t("hydra_cloud")}</h3>
|
||||
<div className="settings-account__subscription-info">
|
||||
{getHydraCloudSectionContent().description}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
@use "../../scss/globals.scss";
|
||||
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.settings-download-sources {
|
||||
&__list {
|
||||
padding: 0;
|
||||
@@ -22,6 +31,17 @@
|
||||
&--syncing {
|
||||
opacity: globals.$disabled-opacity;
|
||||
}
|
||||
|
||||
&--pending {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
&__spinner {
|
||||
animation: spin 1s linear infinite;
|
||||
margin-right: calc(globals.$spacing-unit / 2);
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
&__item-header {
|
||||
|
||||
@@ -22,6 +22,7 @@ import { settingsContext } from "@renderer/context";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { setFilters, clearFilters } from "@renderer/features";
|
||||
import "./settings-download-sources.scss";
|
||||
import { logger } from "@renderer/logger";
|
||||
|
||||
export function SettingsDownloadSources() {
|
||||
const [
|
||||
@@ -58,6 +59,30 @@ export function SettingsDownloadSources() {
|
||||
fetchDownloadSources();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const hasPendingOrMatchingSource = downloadSources.some(
|
||||
(source) =>
|
||||
source.status === DownloadSourceStatus.PendingMatching ||
|
||||
source.status === DownloadSourceStatus.Matching
|
||||
);
|
||||
|
||||
if (!hasPendingOrMatchingSource || !downloadSources.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const intervalId = setInterval(async () => {
|
||||
try {
|
||||
await window.electron.syncDownloadSources();
|
||||
const sources = await window.electron.getDownloadSources();
|
||||
setDownloadSources(sources);
|
||||
} catch (error) {
|
||||
logger.error("Failed to fetch download sources:", error);
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, [downloadSources]);
|
||||
|
||||
const handleRemoveSource = async (downloadSource: DownloadSource) => {
|
||||
setIsRemovingDownloadSource(true);
|
||||
|
||||
@@ -67,7 +92,7 @@ export function SettingsDownloadSources() {
|
||||
setDownloadSources(sources as DownloadSource[]);
|
||||
showSuccessToast(t("removed_download_source"));
|
||||
} catch (error) {
|
||||
console.error("Failed to remove download source:", error);
|
||||
logger.error("Failed to remove download source:", error);
|
||||
} finally {
|
||||
setIsRemovingDownloadSource(false);
|
||||
}
|
||||
@@ -82,7 +107,7 @@ export function SettingsDownloadSources() {
|
||||
setDownloadSources(sources as DownloadSource[]);
|
||||
showSuccessToast(t("removed_all_download_sources"));
|
||||
} catch (error) {
|
||||
console.error("Failed to remove all download sources:", error);
|
||||
logger.error("Failed to remove all download sources:", error);
|
||||
} finally {
|
||||
setIsRemovingDownloadSource(false);
|
||||
setShowConfirmationDeleteAllSourcesModal(false);
|
||||
@@ -94,7 +119,7 @@ export function SettingsDownloadSources() {
|
||||
const sources = await window.electron.getDownloadSources();
|
||||
setDownloadSources(sources as DownloadSource[]);
|
||||
} catch (error) {
|
||||
console.error("Failed to refresh download sources:", error);
|
||||
logger.error("Failed to refresh download sources:", error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -127,7 +152,7 @@ export function SettingsDownloadSources() {
|
||||
|
||||
const navigateToCatalogue = (fingerprint?: string) => {
|
||||
if (!fingerprint) {
|
||||
console.error("Cannot navigate: fingerprint is undefined");
|
||||
logger.error("Cannot navigate: fingerprint is undefined");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,16 +227,25 @@ export function SettingsDownloadSources() {
|
||||
|
||||
<ul className="settings-download-sources__list">
|
||||
{downloadSources.map((downloadSource) => {
|
||||
const isPendingOrMatching =
|
||||
downloadSource.status === DownloadSourceStatus.PendingMatching ||
|
||||
downloadSource.status === DownloadSourceStatus.Matching;
|
||||
|
||||
return (
|
||||
<li
|
||||
key={downloadSource.id}
|
||||
className={`settings-download-sources__item ${isSyncingDownloadSources ? "settings-download-sources__item--syncing" : ""}`}
|
||||
className={`settings-download-sources__item ${isSyncingDownloadSources ? "settings-download-sources__item--syncing" : ""} ${isPendingOrMatching ? "settings-download-sources__item--pending" : ""}`}
|
||||
>
|
||||
<div className="settings-download-sources__item-header">
|
||||
<h2>{downloadSource.name}</h2>
|
||||
|
||||
<div style={{ display: "flex" }}>
|
||||
<Badge>{statusTitle[downloadSource.status]}</Badge>
|
||||
<Badge>
|
||||
{isPendingOrMatching && (
|
||||
<SyncIcon className="settings-download-sources__spinner" />
|
||||
)}
|
||||
{statusTitle[downloadSource.status]}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<button
|
||||
@@ -223,11 +257,13 @@ export function SettingsDownloadSources() {
|
||||
}
|
||||
>
|
||||
<small>
|
||||
{t("download_count", {
|
||||
count: downloadSource.downloadCount,
|
||||
countFormatted:
|
||||
downloadSource.downloadCount.toLocaleString(),
|
||||
})}
|
||||
{isPendingOrMatching
|
||||
? t("download_source_no_information")
|
||||
: t("download_count", {
|
||||
count: downloadSource.downloadCount,
|
||||
countFormatted:
|
||||
downloadSource.downloadCount.toLocaleString(),
|
||||
})}
|
||||
</small>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -133,7 +133,7 @@ export function SettingsRealDebrid() {
|
||||
{t("save_changes")}
|
||||
</Button>
|
||||
}
|
||||
placeholder="API Token"
|
||||
placeholder={t("api_token")}
|
||||
hint={
|
||||
<Trans i18nKey="debrid_api_token_hint" ns="settings">
|
||||
<Link to={REAL_DEBRID_API_TOKEN_URL} />
|
||||
|
||||
@@ -116,7 +116,7 @@ export function SettingsTorBox() {
|
||||
onChange={(event) =>
|
||||
setForm({ ...form, torBoxApiToken: event.target.value })
|
||||
}
|
||||
placeholder="API Token"
|
||||
placeholder={t("api_token")}
|
||||
rightContent={
|
||||
<Button type="submit" disabled={isButtonDisabled}>
|
||||
{t("save_changes")}
|
||||
|
||||
Reference in New Issue
Block a user