-
Notifications
You must be signed in to change notification settings - Fork 4
Fix linter errors #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8303db
refactor(MainCanvas, useDragPreview): improve variable declarations a…
eloiberlinger1 7ad403d
refactor(SidebarHoldsSection): simplify state initialization for curr…
eloiberlinger1 1100f5b
refactor(EditorApp, Sidebar, SidebarHoldsSection): optimize state man…
eloiberlinger1 e1cbd28
Introduced HoldType, HoldModel, SessionData, SessionHoldInstance in …
eloiberlinger1 c742c26
refactor(useHoldAvailabilityValidation): enhance type safety and impr…
eloiberlinger1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,19 +5,19 @@ import HandleAddHold from "../utils/HandleAddHold"; | |||||
| import { useEditorAuth } from "../mocks/useEditorAuth"; | ||||||
| import PaginationList from "../stubs/PaginationList"; | ||||||
| import { useTranslation } from "react-i18next"; | ||||||
| import type { HoldModel, SessionData } from "../store"; | ||||||
|
|
||||||
| type HoldModel = { | ||||||
| name: string; | ||||||
| file: string; | ||||||
| hold_type: Record<string, any>; | ||||||
| hold_instance_id: string; | ||||||
| id?: string; | ||||||
| type StockItem = { | ||||||
| id: string | number; | ||||||
| hold_type: { id: string | number; cdn_ref?: string; [key: string]: unknown }; | ||||||
| model?: string; | ||||||
| [key: string]: unknown; | ||||||
| }; | ||||||
|
|
||||||
| interface AddHoldModalProps { | ||||||
| isOpen: boolean; | ||||||
| onClose: () => void; | ||||||
| session_data: any; | ||||||
| session_data: SessionData; | ||||||
| onHoldAdded: (hold: HoldModel) => void; | ||||||
| currentHolds: HoldModel[]; | ||||||
| } | ||||||
|
|
@@ -32,7 +32,7 @@ export default function AddHoldModal({ | |||||
| const [search, setSearch] = useState(""); | ||||||
| const [isAdding, setIsAdding] = useState(false); | ||||||
| const scrollRef = useRef<HTMLElement>(null); | ||||||
| const [addedHoldIds, setAddedHoldIds] = useState<Set<number>>(new Set()); | ||||||
| const [addedHoldIds, setAddedHoldIds] = useState<Set<string | number>>(new Set()); | ||||||
| const { user, authenticatedFetch } = useEditorAuth(); | ||||||
| const [page, setPage] = useState(1); | ||||||
| const API_URL = import.meta.env.VITE_API_BASE; | ||||||
|
|
@@ -97,7 +97,7 @@ export default function AddHoldModal({ | |||||
| ); | ||||||
|
|
||||||
| const deduplicatedStockData = Array.isArray(rawStockData) | ||||||
| ? rawStockData.reduce((acc: any[], current: any) => { | ||||||
| ? rawStockData.reduce((acc: StockItem[], current: StockItem) => { | ||||||
| const exists = acc.find( | ||||||
| (hold) => hold.hold_type.id === current.hold_type.id | ||||||
| ); | ||||||
|
|
@@ -108,24 +108,25 @@ export default function AddHoldModal({ | |||||
|
|
||||||
| const stockData = Array.isArray(deduplicatedStockData) | ||||||
| ? deduplicatedStockData.filter( | ||||||
| (hold: any) => | ||||||
| (hold: StockItem) => | ||||||
| !currentHoldTypeIds.has(hold.hold_type.id) && | ||||||
| !addedHoldIds.has(hold.hold_type.id) | ||||||
| !addedHoldIds.has(hold.hold_type.id as number) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type cast
Suggested change
|
||||||
| ) | ||||||
| : deduplicatedStockData; | ||||||
|
|
||||||
| const filteredStockData = Array.isArray(stockData) | ||||||
| ? stockData.filter((hold: any) => { | ||||||
| ? stockData.filter((hold: StockItem) => { | ||||||
| if (!search) return true; | ||||||
| const searchLower = search.toLowerCase(); | ||||||
| const manufacturerName = hold.hold_type?.manufacturer_name as string | undefined; | ||||||
| return ( | ||||||
| hold.model?.toLowerCase().includes(searchLower) || | ||||||
| hold.hold_type?.manufacturer_name?.toLowerCase().includes(searchLower) | ||||||
| manufacturerName?.toLowerCase().includes(searchLower) | ||||||
| ); | ||||||
| }) | ||||||
| : stockData; | ||||||
|
|
||||||
| const handleAddHoldClick = async (hold: any) => { | ||||||
| const handleAddHoldClick = async (hold: StockItem) => { | ||||||
| setIsAdding(true); | ||||||
| try { | ||||||
| const result = await HandleAddHold(hold, session_data, onHoldAdded); | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mutating the
holdobject directly insideuseMemois a side effect that should be avoided. Sincesession_datalikely comes from a cache (e.g., TanStack Query), mutating its contents can lead to unexpected behavior in other parts of the application or when the data is re-read from the cache. It is better to create a new object with the added property to maintain immutability.