clean up and refactor open graph
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api/tauri';
|
||||
|
||||
import { getLinkPreview } from '@libs/openGraph';
|
||||
import { Opengraph } from '@utils/types';
|
||||
|
||||
export function useOpenGraph(url: string) {
|
||||
const { status, data, error, isFetching } = useQuery(
|
||||
['preview', url],
|
||||
async () => {
|
||||
const res = await getLinkPreview(url);
|
||||
const res: Opengraph = await invoke('opengraph', { url });
|
||||
if (!res) {
|
||||
throw new Error('fetch preview failed');
|
||||
}
|
||||
|
||||
7
src/utils/types.d.ts
vendored
7
src/utils/types.d.ts
vendored
@@ -62,3 +62,10 @@ export interface Relays {
|
||||
relay: string;
|
||||
purpose?: string;
|
||||
}
|
||||
|
||||
export interface Opengraph {
|
||||
url: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
image?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user