|
|
@ -1,6 +1,7 @@ |
|
|
|
<template> |
|
|
|
<div class="inline" v-if="store.user.getPublicKey.length"> |
|
|
|
<div class="inline text-left"> |
|
|
|
|
|
|
|
<span v-if="savedSuccess" class="inline-block mr-3"> |
|
|
|
<svg class="h-4 w-4 inline-block" fill="none" stroke="#32CD32" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> |
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path> |
|
|
@ -28,13 +29,19 @@ |
|
|
|
</button> |
|
|
|
|
|
|
|
<button |
|
|
|
:title="!changed ? 'nothing to save' : ''" |
|
|
|
ref="btnRef" |
|
|
|
type="button" |
|
|
|
v-on:click="persistChanges()" |
|
|
|
v-on:click="changed ? persistChanges() : false" |
|
|
|
v-if="this.store.layout.editorExpanded && store.tasks.getActiveSlug !== 'user/relay/list'" |
|
|
|
:class="{ |
|
|
|
'cursor-not-allowed opacity-40': !changed, |
|
|
|
'cursor-pointer': changed |
|
|
|
}" |
|
|
|
class="mr-3 inline-flex items-center justify-center rounded-md border border-transparent bg-white/20 px-4 py-2 text-m font-medium text-white shadow-sm hover:bg-white/40 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:w-auto"> |
|
|
|
Save |
|
|
|
</button> |
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -47,6 +54,7 @@ import safeStringify from 'fast-safe-stringify' |
|
|
|
import { getEventHash, validateEvent, verifySignature } from 'nostr-tools' |
|
|
|
import RelaysLib from '@/shared/relays-lib' |
|
|
|
import { RelayPool } from 'nostr' |
|
|
|
import objHash from 'object-hash' |
|
|
|
|
|
|
|
export default defineComponent({ |
|
|
|
name: "NostrSyncPopoverNag", |
|
|
@ -60,6 +68,8 @@ export default defineComponent({ |
|
|
|
data() { |
|
|
|
return { |
|
|
|
changed: false, |
|
|
|
hashCache: null, |
|
|
|
hashOG: null, |
|
|
|
savedTo: [], |
|
|
|
savedSuccess: null, |
|
|
|
interval: null, |
|
|
@ -68,15 +78,43 @@ export default defineComponent({ |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted(){ |
|
|
|
this.hashOG = objHash(structuredClone(this.store.user.getKind3)) |
|
|
|
this.hashCache = structuredClone(this.hashOG) |
|
|
|
this.store.layout.editorOff() |
|
|
|
this.interval = setInterval( () => { |
|
|
|
if(this.savedTo.length) |
|
|
|
this.savedSuccess = this.savedTo.shift() |
|
|
|
else |
|
|
|
this.savedSuccess = null |
|
|
|
}, 1000) |
|
|
|
|
|
|
|
const hashCurrent = objHash(this.store.user.getKind3), |
|
|
|
hashCache = this.hashCache, |
|
|
|
hashOG = this.hashOG |
|
|
|
|
|
|
|
if(hashCache === hashCurrent) |
|
|
|
return |
|
|
|
|
|
|
|
if(hashOG === hashCurrent ) |
|
|
|
return this.changed = false |
|
|
|
|
|
|
|
console.log('input cache did not match', hashCache) |
|
|
|
|
|
|
|
console.log( |
|
|
|
'changed?', |
|
|
|
this.changed, |
|
|
|
'ok..', |
|
|
|
hashCache, |
|
|
|
objHash(this.store.user.getKind3), |
|
|
|
hashCache == objHash(this.store.user.getKind3) |
|
|
|
) |
|
|
|
|
|
|
|
this.hashCache = objHash(structuredClone(this.store.user.getKind3)) |
|
|
|
this.changed = true |
|
|
|
|
|
|
|
}, 500) |
|
|
|
}, |
|
|
|
unmounted(){ |
|
|
|
clearInterval(this.interval) |
|
|
|
this.store.layout.editorOff() |
|
|
|
}, |
|
|
|
methods: Object.assign(RelaysLib, { |
|
|
@ -100,7 +138,7 @@ export default defineComponent({ |
|
|
|
}, |
|
|
|
true |
|
|
|
) |
|
|
|
}, |
|
|
|
}, |
|
|
|
persistChanges: async function(){ |
|
|
|
const event = { |
|
|
|
created_at: Math.floor(Date.now()/1000), |
|
|
|