feat: support sending and preview links
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { extractUrls, type LinkMetadata } from "@/lib/link-metadata";
|
||||
|
||||
export function useLinkMetadata(url: string | null) {
|
||||
return useQuery<LinkMetadata | null>({
|
||||
queryKey: ["link-metadata", url],
|
||||
queryFn: () => window.electronLink.fetchMetadata(url!),
|
||||
enabled: !!url,
|
||||
staleTime: Infinity,
|
||||
gcTime: 30 * 60 * 1000,
|
||||
retry: 1,
|
||||
});
|
||||
}
|
||||
|
||||
export function useFirstLinkMetadata(text: string) {
|
||||
const urls = extractUrls(text);
|
||||
const firstUrl = urls[0] ?? null;
|
||||
return { ...useLinkMetadata(firstUrl), url: firstUrl };
|
||||
}
|
||||
Reference in New Issue
Block a user