XPlane objecte können wegebt und per rechts-click gelöscht werden
This commit is contained in:
@@ -117,7 +117,7 @@ export const MissionForm = () => {
|
||||
resolver: zodResolver(MissionOptionalDefaultsSchema),
|
||||
defaultValues: defaultFormValues,
|
||||
});
|
||||
const { missionFormValues, setOpen } = usePannelStore((state) => state);
|
||||
const { missionFormValues, setOpen, setMissionFormValues } = usePannelStore((state) => state);
|
||||
|
||||
const validationRequired =
|
||||
HPGValidationRequired(
|
||||
@@ -156,6 +156,21 @@ export const MissionForm = () => {
|
||||
}
|
||||
}, [missionFormValues, form, defaultFormValues]);
|
||||
|
||||
// Sync form state to store (avoid infinity loops by using watch)
|
||||
useEffect(() => {
|
||||
const subscription = form.watch((values) => {
|
||||
// Only update store if values actually changed to prevent loops
|
||||
const currentStoreValues = JSON.stringify(missionFormValues);
|
||||
const newFormValues = JSON.stringify(values);
|
||||
|
||||
if (currentStoreValues !== newFormValues) {
|
||||
setMissionFormValues(values as MissionOptionalDefaults);
|
||||
}
|
||||
});
|
||||
|
||||
return () => subscription.unsubscribe();
|
||||
}, [form, setMissionFormValues, missionFormValues]);
|
||||
|
||||
const saveMission = async (
|
||||
mission: MissionOptionalDefaults,
|
||||
{ alertWhenValid = false, createNewMission = false } = {},
|
||||
@@ -449,7 +464,11 @@ export const MissionForm = () => {
|
||||
setSearchElements([]); // Reset search elements
|
||||
setEditingMission(null);
|
||||
setContextMenu(null);
|
||||
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
||||
if (editingMissionId) {
|
||||
toast.success(`Einsatz ${newMission.publicId} bearbeitet`);
|
||||
} else {
|
||||
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
||||
}
|
||||
form.reset();
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
@@ -474,7 +493,11 @@ export const MissionForm = () => {
|
||||
|
||||
setSearchElements([]); // Reset search elements
|
||||
setContextMenu(null);
|
||||
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
||||
if (editingMissionId) {
|
||||
toast.success(`Einsatz ${newMission.publicId} bearbeitet`);
|
||||
} else {
|
||||
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
||||
}
|
||||
form.reset();
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user