From e1da6ddcef21693edd2a4717d580568b421bc6fb Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Tue, 27 Feb 2024 22:15:32 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A2=20Wiring=20up=20to=20addTorrent=20?= =?UTF-8?q?endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComicDetail/TorrentSearchPanel.tsx | 74 +++++++++++++++++-- src/client/components/Search/Search.tsx | 6 +- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/src/client/components/ComicDetail/TorrentSearchPanel.tsx b/src/client/components/ComicDetail/TorrentSearchPanel.tsx index 983b561..05f6d40 100644 --- a/src/client/components/ComicDetail/TorrentSearchPanel.tsx +++ b/src/client/components/ComicDetail/TorrentSearchPanel.tsx @@ -3,12 +3,33 @@ import React, { useCallback, ReactElement, useEffect, useState } from "react"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import axios from "axios"; import { Form, Field } from "react-final-form"; -import { PROWLARR_SERVICE_BASE_URI } from "../../constants/endpoints"; +import { + PROWLARR_SERVICE_BASE_URI, + QBITTORRENT_SERVICE_BASE_URI, +} from "../../constants/endpoints"; +import { isEmpty, isNil } from "lodash"; export const TorrentSearchPanel = (props): ReactElement => { const [prowlarrSettingsData, setProwlarrSettingsData] = useState({}); + const [searchTerm, setSearchTerm] = useState(""); + const [torrentToDownload, setTorrentToDownload] = useState([]); - const { data } = useQuery({ + const { data: qbittorrentConnectionResult } = useQuery({ + queryFn: async () => + axios({ + url: `${QBITTORRENT_SERVICE_BASE_URI}/connect`, + method: "POST", + data: { + hostname: "localhost", + protocol: "http", + port: "8080", + username: "admin", + password: "password", + }, + }), + queryKey: ["qbittorrentConnection"], + }); + const { data, isSuccess } = useQuery({ queryFn: async () => axios({ url: `${PROWLARR_SERVICE_BASE_URI}/search`, @@ -18,25 +39,46 @@ export const TorrentSearchPanel = (props): ReactElement => { apiKey: "c4f42e265fb044dc81f7e88bd41c3367", offset: 0, categories: [7030], - query: "the darkness", + query: searchTerm, host: "localhost", limit: 100, type: "search", indexerIds: [2], }, }), - queryKey: ["prowlarrSettingsData"], + queryKey: ["prowlarrSettingsData", searchTerm], + enabled: searchTerm !== "", }); - console.log(data?.data); + + const { data: addTorrentResult } = useQuery({ + queryFn: async () => + axios({ + url: `${QBITTORRENT_SERVICE_BASE_URI}/addTorrent`, + method: "POST", + data: { + torrentToDownload, + }, + }), + queryKey: ["addTorrentResult", torrentToDownload], + enabled: !isEmpty(torrentToDownload), + }); + console.log(addTorrentResult); + const searchProwlarrIndexer = (evt) => { + setSearchTerm(evt.searchTerm); + }; + const downloadTorrent = (evt) => { + console.log(evt); + setTorrentToDownload(evt); + }; return ( <>
{}} + onSubmit={searchProwlarrIndexer} initialValues={{}} render={({ handleSubmit, form, submitting, pristine, values }) => ( - + {({ input, meta }) => { return (
@@ -70,6 +112,24 @@ export const TorrentSearchPanel = (props): ReactElement => { )} />
+ {/* results */} +
    + {isSuccess && + data?.data.map((result, idx) => { + return ( +
  • +

    {result.fileName}

    +

    {result.indexer}

    + +
  • + ); + })} +
); }; diff --git a/src/client/components/Search/Search.tsx b/src/client/components/Search/Search.tsx index 07fe3db..ecc386d 100644 --- a/src/client/components/Search/Search.tsx +++ b/src/client/components/Search/Search.tsx @@ -1,9 +1,7 @@ import React, { useCallback, ReactElement, useState } from "react"; import { isNil, isEmpty } from "lodash"; import { IExtractedComicBookCoverFile, RootState } from "threetwo-ui-typings"; -import { importToDB } from "../../actions/fileops.actions"; -import { comicinfoAPICall } from "../../actions/comicinfo.actions"; -import { search } from "../../services/api/SearchApi"; + import { Form, Field } from "react-final-form"; import Card from "../shared/Carda"; import ellipsize from "ellipsize"; @@ -27,7 +25,6 @@ export const Search = ({}: ISearchProps): ReactElement => { const [comicVineMetadata, setComicVineMetadata] = useState({}); const getCVSearchResults = (searchQuery) => { setSearchQuery(searchQuery.search); - // queryClient.invalidateQueries({ queryKey: ["comicvineSearchResults"] }); }; const { @@ -146,6 +143,7 @@ export const Search = ({}: ISearchProps): ReactElement => { )} />
+ {isLoading && <>Loading kaka...} {!isNil(comicVineSearchResults?.data.results) && !isEmpty(comicVineSearchResults?.data.results) ? (