Browse Source

add some gates

feature/kind3-ssl-more
dskvr 2 years ago
parent
commit
fcb613c364
  1. 1
      package.json
  2. 44
      src/components/relays/partials/NostrSync.vue
  3. 2
      yarn.lock

1
package.json

@ -34,6 +34,7 @@
"nostr": "0.2.5",
"nostr-relay-inspector": "0.0.25",
"nostr-tools": "1.1.1",
"object-hash": "3.0.0",
"object-sizeof": "1.6.3",
"onion-regex": "2.0.8",
"pinia": "2.0.28",

44
src/components/relays/partials/NostrSync.vue

@ -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),

2
yarn.lock

@ -6497,7 +6497,7 @@ object-assign@^4, object-assign@^4.0.1:
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
object-hash@^3.0.0:
object-hash@3.0.0, object-hash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-3.0.0.tgz#73f97f753e7baffc0e2cc9d6e079079744ac82e9"
integrity sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==

Loading…
Cancel
Save