Skip to content

Commit

Permalink
Fix scene marker form resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
DingDongSoLong4 committed Jul 27, 2023
1 parent a0986f8 commit c676ffb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ui/v2.5/src/components/Scenes/SceneDetails/SceneMarkerForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useMemo } from "react";
import { Button, Form } from "react-bootstrap";
import { FormattedMessage } from "react-intl";
import { useFormik } from "formik";
Expand Down Expand Up @@ -40,12 +40,16 @@ export const SceneMarkerForm: React.FC<ISceneMarkerForm> = ({
tag_ids: yup.array(yup.string().required()).defined(),
});

const initialValues = {
title: marker?.title ?? "",
seconds: marker?.seconds ?? Math.round(getPlayerPosition() ?? 0),
primary_tag_id: marker?.primary_tag.id ?? "",
tag_ids: marker?.tags.map((tag) => tag.id) ?? [],
};
// useMemo to only run getPlayerPosition when the input marker actually changes
const initialValues = useMemo(
() => ({
title: marker?.title ?? "",
seconds: marker?.seconds ?? Math.round(getPlayerPosition() ?? 0),
primary_tag_id: marker?.primary_tag.id ?? "",
tag_ids: marker?.tags.map((tag) => tag.id) ?? [],
}),
[marker]
);

type InputValues = yup.InferType<typeof schema>;

Expand Down

0 comments on commit c676ffb

Please sign in to comment.