import React, { useMemo, useCallback, useDeferredValue } from 'react' import { MoreOptions } from '@app/components/general/cells/menu/more' import { Link } from '../link' import { WebsiteSecondary } from './render' import { BASE_GQL_URL, STATUS_URL } from '@app/configs/app-config' import { copyClipboard } from '@app/lib' import { PagesBox, LoadTimeBox, HeadersBox, LighthouseBox, StandardBox, IssuesBox, WarningsBox, SitemapBox, MonitoringEnabledBox, } from './blocks' import { MobileBox } from './blocks/mobile' import { Issue, Website } from '@app/types' import { Timer } from '../timer' import { UserAgentBox } from './blocks/user-agent' import { ActionsBox } from './blocks/actions' import { CdnFixBox } from './blocks/cdn-fix' import { useWasmContext } from '@app/components/providers' import { useAuthContext } from '@app/components/providers/auth' import { GrChannel, GrStatusInfo, GrSync, GrValidate } from 'react-icons/gr' import { fetcher } from '@app/utils/fetcher' import { AppManager, HomeManager } from '@app/managers' import { useInteractiveContext } from '@app/components/providers/interactive' import { IssueCard } from './card/issue-card' import { AnalyticsCard } from './card/analytics-card' import { LighthouseCard } from './card/lighthouse-card' import { TLDBox } from './blocks/tld' import { SubDomainsBox } from './blocks/subdomains' import { RobotsBox } from './blocks/robots' import { useWebsiteLiveData } from '@app/data/formatters/use-live-data' import { RunnersBox } from './blocks/runner' import { ProxyBox } from './blocks/proxy' import { Score } from '../blocks/score' import { PageCard } from './card/pages-card' const styles = { title: 'text-xl md:text-3xl font-medium truncate', spacing: 'py-2', row: 'flex flex-1', metaBlock: 'px-2 py-1 border', } interface WebsiteCellProps { index: number crawlWebsite(x: any): Promise removePress(x: any): Promise crawlDuration?: number lighthouseVisible?: boolean activeCrawl?: Record handleClickOpen(data: any, title: any, url: any, error: any): void url: string pageHeaders?: any } interface InteractiveProps extends Partial { linkUrl: string onWebsiteCrawl(x: any): Promise statusBadgeUrl: string } const statusRowClass = 'hover:opacity-70 p-2 rounded text-xs md:text-sm lg:text-lg' const WebsiteInteractiveBlock = ({ url, onWebsiteCrawl, linkUrl, statusBadgeUrl, }: InteractiveProps) => { return (
) } // main dashboard cell with details and paginated views export function WebsiteCellDashboard({ url, removePress, handleClickOpen, pages, issues: currentIssues, issuesInfo, crawlWebsite, pageLoadTime, lastScanDate, pageHeaders, index, domain, online, insight, pageInsights, mobile, lighthouseVisible, standard, activeCrawl, crawlDuration, ua, actions, actionsEnabled, robots, subdomains, tld, shutdown, verified, runners, proxy, sitemap, monitoringEnabled, }: Website & WebsiteCellProps) { const { account } = useAuthContext() // TODO: move to provider top level const { feed } = useWasmContext() const items: Issue[] = useDeferredValue( feed?.get_data_item(domain, !!(tld || subdomains)) ?? [] ) const { setSelectedWebsite, selectedWebsite } = useInteractiveContext() const issues = items.length ? items : currentIssues // real time issue tracking todo: send subscription with issuesInfo [todo: build analytics feed usage] const { errorCount, warningCount, totalIssues, issuesFixedByCdn, liveData } = useWebsiteLiveData({ issues, issuesInfo }) const onRemovePress = useCallback(async () => { if (url === selectedWebsite) { HomeManager.setDashboardView('') setSelectedWebsite('') } try { await removePress({ variables: { url, }, }) } catch (e) { console.error(e) } }, [url, removePress, selectedWebsite, setSelectedWebsite]) const handleMainClick = (eventData?: any, title?: string, _mini?: boolean, url?: string) => async () => { // mini player open - small modal with dynamic content let eventDS = eventData // todo: open modal and set loading afterwards if (title === 'Verify DNS' && url) { eventDS = await fetcher( '/website/dns', { domain: new URL(url).hostname }, 'POST' ) } if (title === 'Website Analytics') { const path = url ? `/list/analytics?limit=10000&domain=${new URL(url).hostname}` : '/list/website?=limit=50' eventDS = await fetcher(path, null, 'GET') } if (handleClickOpen) { handleClickOpen(eventDS, title, url, null) } } const { statusBadgeUrl, linkUrl, domainHost } = useMemo(() => { // TODO: REMOVE ALL URL CLIENT APPENDING const encodedUrl = encodeURIComponent(url) const reportsLink = `${BASE_GQL_URL}/${encodedUrl}` const reportsPageLink = `/reports/${encodedUrl}` // hostname should always be valid - ignore try catching const hostname = url && new URL(url).hostname const badgeUrl = `${STATUS_URL}/${encodeURIComponent(domain)}` return { domainHost: hostname, encodedUrl, reportsLink, reportsPageLink, linkUrl: `/website-details?url=${encodedUrl}`, statusBadgeUrl: `[![A11yWatch](${`${badgeUrl}`})](${reportsLink})`, } }, [domain, url]) const pagecount = issuesInfo?.pageCount || 0 const issueTotal = issuesInfo?.totalIssues || 0 const pageIssueCount = issues && Array.isArray(issues) && issues.length > pagecount ? issues.length : pagecount const { accessScoreAverage: accessScore } = issuesInfo ?? {} const onWebsiteCrawl = useCallback(async () => { AppManager.toggleSnack( true, `Scan in progress, you’ll be notified if new issues occur.`, 'message' ) try { await crawlWebsite({ variables: { url, }, }) } catch (e) {} }, [url, crawlWebsite]) const lhVisible = pageInsights && insight && lighthouseVisible return (
  • {domainHost} issueTotal ? totalIssues : issueTotal, }} pageIssueCount={pageIssueCount} pageLoadTime={pageLoadTime} lastScanDate={lastScanDate} score={accessScore} pageHeaders={pageHeaders} robots={robots} subdomains={subdomains} tld={tld} dashboard online={online} borderLess />
    {verified ? ( ) : null}
    {account.activeSubscription && (issuesInfo || liveData.length) ? ( ) : null}
    {issuesInfo || liveData.length ? (
    ) : null}
    {lhVisible ? (
    ) : null}
  • ) }