Skip to content

Commit

Permalink
Rename NatureStatsEditor component
Browse files Browse the repository at this point in the history
  • Loading branch information
Palbolsky committed Sep 11, 2024
1 parent ac16e3d commit 618e662
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions assets/i18n/en/database_natures.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"new": "New nature",
"delete": "Delete this nature",
"deleting": "Deleting",
"stats": "Statistics",
"changing_stats": "Changing statistics",
"changing_stat_atk": "Attack",
"changing_stat_dfe": "Defense",
Expand Down
1 change: 1 addition & 0 deletions assets/i18n/fr/database_natures.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"new": "Nouvelle nature",
"delete": "Supprimer cette nature",
"deleting": "Suppression",
"stats": "Statistiques",
"changing_stats": "Modification des statistiques",
"changing_stat_atk": "Attaque",
"changing_stat_dfe": "Défense",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { defineEditorOverlay } from '@components/editor/EditorOverlayV2';
import { assertUnreachable } from '@utils/assertUnreachable';
import { DialogRefData } from '@hooks/useDialogsRef';
import { NatureChangingStatsEditor, NatureDeletion, NatureFlavorsEditor, NatureFrameEditor, NatureNewEditor } from '.';
import { NatureDeletion, NatureFlavorsEditor, NatureFrameEditor, NatureNewEditor, NatureStatsEditor } from '.';

export type NatureEditorAndDeletionKeys = 'new' | 'frame' | 'stats' | 'flavors' | 'deletion';
export type NatureDialogsRef = React.RefObject<DialogRefData<NatureEditorAndDeletionKeys>>;
Expand All @@ -20,7 +20,7 @@ export const NatureEditorOverlay = defineEditorOverlay<NatureEditorAndDeletionKe
case 'frame':
return <NatureFrameEditor ref={handleCloseRef} />;
case 'stats':
return <NatureChangingStatsEditor ref={handleCloseRef} />;
return <NatureStatsEditor ref={handleCloseRef} />;
case 'flavors':
return <NatureFlavorsEditor ref={handleCloseRef} />;
case 'deletion':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { useUpdateNature } from './useUpdateNature';
import { EditorHandlingClose, useEditorHandlingClose } from '@components/editor/useHandleCloseEditor';
import { useZodForm } from '@hooks/useZodForm';
import { useInputAttrsWithLabel } from '@hooks/useInputAttrs';
import { InputContainer, InputFormContainer } from '@components/inputs/InputContainer';
import { InputFormContainer } from '@components/inputs/InputContainer';
import { z } from 'zod';
import { NATURE_VALIDATOR, STUDIO_NATURE_STATS_LIST, StudioNature, StudioNatureStats } from '@modelEntities/nature';
import { cloneEntity } from '@utils/cloneEntity';

const CHANGING_STATS_EDITOR_SCHEMA = NATURE_VALIDATOR.extend({
const STATS_EDITOR_SCHEMA = NATURE_VALIDATOR.extend({
stats: z.object({
atk: z.number().min(-99).max(899),
dfe: z.number().min(-99).max(899),
Expand All @@ -33,12 +33,12 @@ const updateStatsForNatureEntity = (stats: StudioNatureStats) => {
return clonedStats;
};

export const NatureChangingStatsEditor = forwardRef<EditorHandlingClose>((_, ref) => {
export const NatureStatsEditor = forwardRef<EditorHandlingClose>((_, ref) => {
const { t } = useTranslation('database_natures');
const { nature } = useNaturePage();
const updateNature = useUpdateNature(nature);
const { canClose, getFormData, onInputTouched, defaults, formRef } = useZodForm(CHANGING_STATS_EDITOR_SCHEMA, updateStatsForEditor(nature));
const { EmbeddedUnitInput } = useInputAttrsWithLabel(CHANGING_STATS_EDITOR_SCHEMA, defaults);
const { canClose, getFormData, onInputTouched, defaults, formRef } = useZodForm(STATS_EDITOR_SCHEMA, updateStatsForEditor(nature));
const { EmbeddedUnitInput } = useInputAttrsWithLabel(STATS_EDITOR_SCHEMA, defaults);

const onClose = () => {
const result = canClose() && getFormData();
Expand All @@ -50,7 +50,7 @@ export const NatureChangingStatsEditor = forwardRef<EditorHandlingClose>((_, ref
useEditorHandlingClose(ref, onClose, canClose);

return (
<Editor type="edit" title={t('changing_stats')}>
<Editor type="edit" title={t('stats')}>
<InputFormContainer ref={formRef} size="xs">
{STUDIO_NATURE_STATS_LIST.map((stat) => (
<EmbeddedUnitInput
Expand All @@ -65,4 +65,4 @@ export const NatureChangingStatsEditor = forwardRef<EditorHandlingClose>((_, ref
</Editor>
);
});
NatureChangingStatsEditor.displayName = 'NatureChangingStatsEditor';
NatureStatsEditor.displayName = 'NatureStatsEditor';
4 changes: 2 additions & 2 deletions src/views/components/database/nature/editors/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { NatureChangingStatsEditor } from './NatureChangingStatsEditor';
export { NatureDeletion } from './NatureDeletion';
export { NatureFlavorsEditor } from './NatureFlavorsEditor';
export { NatureFrameEditor } from './NatureFrameEditor';
export { NatureNewEditor } from './NatureNewEditor';
export { NatureDeletion } from './NatureDeletion';
export { NatureStatsEditor } from './NatureStatsEditor';

0 comments on commit 618e662

Please sign in to comment.