Skip to content

Commit

Permalink
add use strategy input POC
Browse files Browse the repository at this point in the history
  • Loading branch information
pingustar committed Jan 23, 2024
1 parent 706c68a commit b3eac0c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/hooks/useStrategyInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useNavigate, useSearch } from '@tanstack/react-router';
import { SimulatorInputSearch } from 'libs/routing/routes/sim';

Check failure on line 2 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

'"libs/routing/routes/sim"' has no exported member named 'SimulatorInputSearch'. Did you mean 'SimulatorSearch'?

Check failure on line 2 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

'"libs/routing/routes/sim"' has no exported member named 'SimulatorInputSearch'. Did you mean 'SimulatorSearch'?

Check failure on line 2 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

'"libs/routing/routes/sim"' has no exported member named 'SimulatorInputSearch'. Did you mean 'SimulatorSearch'?

Check failure on line 2 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

'"libs/routing/routes/sim"' has no exported member named 'SimulatorInputSearch'. Did you mean 'SimulatorSearch'?
import { useState } from 'react';
import { debounce } from 'utils/helpers';

Check failure on line 4 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Module '"utils/helpers"' has no exported member 'debounce'.

Check failure on line 4 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Module '"utils/helpers"' has no exported member 'debounce'.

Check failure on line 4 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Module '"utils/helpers"' has no exported member 'debounce'.

Check failure on line 4 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Module '"utils/helpers"' has no exported member 'debounce'.

export type StrategyInputDispatch = <
T extends SimulatorInputSearch,
K extends keyof T
>(
key: K,
value: T[K]
) => void;

export const useStrategyInput = () => {
const navigate = useNavigate();
const search: SimulatorInputSearch = useSearch({ strict: false });
const [state, setState] = useState(search);

const navigateDebounced = debounce((key: string, value: string) =>
navigate({
search: (search) => ({ ...search, [key]: value }),
params: {},
replace: true,
resetScroll: false,
})
);

const dispatch: StrategyInputDispatch = (key, value) => {
setState((state) => ({ ...state, [key]: value }));

Check failure on line 29 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Parameter 'state' implicitly has an 'any' type.

Check failure on line 29 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Parameter 'state' implicitly has an 'any' type.

Check failure on line 29 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Parameter 'state' implicitly has an 'any' type.

Check failure on line 29 in src/hooks/useStrategyInput.ts

View workflow job for this annotation

GitHub Actions / Build (20.x)

Parameter 'state' implicitly has an 'any' type.
navigateDebounced(key, value);
};

return [state, dispatch] as const;
};

0 comments on commit b3eac0c

Please sign in to comment.