Fix scene edit panel not updating on scene change (#2471)

This commit is contained in:
WithoutPants
2022-04-04 10:31:51 +10:00
committed by GitHub
parent 92320b3418
commit e76e4c978f

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useMemo } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import {
Button,
@@ -107,7 +107,8 @@ export const SceneEditPanel: React.FC<IProps> = ({
stash_ids: yup.mixed<GQL.StashIdInput>().optional().nullable(),
});
const initialValues = {
const initialValues = useMemo(
() => ({
title: scene.title ?? "",
details: scene.details ?? "",
url: scene.url ?? "",
@@ -122,12 +123,15 @@ export const SceneEditPanel: React.FC<IProps> = ({
tag_ids: (scene.tags ?? []).map((t) => t.id),
cover_image: undefined,
stash_ids: getStashIDs(scene.stash_ids),
};
}),
[scene]
);
type InputValues = typeof initialValues;
const formik = useFormik({
initialValues,
enableReinitialize: true,
validationSchema: schema,
onSubmit: (values) => onSave(getSceneInput(values)),
});