import { Popover } from '@blueprintjs/core'; import React from 'react'; import ReactDOM from 'react-dom/client'; import { QueryClient, QueryClientProvider, useQuery } from 'react-query'; import TimeAgo from 'timeago-react'; import { InfoDialog } from 'vj/components/dialog'; import { AutoloadPage } from 'vj/misc/Page'; import { i18n, request, tpl } from 'vj/utils'; async function historyDialog(payload, time, uid) { const ts = new Date(time).getTime(); const rawHtml = await fetch(`${payload}?time=${ts}&render=1`).then((res) => res.text()); new InfoDialog({ $body: tpl`

${uid}
${i18n('Edited at')} ${time}

${{ templateRaw: true, html: rawHtml }}
`, }).open(); } const queryClient = new QueryClient(); function History({ payload }) { const [load, setLoad] = React.useState(false); const { isLoading, isError, data } = useQuery(['history', payload], async () => { const { history } = await request.get(`${payload}?all=1`); return history; }, { enabled: !!load }); return ( setLoad(true)}> {i18n('Edited')}
    {(isLoading || isError) && (
  1. {isLoading ? i18n('Loading...') : i18n('Loading failed.')}
  2. )} {data?.map((item) => (
  3. historyDialog(payload, item.time, item.uid)}> {i18n('Edited at')} {' '}
  4. ))}
); } const page = new AutoloadPage('discussionHistoryPage', () => { $('[data-discussion-history]').each((i, e) => { const url = $(e).data('raw-url'); if (!url) return; ReactDOM.createRoot(e).render( , ); }); }); export default page;