fix restore feature

This commit is contained in:
=
2023-03-09 00:12:43 +00:00
parent ae0e494098
commit c7ab043dcc
2 changed files with 6 additions and 13 deletions

View File

@@ -1,13 +1,4 @@
import { fetchCachedProfileEventHistory } from './fetchEvents';
import { generateHistoryTable } from './LoadHistory';
const loadContactsBackupHistory = (RootElementID:string) => {
(document.getElementById(RootElementID) as HTMLDivElement)
.innerHTML = `<div class="contactsbackuphistory">
<h3>Contacts Backup History</h3>
${generateHistoryTable(fetchCachedProfileEventHistory(3))}
</div>`;
};
import { loadBackupHistory } from './LoadHistory';
const LoadContactsPage = () => {
const o:HTMLElement = document.getElementById('PM-container') as HTMLElement;
@@ -16,7 +7,7 @@ const LoadContactsPage = () => {
<div id="contactsbackuphistory"></div>
<div>
`;
loadContactsBackupHistory('contactsbackuphistory');
loadBackupHistory('contactsbackuphistory', 3);
};
export default LoadContactsPage;

View File

@@ -168,11 +168,13 @@ export const generateHistoryTable = (history: Event[] | null):string => {
export const activateRestoreButtons = (history: Event[] | null, afterRestore: ()=> void):void => {
history?.forEach((e, i) => {
if (i === 0) return;
const eid = `restore-${e.kind}-${i}`;
const el = document.getElementById(eid) as HTMLButtonElement;
const el = document.getElementById(eid) as HTMLAnchorElement;
const { id, sig, ...unsigned } = e;
unsigned.created_at = Math.floor(Date.now() / 1000);
el.onclick = async () => {
el.onclick = async (event) => {
event.preventDefault();
const r = await submitUnsignedEvent(unsigned, eid, 'Restored!');
if (r) setTimeout(afterRestore, 1000);
};