mirror of
https://github.com/hanzo-io/team.git
synced 2026-10-30 18:56:23 +00:00
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import { useFrappeGetCall, useFrappePostCall } from 'frappe-react-sdk'
|
|
|
|
export type LinkPreviewDetails = {
|
|
title: string
|
|
description: string
|
|
image: string
|
|
force_title: string
|
|
absolute_image: string
|
|
site_name: string
|
|
}
|
|
|
|
|
|
export const useLinkPreview = (href: string) => {
|
|
const { data, isLoading } = useFrappeGetCall<{ message: LinkPreviewDetails[] }>(
|
|
'raven.api.preview_links.get_preview_link',
|
|
{
|
|
urls: JSON.stringify([href])
|
|
},
|
|
href ? `link_preview_${href}` : null,
|
|
{
|
|
revalidateOnFocus: false,
|
|
revalidateOnReconnect: false,
|
|
shouldRetryOnError: false,
|
|
}
|
|
)
|
|
|
|
return {
|
|
linkPreview: data?.message?.[0],
|
|
isLoading
|
|
}
|
|
|
|
}
|
|
|
|
export const useHideLinkPreview = (messageID: string) => {
|
|
const { call } = useFrappePostCall('raven.api.preview_links.hide_link_preview')
|
|
|
|
const hideLinkPreview = () => {
|
|
call({
|
|
message_id: messageID
|
|
})
|
|
}
|
|
|
|
return hideLinkPreview
|
|
} |