-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[TypeScript] Add types to SpreadsheetProvider #4409
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { useState, useRef, useLayoutEffect, useMemo } from 'react'; | ||
|
||
import { useSpreadsheet } from 'loot-core/client/SpreadsheetProvider'; | ||
import { type Query } from 'loot-core/shared/query'; | ||
|
||
import { useSheetName } from './useSheetName'; | ||
|
||
|
@@ -18,7 +17,6 @@ type SheetValueResult< | |
> = { | ||
name: string; | ||
value: Spreadsheets[SheetName][FieldName] | null; | ||
query?: Query; | ||
}; | ||
|
||
export function useSheetValue< | ||
|
@@ -42,7 +40,6 @@ export function useSheetValue< | |
const [result, setResult] = useState<SheetValueResult<SheetName, FieldName>>({ | ||
name: fullSheetName, | ||
value: bindingObj.value ? bindingObj.value : null, | ||
query: bindingObj.query, | ||
}); | ||
const latestOnChange = useRef(onChange); | ||
latestOnChange.current = onChange; | ||
|
@@ -53,23 +50,25 @@ export function useSheetValue< | |
useLayoutEffect(() => { | ||
let isMounted = true; | ||
|
||
const unbind = spreadsheet.bind( | ||
sheetName, | ||
bindingObj, | ||
(newResult: SheetValueResult<SheetName, FieldName>) => { | ||
if (!isMounted) { | ||
return; | ||
} | ||
const unbind = spreadsheet.bind(sheetName, bindingObj, newResult => { | ||
if (!isMounted) { | ||
return; | ||
} | ||
|
||
if (latestOnChange.current) { | ||
latestOnChange.current(newResult); | ||
} | ||
const newCastedResult = { | ||
name: newResult.name, | ||
// TODO: Spreadsheets, SheetNames, SheetFields, etc must be moved to the loot-core package | ||
value: newResult.value as Spreadsheets[SheetName][FieldName], | ||
}; | ||
Comment on lines
+58
to
+62
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. 💡 Verification agent 🧩 Analysis chainConsider moving type definitions to improve code organization. The TODO comment indicates that type definitions should be moved to the loot-core package. This would improve code organization and make types more accessible across the project. Let's verify the current location of type definitions: 🏁 Script executed: #!/bin/bash
# Search for type definitions across the codebase
rg -t typescript "type (Spreadsheets|SheetNames|SheetFields)" -g '!dist' -g '!node_modules' Length of output: 128 I've noticed that the initial search command failed because of an unrecognized file type. To gather more reliable information we should rerun the search using a glob that targets TypeScript files. For example: Once you verify where these type definitions are currently declared (or if they're even declared here), please confirm whether they might benefit from being centralized in the loot-core package as suggested by the TODO comment. Action: Verify the location of the type definitions for Spreadsheets, SheetNames, and SheetFields, and consider migrating them into the loot-core package for improved organization and reusability.
🏁 Script executed: [run_scripts]
#!/bin/bash
# Corrected search for type definitions across TypeScript files in the codebase
rg "type\s+(Spreadsheets|SheetNames|SheetFields)" -g "*.{ts,tsx}" -g '!dist' -g '!node_modules' Length of output: 2241 Consolidate Spreadsheet Type Definitions Across Packages
|
||
|
||
if (newResult.value !== latestValue.current) { | ||
setResult(newResult); | ||
} | ||
}, | ||
); | ||
if (latestOnChange.current) { | ||
latestOnChange.current(newCastedResult); | ||
} | ||
|
||
if (newResult.value !== latestValue.current) { | ||
setResult(newCastedResult); | ||
} | ||
}); | ||
|
||
return () => { | ||
isMounted = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Maintenance | ||
authors: [MikesGlitch] | ||
joel-jeremy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
[TypeScript] Add types for SpreadsheetProvider |
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.
Replaced with useSheetValue which does the same thing