import { Component, createSignal, For, Show } from "solid-js"; import { DANBOORU_API, booru_post, iqdb_search, saucenao_search, tweet_search } from "./api"; import { DanboIcon, IqdbIcon, SauceIcon, GrapeCatIcon } from './Icons'; import { click_out_directive } from "./helper"; type GrapeSearchParams = { media_url:string[], id:string, username: string } // Typescript strips this directive if we don't // force call it in this module const clickOutside = click_out_directive export function GrapeSearch({media_url,id, username}:GrapeSearchParams) { const [showTooltip, setShowTooltip] = createSignal(false); const [ShowDanboResult, setShowDanboResult] = createSignal(false); const [danboPostID, setPostID ] = createSignal(0); const [posts, setPosts] = createSignal>([]) const booru_check = async (e:MouseEvent) => { //console.debug({id,username}) //console.debug({event:e}); const ico = e.target as HTMLImageElement; ico.classList.add('otis-icon-loading'); ico.classList.remove('otis-icon-noresult'); const res = await tweet_search(id,username) ico.classList.remove('otis-icon-loading'); if ( res.length == 0 ) { ico.classList.add('otis-icon-noresult'); ico.title = "Can't find any post based on Tweet ID." return console.debug("grape: none") } setPosts(res) if ( res.length === 1 ) setShowDanboResult(true) else setShowTooltip(true) } const iqdb_check = async (e:MouseEvent) => { const ico = e.target as HTMLImageElement; ico.classList.add('otis-icon-loading'); ico.classList.remove('otis-icon-noresult'); // TODO: handle which image to check const res = await iqdb_search(media_url[0]) ico.classList.remove('otis-icon-loading'); if ( res.length == 0 ) { ico.classList.add('otis-icon-noresult'); ico.title = "No relevant image search results from IQDB" return console.debug("iqdb: none"); } setPosts(res) if ( res.length === 1 ) setShowDanboResult(true) else setShowTooltip(true) } const sauce_check = async (e:MouseEvent) => { const ico = e.target as HTMLImageElement; ico.classList.add('otis-icon-loading'); ico.classList.remove('otis-icon-noresult'); // TODO: handle which image to check const res = await saucenao_search(media_url[0]); ico.classList.remove('otis-icon-loading'); if ( res.length == 0 ) { ico.classList.add('otis-icon-noresult'); ico.title = "No relevant image search results from IQDB" return console.debug("sauce: none"); } setPosts(res) if ( res.length === 1 ) setShowDanboResult(true) else setShowTooltip(true) } const DanboPostsResult = () => ( <> setShowTooltip(true)}> {`#${posts()[0]?.id}`} ) return ( <> }>
setShowTooltip(false)} hidden={!showTooltip()}> { (post) => window.open(`${DANBOORU_API}/posts/${post.id}`,'_blank')}>
#{post.id}
{post.source_domain}
{ post.img_width >= 0 ? `${post.img_width} x ${post.img_height}` : ""}
}
) }