Skip to content

Conversation

@atomisu0312
Copy link
Contributor

間取りエディタにおいて、tool関連のStateをJotaiライブラリ管理に置き換えました。
これにより、selectedToolそのものや、それを操作する関数をPropsで渡す必要がなくなりました。

エディタ上で差分を確認すると次のようになっています。
image

コンポーネントから操作したい場合は次のようにカスタムフック経由でstateや関数を取得できます。
例:front/src/components/organisms/event/venueedit/tools/ToolButtonGroup.tsx
Propsがなくても状態を管理することができます。

image

以下、コミットメッセージのコピーです。

  • Jotaiライブラリのインストール
  • toolやtoolに関するアクションをpropから除外し、Jotaiライブラリが管理するように修正
  • front/src/store/event/venueedit/tool.tsでStateやdispatchを管理し、useSubToolSelectionフック経由で各コンポーネントから状態を取得&操作できるように
  • isTextTool(selectedTool)のような冗長な関数呼び出しではなく、変数としてそのまま使えるように(isDrawingToolやisPixelToolも同様)

- Jotaiライブラリのインストール
- toolやtoolに関するアクションをpropから除外し、Jotaiライブラリが管理するように修正
- front/src/store/event/venueedit/tool.tsでStateやdispatchを管理し、useSubToolSelectionフック経由で各コンポーネントから状態を取得&操作できるように
- isTextTool(selectedTool)のような冗長な関数呼び出しではなく、変数としてそのまま使えるように(isDrawingToolやisPixelToolも同様)

This comment was marked as outdated.

@atomisu0312 atomisu0312 requested a review from Copilot July 29, 2025 15:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors tool-related state management in the venue editor from React's useState to Jotai library, eliminating the need to pass selectedTool and its manipulation functions through props.

  • Introduces centralized state management for tool selection using Jotai atoms
  • Removes prop drilling by providing tool state and actions through a custom hook
  • Simplifies component interfaces by removing tool-related props

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
front/package.json Adds Jotai library dependency
front/src/store/event/venueedit/tool.ts Implements Jotai atoms for tool state management with action-based updates
front/src/hooks/event/venueedit/useSubToolSelection.ts Refactors hook to use Jotai atoms and adds memoized tool type checks
front/src/hooks/event/venueedit/useCanvasDraw.ts Removes selectedTool prop dependency
front/src/hooks/event/venueedit/tool/useToolSelect.ts Gets selectedTool from custom hook instead of props
front/src/components/templates/event/venueedit/*.tsx Removes tool-related props from template components
front/src/components/organisms/event/venueedit/tools/ToolButtonGroup.tsx Uses hook for tool state instead of props
front/src/components/organisms/event/venueedit/palette/*.tsx Removes tool-related props and uses hook for state access
Files not reviewed (1)
  • front/package-lock.json: Language not supported

| { type: 'SET_DRAW_TOOL'; toolKey: EditorToolPairKey };

// 状態を保持するプライベートなベースatom
const _selectedToolAtom = atom<VenueEditTool>('ピクセル塗りつぶし');
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default tool value 'ピクセル塗りつぶし' is a magic string. Consider defining this as a constant to improve maintainability and prevent typos.

Suggested change
const _selectedToolAtom = atom<VenueEditTool>('ピクセル塗りつぶし');
const _selectedToolAtom = atom<VenueEditTool>(DEFAULT_TOOL);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応済み

Comment on lines +33 to +34
// isDrawingToolはselectedToolに依存し、その結果をメモ化する
const isDrawingTool = useMemo(() => _isDrawingTool(selectedTool), [selectedTool]);
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The useMemo for isDrawingTool may be unnecessary overhead. Simple boolean checks like _isDrawingTool(selectedTool) are typically fast enough that memoization adds more complexity than benefit.

Suggested change
// isDrawingToolはselectedToolに依存し、その結果をメモ化する
const isDrawingTool = useMemo(() => _isDrawingTool(selectedTool), [selectedTool]);
// isDrawingToolはselectedToolに依存し、その結果を直接計算する
const isDrawingTool = _isDrawingTool(selectedTool);

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +40
// isPixelToolはselectedToolに依存し、その結果をメモ化する
const isPixelTool = useMemo(() => (PIXEL_TOOLS as readonly string[]).includes(selectedTool), [selectedTool]);
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The useMemo for isPixelTool may be unnecessary overhead. Simple array includes operations are typically fast enough that memoization adds more complexity than benefit.

Suggested change
// isPixelToolはselectedToolに依存し、その結果をメモ化する
const isPixelTool = useMemo(() => (PIXEL_TOOLS as readonly string[]).includes(selectedTool), [selectedTool]);
// isPixelToolはselectedToolに依存する
const isPixelTool = (PIXEL_TOOLS as readonly string[]).includes(selectedTool);

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +43
// isTextToolはselectedToolに依存し、その結果をメモ化する
const isTextTool = useMemo(() => (TEXT_TOOLS as readonly string[]).includes(selectedTool), [selectedTool]);
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The useMemo for isTextTool may be unnecessary overhead. Simple array includes operations are typically fast enough that memoization adds more complexity than benefit.

Suggested change
// isTextToolはselectedToolに依存し、その結果をメモ化する
const isTextTool = useMemo(() => (TEXT_TOOLS as readonly string[]).includes(selectedTool), [selectedTool]);
// isTextToolはselectedToolに依存する
const isTextTool = (TEXT_TOOLS as readonly string[]).includes(selectedTool);

Copilot uses AI. Check for mistakes.
- ハードコーディング部分の修正
@atomisu0312 atomisu0312 merged commit 0b8e3e5 into develop Aug 5, 2025
2 checks passed
@atomisu0312
Copy link
Contributor Author

セルフマージしました

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants