mirror of
https://github.com/aljazceru/nostr-profile-manager.git
synced 2025-12-17 05:34:20 +01:00
fix restore feature
This commit is contained in:
@@ -1,13 +1,4 @@
|
|||||||
import { fetchCachedProfileEventHistory } from './fetchEvents';
|
import { loadBackupHistory } from './LoadHistory';
|
||||||
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>`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const LoadContactsPage = () => {
|
const LoadContactsPage = () => {
|
||||||
const o:HTMLElement = document.getElementById('PM-container') as HTMLElement;
|
const o:HTMLElement = document.getElementById('PM-container') as HTMLElement;
|
||||||
@@ -16,7 +7,7 @@ const LoadContactsPage = () => {
|
|||||||
<div id="contactsbackuphistory"></div>
|
<div id="contactsbackuphistory"></div>
|
||||||
<div>
|
<div>
|
||||||
`;
|
`;
|
||||||
loadContactsBackupHistory('contactsbackuphistory');
|
loadBackupHistory('contactsbackuphistory', 3);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LoadContactsPage;
|
export default LoadContactsPage;
|
||||||
|
|||||||
@@ -168,11 +168,13 @@ export const generateHistoryTable = (history: Event[] | null):string => {
|
|||||||
|
|
||||||
export const activateRestoreButtons = (history: Event[] | null, afterRestore: ()=> void):void => {
|
export const activateRestoreButtons = (history: Event[] | null, afterRestore: ()=> void):void => {
|
||||||
history?.forEach((e, i) => {
|
history?.forEach((e, i) => {
|
||||||
|
if (i === 0) return;
|
||||||
const eid = `restore-${e.kind}-${i}`;
|
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;
|
const { id, sig, ...unsigned } = e;
|
||||||
unsigned.created_at = Math.floor(Date.now() / 1000);
|
unsigned.created_at = Math.floor(Date.now() / 1000);
|
||||||
el.onclick = async () => {
|
el.onclick = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
const r = await submitUnsignedEvent(unsigned, eid, 'Restored!');
|
const r = await submitUnsignedEvent(unsigned, eid, 'Restored!');
|
||||||
if (r) setTimeout(afterRestore, 1000);
|
if (r) setTimeout(afterRestore, 1000);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user