Skip to content

Commit 33014af

Browse files
committed
fix: refactor navigateToEntity function for improved readability and maintainability
1 parent 492293e commit 33014af

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/modules/search/SearcherBar.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,22 @@ export function SearcherBar({ className }: { className?: string }) {
2525
slug: string,
2626
value: string
2727
) => {
28-
const entityToRoute: Record<string, string> = {
28+
const route = Object.entries({
2929
deal: 'deal',
3030
task: 'task',
3131
dataset: 'dataset',
3232
app: 'app',
3333
workerpool: 'workerpool',
3434
account: 'address',
3535
transaction: 'tx',
36-
};
36+
}).find(([entityKey]) => data[entityKey]);
3737

38-
for (const [entityKey, routePath] of Object.entries(entityToRoute)) {
39-
if (data[entityKey]) {
40-
navigate({ to: `/${slug}/${routePath}/${value}` });
41-
return;
42-
}
38+
if (route) {
39+
const [, routePath] = route;
40+
navigate({ to: `/${slug}/${routePath}/${value}` });
41+
} else {
42+
throw new Error('An error occurred please try again');
4343
}
44-
throw new Error('An error occurred please try again');
4544
};
4645

4746
const { mutate, isPending, isError, error } = useMutation({

0 commit comments

Comments
 (0)