mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Use changesets correctly when updating objects (#976)
This commit is contained in:
@@ -29,7 +29,7 @@ export const EditGalleriesDialog: React.FC<IListOperationProps> = (
|
||||
);
|
||||
const [tagIds, setTagIds] = useState<string[]>();
|
||||
|
||||
const [updateGalleries] = useBulkGalleryUpdate(getGalleryInput());
|
||||
const [updateGalleries] = useBulkGalleryUpdate();
|
||||
|
||||
// Network state
|
||||
const [isUpdating, setIsUpdating] = useState(false);
|
||||
@@ -61,8 +61,8 @@ export const EditGalleriesDialog: React.FC<IListOperationProps> = (
|
||||
if (rating === undefined) {
|
||||
// and all galleries have the same rating, then we are unsetting the rating.
|
||||
if (aggregateRating) {
|
||||
// an undefined rating is ignored in the server, so set it to 0 instead
|
||||
galleryInput.rating = 0;
|
||||
// null to unset rating
|
||||
galleryInput.rating = null;
|
||||
}
|
||||
// otherwise not setting the rating
|
||||
} else {
|
||||
@@ -75,8 +75,8 @@ export const EditGalleriesDialog: React.FC<IListOperationProps> = (
|
||||
// and all galleries have the same studioId,
|
||||
// then unset the studioId, otherwise ignoring studioId
|
||||
if (aggregateStudioId) {
|
||||
// an undefined studio_id is ignored in the server, so set it to empty string instead
|
||||
galleryInput.studio_id = "";
|
||||
// null to unset studio_id
|
||||
galleryInput.studio_id = null;
|
||||
}
|
||||
} else {
|
||||
// if studioId is set, then we are setting it
|
||||
@@ -125,7 +125,11 @@ export const EditGalleriesDialog: React.FC<IListOperationProps> = (
|
||||
async function onSave() {
|
||||
setIsUpdating(true);
|
||||
try {
|
||||
await updateGalleries();
|
||||
await updateGalleries({
|
||||
variables: {
|
||||
input: getGalleryInput(),
|
||||
},
|
||||
});
|
||||
Toast.success({ content: "Updated galleries" });
|
||||
props.onClose(true);
|
||||
} catch (e) {
|
||||
|
||||
@@ -63,9 +63,7 @@ export const GalleryEditPanel: React.FC<
|
||||
const [createGallery] = useGalleryCreate(
|
||||
getGalleryInput() as GQL.GalleryCreateInput
|
||||
);
|
||||
const [updateGallery] = useGalleryUpdate(
|
||||
getGalleryInput() as GQL.GalleryUpdateInput
|
||||
);
|
||||
const [updateGallery] = useGalleryUpdate();
|
||||
|
||||
useEffect(() => {
|
||||
if (props.isVisible) {
|
||||
@@ -135,8 +133,8 @@ export const GalleryEditPanel: React.FC<
|
||||
details,
|
||||
url,
|
||||
date,
|
||||
rating,
|
||||
studio_id: studioId,
|
||||
rating: rating ?? null,
|
||||
studio_id: studioId ?? null,
|
||||
performer_ids: performerIds,
|
||||
tag_ids: tagIds,
|
||||
};
|
||||
@@ -152,7 +150,11 @@ export const GalleryEditPanel: React.FC<
|
||||
Toast.success({ content: "Created gallery" });
|
||||
}
|
||||
} else {
|
||||
const result = await updateGallery();
|
||||
const result = await updateGallery({
|
||||
variables: {
|
||||
input: getGalleryInput() as GQL.GalleryUpdateInput,
|
||||
},
|
||||
});
|
||||
if (result.data?.galleryUpdate) {
|
||||
Toast.success({ content: "Updated gallery" });
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export const EditImagesDialog: React.FC<IListOperationProps> = (
|
||||
);
|
||||
const [tagIds, setTagIds] = useState<string[]>();
|
||||
|
||||
const [updateImages] = useBulkImageUpdate(getImageInput());
|
||||
const [updateImages] = useBulkImageUpdate();
|
||||
|
||||
// Network state
|
||||
const [isUpdating, setIsUpdating] = useState(false);
|
||||
@@ -61,8 +61,8 @@ export const EditImagesDialog: React.FC<IListOperationProps> = (
|
||||
if (rating === undefined) {
|
||||
// and all images have the same rating, then we are unsetting the rating.
|
||||
if (aggregateRating) {
|
||||
// an undefined rating is ignored in the server, so set it to 0 instead
|
||||
imageInput.rating = 0;
|
||||
// null rating to unset it
|
||||
imageInput.rating = null;
|
||||
}
|
||||
// otherwise not setting the rating
|
||||
} else {
|
||||
@@ -75,8 +75,8 @@ export const EditImagesDialog: React.FC<IListOperationProps> = (
|
||||
// and all images have the same studioId,
|
||||
// then unset the studioId, otherwise ignoring studioId
|
||||
if (aggregateStudioId) {
|
||||
// an undefined studio_id is ignored in the server, so set it to empty string instead
|
||||
imageInput.studio_id = "";
|
||||
// null studio_id to unset it
|
||||
imageInput.studio_id = null;
|
||||
}
|
||||
} else {
|
||||
// if studioId is set, then we are setting it
|
||||
@@ -125,7 +125,11 @@ export const EditImagesDialog: React.FC<IListOperationProps> = (
|
||||
async function onSave() {
|
||||
setIsUpdating(true);
|
||||
try {
|
||||
await updateImages();
|
||||
await updateImages({
|
||||
variables: {
|
||||
input: getImageInput(),
|
||||
},
|
||||
});
|
||||
Toast.success({ content: "Updated images" });
|
||||
props.onClose(true);
|
||||
} catch (e) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export const ImageEditPanel: React.FC<IProps> = (props: IProps) => {
|
||||
// Network state
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const [updateImage] = useImageUpdate(getImageInput());
|
||||
const [updateImage] = useImageUpdate();
|
||||
|
||||
useEffect(() => {
|
||||
if (props.isVisible) {
|
||||
@@ -95,8 +95,8 @@ export const ImageEditPanel: React.FC<IProps> = (props: IProps) => {
|
||||
return {
|
||||
id: props.image.id,
|
||||
title,
|
||||
rating,
|
||||
studio_id: studioId,
|
||||
rating: rating ?? null,
|
||||
studio_id: studioId ?? null,
|
||||
performer_ids: performerIds,
|
||||
tag_ids: tagIds,
|
||||
};
|
||||
@@ -105,7 +105,11 @@ export const ImageEditPanel: React.FC<IProps> = (props: IProps) => {
|
||||
async function onSave() {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const result = await updateImage();
|
||||
const result = await updateImage({
|
||||
variables: {
|
||||
input: getImageInput(),
|
||||
},
|
||||
});
|
||||
if (result.data?.imageUpdate) {
|
||||
Toast.success({ content: "Updated image" });
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export const Movie: React.FC = () => {
|
||||
// Network state
|
||||
const { data, error, loading } = useFindMovie(id);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [updateMovie] = useMovieUpdate(getMovieInput() as GQL.MovieUpdateInput);
|
||||
const [updateMovie] = useMovieUpdate();
|
||||
const [createMovie] = useMovieCreate(getMovieInput() as GQL.MovieCreateInput);
|
||||
const [deleteMovie] = useMovieDestroy(
|
||||
getMovieInput() as GQL.MovieDestroyInput
|
||||
@@ -201,8 +201,8 @@ export const Movie: React.FC = () => {
|
||||
aliases,
|
||||
duration,
|
||||
date,
|
||||
rating,
|
||||
studio_id: studioId,
|
||||
rating: rating ?? null,
|
||||
studio_id: studioId ?? null,
|
||||
director,
|
||||
synopsis,
|
||||
url,
|
||||
@@ -219,7 +219,11 @@ export const Movie: React.FC = () => {
|
||||
async function onSave() {
|
||||
try {
|
||||
if (!isNew) {
|
||||
const result = await updateMovie();
|
||||
const result = await updateMovie({
|
||||
variables: {
|
||||
input: getMovieInput() as GQL.MovieUpdateInput,
|
||||
},
|
||||
});
|
||||
if (result.data?.movieUpdate) {
|
||||
updateMovieData(result.data.movieUpdate);
|
||||
setIsEditing(false);
|
||||
|
||||
@@ -111,12 +111,14 @@ export const Performer: React.FC = () => {
|
||||
if (!isNew) {
|
||||
await updatePerformer({
|
||||
variables: {
|
||||
...performerInput,
|
||||
stash_ids: (performerInput?.stash_ids ?? []).map((s) => ({
|
||||
endpoint: s.endpoint,
|
||||
stash_id: s.stash_id,
|
||||
})),
|
||||
} as GQL.PerformerUpdateInput,
|
||||
input: {
|
||||
...performerInput,
|
||||
stash_ids: performerInput?.stash_ids?.map((s) => ({
|
||||
endpoint: s.endpoint,
|
||||
stash_id: s.stash_id,
|
||||
})),
|
||||
} as GQL.PerformerUpdateInput,
|
||||
},
|
||||
});
|
||||
if (performerInput.image) {
|
||||
// Refetch image to bust browser cache
|
||||
@@ -215,7 +217,10 @@ export const Performer: React.FC = () => {
|
||||
}
|
||||
|
||||
function setFavorite(v: boolean) {
|
||||
onSave({ ...performer, favorite: v });
|
||||
onSave({
|
||||
id: performer.id,
|
||||
favorite: v,
|
||||
});
|
||||
}
|
||||
|
||||
const renderIcons = () => (
|
||||
|
||||
@@ -61,8 +61,8 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
|
||||
if (rating === undefined) {
|
||||
// and all scenes have the same rating, then we are unsetting the rating.
|
||||
if (aggregateRating) {
|
||||
// an undefined rating is ignored in the server, so set it to 0 instead
|
||||
sceneInput.rating = 0;
|
||||
// null rating unsets it
|
||||
sceneInput.rating = null;
|
||||
}
|
||||
// otherwise not setting the rating
|
||||
} else {
|
||||
@@ -75,8 +75,8 @@ export const EditScenesDialog: React.FC<IListOperationProps> = (
|
||||
// and all scenes have the same studioId,
|
||||
// then unset the studioId, otherwise ignoring studioId
|
||||
if (aggregateStudioId) {
|
||||
// an undefined studio_id is ignored in the server, so set it to empty string instead
|
||||
sceneInput.studio_id = "";
|
||||
// null studio_id unsets it
|
||||
sceneInput.studio_id = null;
|
||||
}
|
||||
} else {
|
||||
// if studioId is set, then we are setting it
|
||||
|
||||
@@ -194,9 +194,9 @@ export const SceneEditPanel: React.FC<IProps> = (props: IProps) => {
|
||||
details,
|
||||
url,
|
||||
date,
|
||||
rating,
|
||||
gallery_id: galleryId,
|
||||
studio_id: studioId,
|
||||
rating: rating ?? null,
|
||||
gallery_id: galleryId ?? null,
|
||||
studio_id: studioId ?? null,
|
||||
performer_ids: performerIds,
|
||||
movies: makeMovieInputs(),
|
||||
tag_ids: tagIds,
|
||||
|
||||
@@ -51,9 +51,7 @@ export const Studio: React.FC = () => {
|
||||
const [imagePreview, setImagePreview] = useState<string | null>();
|
||||
|
||||
const { data, error, loading } = useFindStudio(id);
|
||||
const [updateStudio] = useStudioUpdate(
|
||||
getStudioInput() as GQL.StudioUpdateInput
|
||||
);
|
||||
const [updateStudio] = useStudioUpdate();
|
||||
const [createStudio] = useStudioCreate(
|
||||
getStudioInput() as GQL.StudioCreateInput
|
||||
);
|
||||
@@ -118,8 +116,8 @@ export const Studio: React.FC = () => {
|
||||
const input: Partial<GQL.StudioCreateInput | GQL.StudioUpdateInput> = {
|
||||
name,
|
||||
url,
|
||||
parent_id: parentStudioId,
|
||||
image,
|
||||
parent_id: parentStudioId ?? null,
|
||||
image: image ?? null,
|
||||
};
|
||||
|
||||
if (!isNew) {
|
||||
@@ -131,7 +129,11 @@ export const Studio: React.FC = () => {
|
||||
async function onSave() {
|
||||
try {
|
||||
if (!isNew) {
|
||||
const result = await updateStudio();
|
||||
const result = await updateStudio({
|
||||
variables: {
|
||||
input: getStudioInput() as GQL.StudioUpdateInput,
|
||||
},
|
||||
});
|
||||
if (result.data?.studioUpdate) {
|
||||
updateStudioData(result.data.studioUpdate);
|
||||
setIsEditing(false);
|
||||
|
||||
@@ -279,27 +279,26 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
|
||||
|
||||
const sceneUpdateResult = await updateScene({
|
||||
variables: {
|
||||
id: stashScene.id ?? "",
|
||||
title: scene.title,
|
||||
details: scene.details,
|
||||
date: scene.date,
|
||||
performer_ids: performerIDs.filter((id) => id !== "Skip") as string[],
|
||||
studio_id: studioID,
|
||||
cover_image: imgData,
|
||||
url: scene.url,
|
||||
tag_ids: updatedTags,
|
||||
rating: stashScene.rating,
|
||||
movies: stashScene.movies.map((m) => ({
|
||||
movie_id: m.movie.id,
|
||||
scene_index: m.scene_index,
|
||||
})),
|
||||
stash_ids: [
|
||||
...(stashScene?.stash_ids ?? []),
|
||||
{
|
||||
endpoint,
|
||||
stash_id: scene.stash_id,
|
||||
},
|
||||
],
|
||||
input: {
|
||||
id: stashScene.id ?? "",
|
||||
title: scene.title,
|
||||
details: scene.details,
|
||||
date: scene.date,
|
||||
performer_ids: performerIDs.filter(
|
||||
(id) => id !== "Skip"
|
||||
) as string[],
|
||||
studio_id: studioID,
|
||||
cover_image: imgData,
|
||||
url: scene.url,
|
||||
tag_ids: updatedTags,
|
||||
stash_ids: [
|
||||
...(stashScene?.stash_ids ?? []),
|
||||
{
|
||||
endpoint,
|
||||
stash_id: scene.stash_id,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -12,11 +12,13 @@ export const useUpdatePerformerStashID = () => {
|
||||
) =>
|
||||
updatePerformer({
|
||||
variables: {
|
||||
id: performerID,
|
||||
stash_ids: stashIDs.map((s) => ({
|
||||
stash_id: s.stash_id,
|
||||
endpoint: s.endpoint,
|
||||
})),
|
||||
input: {
|
||||
id: performerID,
|
||||
stash_ids: stashIDs.map((s) => ({
|
||||
stash_id: s.stash_id,
|
||||
endpoint: s.endpoint,
|
||||
})),
|
||||
},
|
||||
},
|
||||
update: (store, updatedPerformer) => {
|
||||
if (!updatedPerformer.data?.performerUpdate) return;
|
||||
@@ -117,12 +119,13 @@ export const useUpdateStudioStashID = () => {
|
||||
) =>
|
||||
updateStudio({
|
||||
variables: {
|
||||
id: studio.id,
|
||||
parent_id: studio.parent_studio?.id,
|
||||
stash_ids: stashIDs.map((s) => ({
|
||||
stash_id: s.stash_id,
|
||||
endpoint: s.endpoint,
|
||||
})),
|
||||
input: {
|
||||
id: studio.id,
|
||||
stash_ids: stashIDs.map((s) => ({
|
||||
stash_id: s.stash_id,
|
||||
endpoint: s.endpoint,
|
||||
})),
|
||||
},
|
||||
},
|
||||
update: (store, result) => {
|
||||
if (!result.data?.studioUpdate) return;
|
||||
|
||||
@@ -47,7 +47,7 @@ export const Tag: React.FC = () => {
|
||||
const [imagePreview, setImagePreview] = useState<string>();
|
||||
|
||||
const { data, error, loading } = useFindTag(id);
|
||||
const [updateTag] = useTagUpdate(getTagInput() as GQL.TagUpdateInput);
|
||||
const [updateTag] = useTagUpdate();
|
||||
const [createTag] = useTagCreate(getTagInput() as GQL.TagUpdateInput);
|
||||
const [deleteTag] = useTagDestroy(getTagInput() as GQL.TagUpdateInput);
|
||||
|
||||
@@ -127,7 +127,11 @@ export const Tag: React.FC = () => {
|
||||
async function onSave() {
|
||||
try {
|
||||
if (!isNew) {
|
||||
const result = await updateTag();
|
||||
const result = await updateTag({
|
||||
variables: {
|
||||
input: getTagInput() as GQL.TagUpdateInput,
|
||||
},
|
||||
});
|
||||
if (result.data?.tagUpdate) {
|
||||
updateTagData(result.data.tagUpdate);
|
||||
setIsEditing(false);
|
||||
|
||||
Reference in New Issue
Block a user