Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scraped studio not matching existing value #4548

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "src/components/Shared/ScrapeDialog/ScrapeDialog";
import {
ObjectListScrapeResult,
ObjectScrapeResult,
ScrapeResult,
} from "src/components/Shared/ScrapeDialog/scrapeResult";
import {
Expand Down Expand Up @@ -66,8 +67,8 @@ export const GalleryScrapeDialog: React.FC<IGalleryScrapeDialogProps> = ({
const [photographer, setPhotographer] = useState<ScrapeResult<string>>(
new ScrapeResult<string>(gallery.photographer, scraped.photographer)
);
const [studio, setStudio] = useState<ScrapeResult<GQL.ScrapedStudio>>(
new ScrapeResult<GQL.ScrapedStudio>(
const [studio, setStudio] = useState<ObjectScrapeResult<GQL.ScrapedStudio>>(
new ObjectScrapeResult<GQL.ScrapedStudio>(
galleryStudio
? {
stored_id: galleryStudio.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ const SceneSearchResultDetails: React.FC<ISceneSearchResultDetailsProps> = ({
<Row>
<Col>
{scene.tags?.map((tag) => (
<Badge
className="tag-item"
variant="secondary"
key={tag.stored_id}
>
<Badge className="tag-item" variant="secondary" key={tag.name}>
{tag.name}
</Badge>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Performer } from "src/components/Performers/PerformerSelect";
import { IHasStoredID, sortStoredIdObjects } from "src/utils/data";
import {
ObjectListScrapeResult,
ObjectScrapeResult,
ScrapeResult,
} from "src/components/Shared/ScrapeDialog/scrapeResult";
import {
Expand Down Expand Up @@ -73,8 +74,8 @@ export const SceneScrapeDialog: React.FC<ISceneScrapeDialogProps> = ({
const [director, setDirector] = useState<ScrapeResult<string>>(
new ScrapeResult<string>(scene.director, scraped.director)
);
const [studio, setStudio] = useState<ScrapeResult<GQL.ScrapedStudio>>(
new ScrapeResult<GQL.ScrapedStudio>(
const [studio, setStudio] = useState<ObjectScrapeResult<GQL.ScrapedStudio>>(
new ObjectScrapeResult<GQL.ScrapedStudio>(
sceneStudio
? {
stored_id: sceneStudio.id,
Expand Down
11 changes: 7 additions & 4 deletions ui/v2.5/src/components/Shared/ScrapeDialog/ScrapedObjectsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import {
IHasName,
} from "src/components/Shared/ScrapeDialog/ScrapeDialog";
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 { StudioSelect } from "src/components/Studios/StudioSelect";

interface IScrapedStudioRow {
title: string;
result: ScrapeResult<GQL.ScrapedStudio>;
onChange: (value: ScrapeResult<GQL.ScrapedStudio>) => void;
result: ObjectScrapeResult<GQL.ScrapedStudio>;
onChange: (value: ObjectScrapeResult<GQL.ScrapedStudio>) => void;
newStudio?: GQL.ScrapedStudio;
onCreateNew?: (value: GQL.ScrapedStudio) => void;
}
Expand All @@ -26,7 +29,7 @@ export const ScrapedStudioRow: React.FC<IScrapedStudioRow> = ({
onCreateNew,
}) => {
function renderScrapedStudio(
scrapeResult: ScrapeResult<GQL.ScrapedStudio>,
scrapeResult: ObjectScrapeResult<GQL.ScrapedStudio>,
isNew?: boolean,
onChangeFn?: (value: GQL.ScrapedStudio) => void
) {
Expand Down
8 changes: 5 additions & 3 deletions ui/v2.5/src/components/Shared/ScrapeDialog/createObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useStudioCreate,
useTagCreate,
} from "src/core/StashService";
import { ScrapeResult } from "./scrapeResult";
import { ObjectScrapeResult, ScrapeResult } from "./scrapeResult";
import { useIntl } from "react-intl";
import { scrapedPerformerToCreateInput } from "src/core/performers";
import { scrapedMovieToCreateInput } from "src/core/movies";
Expand Down Expand Up @@ -41,8 +41,10 @@ function useCreateObject<T>(
}

interface IUseCreateNewStudioProps {
scrapeResult: ScrapeResult<GQL.ScrapedStudio>;
setScrapeResult: (scrapeResult: ScrapeResult<GQL.ScrapedStudio>) => void;
scrapeResult: ObjectScrapeResult<GQL.ScrapedStudio>;
setScrapeResult: (
scrapeResult: ObjectScrapeResult<GQL.ScrapedStudio>
) => void;
setNewObject: (newObject: GQL.ScrapedStudio | undefined) => void;
}

Expand Down
17 changes: 17 additions & 0 deletions ui/v2.5/src/components/Shared/ScrapeDialog/scrapeResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return values.some((r) => r.scraped);
}
Loading