import { ActionIcon, Center, Group, Stack, Text, TextInput, ThemeIcon } from '@mantine/core'; import { IconRefresh, IconSearch, IconVariable, IconVariableOff } from '@tabler/icons-react'; import { __, sprintf } from '@wordpress/i18n'; import { DataTable } from 'mantine-datatable'; import { useMemo, useState } from 'react'; import useSWR from 'swr'; import { post } from '../../utils/post'; export function Shortcode() { const { data, isLoading, isValidating, mutate } = useSWR('shortcode', post); const [search, setSearch] = useState(''); const filtered = useMemo(() => { if (!data) { return []; } if (!search) { return data; } const q = search.toLowerCase(); return data.filter((r: { name: string }) => r.name.toLowerCase().includes(q)); }, [data, search]); return ( } value={search} onChange={(e) => setSearch(e.currentTarget.value)} style={{ width: 250 }} /> {sprintf( // translators: %d: number of shortcodes listed. __('Total: %d', 'scotty'), filtered.length )} {search && data && ` / ${data.length}`} ), }, { accessor: 'callable', width: 100, textAlign: 'center', render: (record) => (
{record.callable ? : }
), footer: ( { await mutate(); }} > ), }, ]} />
); }