/* eslint-disable react-refresh/only-export-components */ import { MantineProvider, Popover } from '@mantine/core'; import React from 'react'; import ReactDOM from 'react-dom/client'; 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(); } function History({ payload }) { const [load, setLoad] = React.useState(false); const [data, setData] = React.useState([]); const [isLoading, setLoading] = React.useState(true); const [error, setError] = React.useState(''); React.useEffect(() => { if (!load) return; setLoading(true); request.get(`${payload}?all=1`).then(({ history }) => { setData(history); }).catch((e) => { setError(e.message); }).finally(() => { setLoading(false); }); }, [load]); return setLoad(true)}> {i18n('Edited')}
    {(isLoading || error) && (
  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;