Fix scraped studio not matching existing value (#4548)

* Fix scraped studio not matching existing
* Fix incorrect key value
This commit is contained in:
WithoutPants
2024-02-13 12:24:11 +11:00
committed by GitHub
parent e9703e9a6e
commit dad4ab6a6f
6 changed files with 36 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ import {
} from "src/components/Shared/ScrapeDialog/ScrapeDialog"; } from "src/components/Shared/ScrapeDialog/ScrapeDialog";
import { import {
ObjectListScrapeResult, ObjectListScrapeResult,
ObjectScrapeResult,
ScrapeResult, ScrapeResult,
} from "src/components/Shared/ScrapeDialog/scrapeResult"; } from "src/components/Shared/ScrapeDialog/scrapeResult";
import { import {
@@ -66,8 +67,8 @@ export const GalleryScrapeDialog: React.FC<IGalleryScrapeDialogProps> = ({
const [photographer, setPhotographer] = useState<ScrapeResult<string>>( const [photographer, setPhotographer] = useState<ScrapeResult<string>>(
new ScrapeResult<string>(gallery.photographer, scraped.photographer) new ScrapeResult<string>(gallery.photographer, scraped.photographer)
); );
const [studio, setStudio] = useState<ScrapeResult<GQL.ScrapedStudio>>( const [studio, setStudio] = useState<ObjectScrapeResult<GQL.ScrapedStudio>>(
new ScrapeResult<GQL.ScrapedStudio>( new ObjectScrapeResult<GQL.ScrapedStudio>(
galleryStudio galleryStudio
? { ? {
stored_id: galleryStudio.id, stored_id: galleryStudio.id,

View File

@@ -44,11 +44,7 @@ const SceneSearchResultDetails: React.FC<ISceneSearchResultDetailsProps> = ({
<Row> <Row>
<Col> <Col>
{scene.tags?.map((tag) => ( {scene.tags?.map((tag) => (
<Badge <Badge className="tag-item" variant="secondary" key={tag.name}>
className="tag-item"
variant="secondary"
key={tag.stored_id}
>
{tag.name} {tag.name}
</Badge> </Badge>
))} ))}

View File

@@ -14,6 +14,7 @@ import { Performer } from "src/components/Performers/PerformerSelect";
import { IHasStoredID, sortStoredIdObjects } from "src/utils/data"; import { IHasStoredID, sortStoredIdObjects } from "src/utils/data";
import { import {
ObjectListScrapeResult, ObjectListScrapeResult,
ObjectScrapeResult,
ScrapeResult, ScrapeResult,
} from "src/components/Shared/ScrapeDialog/scrapeResult"; } from "src/components/Shared/ScrapeDialog/scrapeResult";
import { import {
@@ -73,8 +74,8 @@ export const SceneScrapeDialog: React.FC<ISceneScrapeDialogProps> = ({
const [director, setDirector] = useState<ScrapeResult<string>>( const [director, setDirector] = useState<ScrapeResult<string>>(
new ScrapeResult<string>(scene.director, scraped.director) new ScrapeResult<string>(scene.director, scraped.director)
); );
const [studio, setStudio] = useState<ScrapeResult<GQL.ScrapedStudio>>( const [studio, setStudio] = useState<ObjectScrapeResult<GQL.ScrapedStudio>>(
new ScrapeResult<GQL.ScrapedStudio>( new ObjectScrapeResult<GQL.ScrapedStudio>(
sceneStudio sceneStudio
? { ? {
stored_id: sceneStudio.id, stored_id: sceneStudio.id,

View File

@@ -6,14 +6,17 @@ import {
IHasName, IHasName,
} from "src/components/Shared/ScrapeDialog/ScrapeDialog"; } from "src/components/Shared/ScrapeDialog/ScrapeDialog";
import { PerformerSelect } from "src/components/Performers/PerformerSelect"; import { PerformerSelect } from "src/components/Performers/PerformerSelect";
import { ScrapeResult } from "src/components/Shared/ScrapeDialog/scrapeResult"; import {
ObjectScrapeResult,
ScrapeResult,
} from "src/components/Shared/ScrapeDialog/scrapeResult";
import { TagSelect } from "src/components/Tags/TagSelect"; import { TagSelect } from "src/components/Tags/TagSelect";
import { StudioSelect } from "src/components/Studios/StudioSelect"; import { StudioSelect } from "src/components/Studios/StudioSelect";
interface IScrapedStudioRow { interface IScrapedStudioRow {
title: string; title: string;
result: ScrapeResult<GQL.ScrapedStudio>; result: ObjectScrapeResult<GQL.ScrapedStudio>;
onChange: (value: ScrapeResult<GQL.ScrapedStudio>) => void; onChange: (value: ObjectScrapeResult<GQL.ScrapedStudio>) => void;
newStudio?: GQL.ScrapedStudio; newStudio?: GQL.ScrapedStudio;
onCreateNew?: (value: GQL.ScrapedStudio) => void; onCreateNew?: (value: GQL.ScrapedStudio) => void;
} }
@@ -26,7 +29,7 @@ export const ScrapedStudioRow: React.FC<IScrapedStudioRow> = ({
onCreateNew, onCreateNew,
}) => { }) => {
function renderScrapedStudio( function renderScrapedStudio(
scrapeResult: ScrapeResult<GQL.ScrapedStudio>, scrapeResult: ObjectScrapeResult<GQL.ScrapedStudio>,
isNew?: boolean, isNew?: boolean,
onChangeFn?: (value: GQL.ScrapedStudio) => void onChangeFn?: (value: GQL.ScrapedStudio) => void
) { ) {

View File

@@ -6,7 +6,7 @@ import {
useStudioCreate, useStudioCreate,
useTagCreate, useTagCreate,
} from "src/core/StashService"; } from "src/core/StashService";
import { ScrapeResult } from "./scrapeResult"; import { ObjectScrapeResult, ScrapeResult } from "./scrapeResult";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
import { scrapedPerformerToCreateInput } from "src/core/performers"; import { scrapedPerformerToCreateInput } from "src/core/performers";
import { scrapedMovieToCreateInput } from "src/core/movies"; import { scrapedMovieToCreateInput } from "src/core/movies";
@@ -41,8 +41,10 @@ function useCreateObject<T>(
} }
interface IUseCreateNewStudioProps { interface IUseCreateNewStudioProps {
scrapeResult: ScrapeResult<GQL.ScrapedStudio>; scrapeResult: ObjectScrapeResult<GQL.ScrapedStudio>;
setScrapeResult: (scrapeResult: ScrapeResult<GQL.ScrapedStudio>) => void; setScrapeResult: (
scrapeResult: ObjectScrapeResult<GQL.ScrapedStudio>
) => void;
setNewObject: (newObject: GQL.ScrapedStudio | undefined) => void; setNewObject: (newObject: GQL.ScrapedStudio | undefined) => void;
} }

View File

@@ -106,6 +106,23 @@ export class ObjectListScrapeResult<
} }
} }
export class ObjectScrapeResult<
T extends IHasStoredID
> extends ScrapeResult<T> {
public constructor(
originalValue?: T | null,
newValue?: T | null,
useNewValue?: boolean
) {
super(
originalValue,
newValue,
useNewValue,
(o1, o2) => o1?.stored_id === o2?.stored_id
);
}
}
export function hasScrapedValues(values: { scraped: boolean }[]): boolean { export function hasScrapedValues(values: { scraped: boolean }[]): boolean {
return values.some((r) => r.scraped); return values.some((r) => r.scraped);
} }