From f794c6ae45f9611bbdf4875a99b5b2b6248fe251 Mon Sep 17 00:00:00 2001 From: gitgiggety <79809426+gitgiggety@users.noreply.github.com> Date: Wed, 10 Mar 2021 03:47:22 +0100 Subject: [PATCH] Add scrape gallery from fragment to UI (#1166) --- .../src/components/Changelog/versions/v060.md | 1 + .../GalleryDetails/GalleryEditPanel.tsx | 84 ++++++++++++++++++- ui/v2.5/src/core/StashService.ts | 4 +- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/ui/v2.5/src/components/Changelog/versions/v060.md b/ui/v2.5/src/components/Changelog/versions/v060.md index 3c71bda2b..f03a39cde 100644 --- a/ui/v2.5/src/components/Changelog/versions/v060.md +++ b/ui/v2.5/src/components/Changelog/versions/v060.md @@ -2,6 +2,7 @@ * Added Performer tags. ### 🎨 Improvements +* Add scrape gallery from fragment to UI * Improved performer details and edit UI pages. * Resolve python executable to `python3` or `python` for python script scrapers. * Add `url` field to `URLReplace`, and make `queryURLReplace` available when scraping by URL. diff --git a/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryEditPanel.tsx b/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryEditPanel.tsx index 5f515fb0b..5769f55d2 100644 --- a/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryEditPanel.tsx +++ b/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryEditPanel.tsx @@ -1,13 +1,22 @@ import React, { useEffect, useState } from "react"; import { useHistory } from "react-router-dom"; -import { Button, Form, Col, Row } from "react-bootstrap"; +import { + Button, + Dropdown, + DropdownButton, + Form, + Col, + Row, +} from "react-bootstrap"; import Mousetrap from "mousetrap"; import * as GQL from "src/core/generated-graphql"; import { + queryScrapeGallery, queryScrapeGalleryURL, useGalleryCreate, useGalleryUpdate, useListGalleryScrapers, + mutateReloadScrapers, } from "src/core/StashService"; import { PerformerSelect, @@ -64,6 +73,7 @@ export const GalleryEditPanel: React.FC< ); const Scrapers = useListGalleryScrapers(); + const [queryableScrapers, setQueryableScrapers] = useState([]); const [ scrapedGallery, @@ -118,6 +128,16 @@ export const GalleryEditPanel: React.FC< } }); + useEffect(() => { + const newQueryableScrapers = ( + Scrapers?.data?.listGalleryScrapers ?? [] + ).filter((s) => + s.gallery?.supported_scrapes.includes(GQL.ScrapeType.Fragment) + ); + + setQueryableScrapers(newQueryableScrapers); + }, [Scrapers]); + function getGalleryInput() { return { id: isNew ? undefined : gallery?.id ?? "", @@ -162,6 +182,39 @@ export const GalleryEditPanel: React.FC< setIsLoading(false); } + async function onScrapeClicked(scraper: GQL.Scraper) { + setIsLoading(true); + try { + const galleryInput = getGalleryInput() as GQL.GalleryUpdateInput; + const result = await queryScrapeGallery(scraper.id, galleryInput); + if (!result.data || !result.data.scrapeGallery) { + Toast.success({ + content: "No galleries found", + }); + return; + } + setScrapedGallery(result.data.scrapeGallery); + } catch (e) { + Toast.error(e); + } finally { + setIsLoading(false); + } + } + + async function onReloadScrapers() { + setIsLoading(true); + try { + await mutateReloadScrapers(); + + // reload the performer scrapers + await Scrapers.refetch(); + } catch (e) { + Toast.error(e); + } finally { + setIsLoading(false); + } + } + function onScrapeDialogClosed(data?: GQL.ScrapedGalleryDataFragment) { if (data) { updateGalleryFromScrapedGallery(data); @@ -187,6 +240,32 @@ export const GalleryEditPanel: React.FC< ); } + function renderScraperMenu() { + if (isNew) { + return; + } + + return ( + + {queryableScrapers.map((s) => ( + onScrapeClicked(s)}> + {s.name} + + ))} + onReloadScrapers()}> + + + + Reload scrapers + + + ); + } + function urlScrapable(scrapedUrl: string): boolean { return (Scrapers?.data?.listGalleryScrapers ?? []).some((s) => (s?.gallery?.urls ?? []).some((u) => scrapedUrl.includes(u)) @@ -290,6 +369,9 @@ export const GalleryEditPanel: React.FC< Delete + + {renderScraperMenu()} +
diff --git a/ui/v2.5/src/core/StashService.ts b/ui/v2.5/src/core/StashService.ts index d903d8d03..b5639ac62 100644 --- a/ui/v2.5/src/core/StashService.ts +++ b/ui/v2.5/src/core/StashService.ts @@ -776,13 +776,13 @@ export const queryStashBoxScene = (stashBoxIndex: number, sceneID: string) => export const queryScrapeGallery = ( scraperId: string, - scene: GQL.GalleryUpdateInput + gallery: GQL.GalleryUpdateInput ) => client.query({ query: GQL.ScrapeGalleryDocument, variables: { scraper_id: scraperId, - scene, + gallery, }, fetchPolicy: "network-only", });