mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
link small fixes
This commit is contained in:
+10
-4
@@ -6,15 +6,15 @@ import type { RouteName } from './routes';
|
||||
|
||||
const PATH_PARAM_REGEXP = /\/\[(\w+)\]/g;
|
||||
|
||||
export function link(routeName: RouteName, urlParams?: Record<string, string | undefined>, queryParams?: Record<string, string>): string {
|
||||
export function link(routeName: RouteName, urlParams?: Record<string, Array<string> | string | undefined>, queryParams?: Record<string, string>): string {
|
||||
const route = ROUTES[routeName];
|
||||
if (!route) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const network = findNetwork({
|
||||
network_type: urlParams?.network_type || '',
|
||||
network_sub_type: urlParams?.network_sub_type,
|
||||
network_type: typeof urlParams?.network_type === 'string' ? urlParams?.network_type : '',
|
||||
network_sub_type: typeof urlParams?.network_sub_type === 'string' ? urlParams?.network_sub_type : undefined,
|
||||
});
|
||||
|
||||
const path = route.pattern.replace(PATH_PARAM_REGEXP, (_, paramName: string) => {
|
||||
@@ -22,7 +22,13 @@ export function link(routeName: RouteName, urlParams?: Record<string, string | u
|
||||
return '';
|
||||
}
|
||||
|
||||
const paramValue = urlParams?.[paramName];
|
||||
let paramValue = urlParams?.[paramName];
|
||||
if (Array.isArray(paramValue)) {
|
||||
// FIXME we don't have yet params as array, but typescript says that we could
|
||||
// dun't know how to manage it, fix me if you find an issue
|
||||
paramValue = paramValue.join(',');
|
||||
}
|
||||
|
||||
return paramValue ? `/${ paramValue }` : '';
|
||||
});
|
||||
|
||||
|
||||
@@ -11,10 +11,6 @@ export default function useLink() {
|
||||
const networkSubType = router.query.network_sub_type;
|
||||
|
||||
return React.useCallback((...args: LinkBuilderParams) => {
|
||||
if (typeof networkType !== 'string' || typeof networkSubType !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return link(args[0], { network_type: networkType, network_sub_type: networkSubType, ...args[1] }, args[2]);
|
||||
}, [ networkType, networkSubType ]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user