-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 migration (partial). #1671
Changes from all commits
943a219
f35ed4d
bb092d9
e8a8b9a
1b483df
858633f
b03b42f
016b510
9e533b4
f4a7c75
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ export default function ConfigServer() { | |
let currentUrl = useServerURL(); | ||
let setServerUrl = useSetServerURL(); | ||
useEffect(() => { | ||
setUrl(currentUrl); | ||
setUrl(currentUrl || ''); | ||
}, [currentUrl]); | ||
let [loading, setLoading] = useState(false); | ||
let [error, setError] = useState<string | null>(null); | ||
|
@@ -77,15 +77,15 @@ export default function ConfigServer() { | |
} | ||
|
||
async function onSkip() { | ||
await setServerUrl(null); | ||
await setServerUrl(''); | ||
await loggedIn(); | ||
navigate('/'); | ||
} | ||
|
||
async function onCreateTestFile() { | ||
await setServerUrl(null); | ||
await setServerUrl(''); | ||
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. Same here |
||
await createBudget({ testMode: true }); | ||
window.__navigate('/'); | ||
window.__navigate?.('/'); | ||
} | ||
|
||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,11 @@ import { ConfirmPasswordForm } from './ConfirmPasswordForm'; | |
|
||
export default function Bootstrap() { | ||
let dispatch = useDispatch(); | ||
let [error, setError] = useState(null); | ||
let [error, setError] = useState<string | null>(null); | ||
|
||
let { checked } = useBootstrapped(); | ||
|
||
function getErrorMessage(error) { | ||
function getErrorMessage(error: string) { | ||
switch (error) { | ||
case 'invalid-password': | ||
return 'Password cannot be empty'; | ||
|
@@ -34,7 +34,7 @@ export default function Bootstrap() { | |
} | ||
} | ||
|
||
async function onSetPassword(password) { | ||
async function onSetPassword(password: string) { | ||
setError(null); | ||
let { error } = await send('subscribe-bootstrap', { password }); | ||
|
||
|
@@ -94,7 +94,7 @@ export default function Bootstrap() { | |
</Button> | ||
} | ||
onSetPassword={onSetPassword} | ||
onError={setError} | ||
onError={err => setError(err)} | ||
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. 🥜 nitpick: I don't think this change is necessary |
||
/> | ||
</View> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ import { ConfirmPasswordForm } from './ConfirmPasswordForm'; | |
|
||
export default function ChangePassword() { | ||
let navigate = useNavigate(); | ||
let [error, setError] = useState(null); | ||
let [msg, setMessage] = useState(null); | ||
let [error, setError] = useState<string | null>(null); | ||
let [msg, setMessage] = useState<string | null>(null); | ||
|
||
function getErrorMessage(error) { | ||
function getErrorMessage(error: string) { | ||
switch (error) { | ||
case 'invalid-password': | ||
return 'Password cannot be empty'; | ||
|
@@ -29,7 +29,7 @@ export default function ChangePassword() { | |
} | ||
} | ||
|
||
async function onSetPassword(password) { | ||
async function onSetPassword(password: string) { | ||
setError(null); | ||
let { error } = await send('subscribe-change-password', { password }); | ||
|
||
|
@@ -93,7 +93,7 @@ export default function ChangePassword() { | |
</Button> | ||
} | ||
onSetPassword={onSetPassword} | ||
onError={setError} | ||
onError={err => setError(err)} | ||
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. Same here |
||
/> | ||
</View> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ import View from '../common/View'; | |
|
||
type ItemContentProps = { | ||
style: CSSProperties; | ||
to: string; | ||
onClick: MouseEventHandler<HTMLDivElement>; | ||
to?: string; | ||
onClick?: MouseEventHandler<HTMLDivElement>; | ||
Comment on lines
+9
to
+10
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. ❓ question: is it that there can be either (very poor naming chosen here intentionally as this is just an example)
|
||
activeStyle: CSSProperties; | ||
children: ReactNode; | ||
forceActive?: boolean; | ||
|
@@ -21,7 +21,7 @@ function ItemContent({ | |
forceActive, | ||
children, | ||
}: ItemContentProps) { | ||
return onClick ? ( | ||
return onClick || !to ? ( | ||
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. 💭 thought: I don't think we need this change. |
||
<View | ||
role="button" | ||
tabIndex={0} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
type MutableRefObject, | ||
type Ref, | ||
type RefCallback, | ||
useMemo, | ||
} from 'react'; | ||
|
||
export function useMergedRefs<T>( | ||
ref1: RefCallback<T> | MutableRefObject<T>, | ||
ref2: RefCallback<T> | MutableRefObject<T>, | ||
): Ref<T> { | ||
return useMemo(() => { | ||
function ref(value: T) { | ||
[ref1, ref2].forEach(ref => { | ||
if (typeof ref === 'function') { | ||
ref(value); | ||
} else if (ref != null) { | ||
ref.current = value; | ||
} | ||
}); | ||
} | ||
|
||
return ref; | ||
}, [ref1, ref2]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import { last, diffItems, applyChanges } from './util'; | ||
import { diffItems, applyChanges } from './util'; | ||
|
||
export function isPreviewId(id) { | ||
return id.indexOf('preview/') !== -1; | ||
|
@@ -164,7 +164,7 @@ export function addSplitTransaction(transactions, id) { | |
if (!trans.is_parent) { | ||
return trans; | ||
} | ||
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. Making |
||
let prevSub = last(trans.subtransactions); | ||
let prevSub = trans.subtransactions[trans.subtransactions.length - 1]; | ||
trans.subtransactions.push( | ||
makeChild(trans, { | ||
amount: 0, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Maintenance | ||
authors: [doggan] | ||
--- | ||
|
||
TypeScript migration and type hardening. |
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.
🔨 warning: we need to keep
null
here.actual/packages/loot-core/src/server/main.ts
Line 1775 in a8a0f77