Initialer Laravel Commit für BetiX
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
2026-04-04 18:01:50 +02:00
commit 0280278978
374 changed files with 65210 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import type { InertiaLinkProps } from '@inertiajs/vue3';
import { usePage } from '@inertiajs/vue3';
import type { ComputedRef, DeepReadonly } from 'vue';
import { computed, readonly } from 'vue';
import { toUrl } from '@/lib/utils';
export type UseCurrentUrlReturn = {
currentUrl: DeepReadonly<ComputedRef<string>>;
isCurrentUrl: (
urlToCheck: NonNullable<InertiaLinkProps['href']>,
currentUrl?: string,
) => boolean;
whenCurrentUrl: <T, F = null>(
urlToCheck: NonNullable<InertiaLinkProps['href']>,
ifTrue: T,
ifFalse?: F,
) => T | F;
};
const page = usePage();
const currentUrlReactive = computed(
() => new URL(page.url, window?.location.origin).pathname,
);
export function useCurrentUrl(): UseCurrentUrlReturn {
function isCurrentUrl(
urlToCheck: NonNullable<InertiaLinkProps['href']>,
currentUrl?: string,
) {
const urlToCompare = currentUrl ?? currentUrlReactive.value;
const urlString = toUrl(urlToCheck);
if (!urlString.startsWith('http')) {
return urlString === urlToCompare;
}
try {
const absoluteUrl = new URL(urlString);
return absoluteUrl.pathname === urlToCompare;
} catch {
return false;
}
}
function whenCurrentUrl(
urlToCheck: NonNullable<InertiaLinkProps['href']>,
ifTrue: any,
ifFalse: any = null,
) {
return isCurrentUrl(urlToCheck) ? ifTrue : ifFalse;
}
return {
currentUrl: readonly(currentUrlReactive),
isCurrentUrl,
whenCurrentUrl,
};
}