mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 07:03:25 +00:00
refactor: migrate from @izzyjs/route to @tuyau
This commit is contained in:
@@ -1,19 +1,43 @@
|
||||
import { tuyau } from '~/lib/tuyau';
|
||||
import { Collection, Link } from '~/types/app';
|
||||
import { RouteName } from '~/types/tuyau';
|
||||
|
||||
export const appendCollectionId = (
|
||||
url: string,
|
||||
export const routeWithCollectionId = (
|
||||
routeName: RouteName,
|
||||
collectionId?: Collection['id'] | null | undefined
|
||||
) => `${url}${collectionId ? `?collectionId=${collectionId}` : ''}`;
|
||||
) =>
|
||||
buildUrlWithQueryParams(routeName, {
|
||||
collectionId,
|
||||
});
|
||||
|
||||
export const appendLinkId = (
|
||||
url: string,
|
||||
export const routeWithLinkId = (
|
||||
routeName: RouteName,
|
||||
linkId?: Link['id'] | null | undefined
|
||||
) => `${url}${linkId ? `?linkId=${linkId}` : ''}`;
|
||||
) => buildUrlWithQueryParams(routeName, { linkId });
|
||||
|
||||
export const appendResourceId = (
|
||||
url: string,
|
||||
export const routeWithResourceId = (
|
||||
routeName: RouteName,
|
||||
resourceId?: Collection['id'] | Link['id']
|
||||
) => `${url}${resourceId ? `/${resourceId}` : ''}`;
|
||||
) => `${routeName}${resourceId ? `/${resourceId}` : ''}`;
|
||||
|
||||
export function buildUrlWithQueryParams(
|
||||
routeName: RouteName,
|
||||
queryParam: Record<string, string | number | null | undefined>
|
||||
) {
|
||||
const path = tuyau.$route(routeName).path;
|
||||
const [key, value] = Object.entries(queryParam)[0];
|
||||
if (!value) {
|
||||
return path;
|
||||
}
|
||||
|
||||
const searchParams = new URLSearchParams({
|
||||
[key]: value.toString(),
|
||||
});
|
||||
return `${path}?${searchParams}`;
|
||||
}
|
||||
|
||||
export const getRoute = (routeName: RouteName) => tuyau.$route(routeName);
|
||||
export const getPath = (routeName: RouteName) => getRoute(routeName).path;
|
||||
|
||||
export function isValidHttpUrl(urlParam: string) {
|
||||
let url;
|
||||
|
||||
Reference in New Issue
Block a user