mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Use new studio selector in movie scrape dialog (#4692)
This commit is contained in:
@@ -228,6 +228,7 @@ export const MovieEditPanel: React.FC<IMovieEditPanel> = ({
|
|||||||
return (
|
return (
|
||||||
<MovieScrapeDialog
|
<MovieScrapeDialog
|
||||||
movie={currentMovie}
|
movie={currentMovie}
|
||||||
|
movieStudio={studio}
|
||||||
scraped={scrapedMovie}
|
scraped={scrapedMovie}
|
||||||
onClose={(m) => {
|
onClose={(m) => {
|
||||||
onScrapeDialogClosed(m);
|
onScrapeDialogClosed(m);
|
||||||
|
|||||||
@@ -5,66 +5,20 @@ import {
|
|||||||
ScrapeDialog,
|
ScrapeDialog,
|
||||||
ScrapedInputGroupRow,
|
ScrapedInputGroupRow,
|
||||||
ScrapedImageRow,
|
ScrapedImageRow,
|
||||||
ScrapeDialogRow,
|
|
||||||
ScrapedTextAreaRow,
|
ScrapedTextAreaRow,
|
||||||
} from "src/components/Shared/ScrapeDialog/ScrapeDialog";
|
} from "src/components/Shared/ScrapeDialog/ScrapeDialog";
|
||||||
import { StudioSelect } from "src/components/Shared/Select";
|
|
||||||
import TextUtils from "src/utils/text";
|
import TextUtils from "src/utils/text";
|
||||||
import { useStudioCreate } from "src/core/StashService";
|
import {
|
||||||
import { useToast } from "src/hooks/Toast";
|
ObjectScrapeResult,
|
||||||
import { ScrapeResult } from "src/components/Shared/ScrapeDialog/scrapeResult";
|
ScrapeResult,
|
||||||
|
} from "src/components/Shared/ScrapeDialog/scrapeResult";
|
||||||
function renderScrapedStudio(
|
import { Studio } from "src/components/Studios/StudioSelect";
|
||||||
result: ScrapeResult<string>,
|
import { useCreateScrapedStudio } from "src/components/Shared/ScrapeDialog/createObjects";
|
||||||
isNew?: boolean,
|
import { ScrapedStudioRow } from "src/components/Shared/ScrapeDialog/ScrapedObjectsRow";
|
||||||
onChange?: (value: string) => void
|
|
||||||
) {
|
|
||||||
const resultValue = isNew ? result.newValue : result.originalValue;
|
|
||||||
const value = resultValue ? [resultValue] : [];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StudioSelect
|
|
||||||
className="form-control react-select"
|
|
||||||
isDisabled={!isNew}
|
|
||||||
onSelect={(items) => {
|
|
||||||
if (onChange) {
|
|
||||||
onChange(items[0]?.id);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
ids={value}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderScrapedStudioRow(
|
|
||||||
result: ScrapeResult<string>,
|
|
||||||
onChange: (value: ScrapeResult<string>) => void,
|
|
||||||
newStudio?: GQL.ScrapedStudio,
|
|
||||||
onCreateNew?: (value: GQL.ScrapedStudio) => void
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
<ScrapeDialogRow
|
|
||||||
title="Studio"
|
|
||||||
result={result}
|
|
||||||
renderOriginalField={() => renderScrapedStudio(result)}
|
|
||||||
renderNewField={() =>
|
|
||||||
renderScrapedStudio(result, true, (value) =>
|
|
||||||
onChange(result.cloneWithValue(value))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onChange={onChange}
|
|
||||||
newValues={newStudio ? [newStudio] : undefined}
|
|
||||||
onCreateNew={() => {
|
|
||||||
if (onCreateNew && newStudio) {
|
|
||||||
onCreateNew(newStudio);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IMovieScrapeDialogProps {
|
interface IMovieScrapeDialogProps {
|
||||||
movie: Partial<GQL.MovieUpdateInput>;
|
movie: Partial<GQL.MovieUpdateInput>;
|
||||||
|
movieStudio: Studio | null;
|
||||||
scraped: GQL.ScrapedMovie;
|
scraped: GQL.ScrapedMovie;
|
||||||
|
|
||||||
onClose: (scrapedMovie?: GQL.ScrapedMovie) => void;
|
onClose: (scrapedMovie?: GQL.ScrapedMovie) => void;
|
||||||
@@ -99,10 +53,15 @@ export const MovieScrapeDialog: React.FC<IMovieScrapeDialogProps> = (
|
|||||||
const [synopsis, setSynopsis] = useState<ScrapeResult<string>>(
|
const [synopsis, setSynopsis] = useState<ScrapeResult<string>>(
|
||||||
new ScrapeResult<string>(props.movie.synopsis, props.scraped.synopsis)
|
new ScrapeResult<string>(props.movie.synopsis, props.scraped.synopsis)
|
||||||
);
|
);
|
||||||
const [studio, setStudio] = useState<ScrapeResult<string>>(
|
const [studio, setStudio] = useState<ObjectScrapeResult<GQL.ScrapedStudio>>(
|
||||||
new ScrapeResult<string>(
|
new ObjectScrapeResult<GQL.ScrapedStudio>(
|
||||||
props.movie.studio_id,
|
props.movieStudio
|
||||||
props.scraped.studio?.stored_id
|
? {
|
||||||
|
stored_id: props.movieStudio.id,
|
||||||
|
name: props.movieStudio.name,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
props.scraped.studio?.stored_id ? props.scraped.studio : undefined
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const [url, setURL] = useState<ScrapeResult<string>>(
|
const [url, setURL] = useState<ScrapeResult<string>>(
|
||||||
@@ -121,35 +80,12 @@ export const MovieScrapeDialog: React.FC<IMovieScrapeDialogProps> = (
|
|||||||
: undefined
|
: undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
const [createStudio] = useStudioCreate();
|
const createNewStudio = useCreateScrapedStudio({
|
||||||
|
scrapeResult: studio,
|
||||||
const Toast = useToast();
|
setScrapeResult: setStudio,
|
||||||
|
setNewObject: setNewStudio,
|
||||||
async function createNewStudio(toCreate: GQL.ScrapedStudio) {
|
|
||||||
try {
|
|
||||||
const result = await createStudio({
|
|
||||||
variables: {
|
|
||||||
input: {
|
|
||||||
name: toCreate.name,
|
|
||||||
url: toCreate.url,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// set the new studio as the value
|
|
||||||
setStudio(studio.cloneWithValue(result.data!.studioCreate!.id));
|
|
||||||
setNewStudio(undefined);
|
|
||||||
|
|
||||||
Toast.success(
|
|
||||||
<span>
|
|
||||||
Created studio: <b>{toCreate.name}</b>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
Toast.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const allFields = [
|
const allFields = [
|
||||||
name,
|
name,
|
||||||
aliases,
|
aliases,
|
||||||
@@ -170,7 +106,7 @@ export const MovieScrapeDialog: React.FC<IMovieScrapeDialogProps> = (
|
|||||||
|
|
||||||
// todo: reenable
|
// todo: reenable
|
||||||
function makeNewScrapedItem(): GQL.ScrapedMovie {
|
function makeNewScrapedItem(): GQL.ScrapedMovie {
|
||||||
const newVal = studio.getNewValue();
|
const newStudioValue = studio.getNewValue();
|
||||||
const durationString = duration.getNewValue();
|
const durationString = duration.getNewValue();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -180,12 +116,7 @@ export const MovieScrapeDialog: React.FC<IMovieScrapeDialogProps> = (
|
|||||||
date: date.getNewValue(),
|
date: date.getNewValue(),
|
||||||
director: director.getNewValue(),
|
director: director.getNewValue(),
|
||||||
synopsis: synopsis.getNewValue(),
|
synopsis: synopsis.getNewValue(),
|
||||||
studio: newVal
|
studio: newStudioValue,
|
||||||
? {
|
|
||||||
stored_id: newVal,
|
|
||||||
name: "",
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
url: url.getNewValue(),
|
url: url.getNewValue(),
|
||||||
front_image: frontImage.getNewValue(),
|
front_image: frontImage.getNewValue(),
|
||||||
back_image: backImage.getNewValue(),
|
back_image: backImage.getNewValue(),
|
||||||
@@ -226,12 +157,13 @@ export const MovieScrapeDialog: React.FC<IMovieScrapeDialogProps> = (
|
|||||||
result={synopsis}
|
result={synopsis}
|
||||||
onChange={(value) => setSynopsis(value)}
|
onChange={(value) => setSynopsis(value)}
|
||||||
/>
|
/>
|
||||||
{renderScrapedStudioRow(
|
<ScrapedStudioRow
|
||||||
studio,
|
title={intl.formatMessage({ id: "studios" })}
|
||||||
(value) => setStudio(value),
|
result={studio}
|
||||||
newStudio,
|
onChange={(value) => setStudio(value)}
|
||||||
createNewStudio
|
newStudio={newStudio}
|
||||||
)}
|
onCreateNew={createNewStudio}
|
||||||
|
/>
|
||||||
<ScrapedInputGroupRow
|
<ScrapedInputGroupRow
|
||||||
title="URL"
|
title="URL"
|
||||||
result={url}
|
result={url}
|
||||||
|
|||||||
Reference in New Issue
Block a user