diff --git a/app/components/nostr-connect.gjs b/app/components/nostr-connect.gjs new file mode 100644 index 0000000..4e3340f --- /dev/null +++ b/app/components/nostr-connect.gjs @@ -0,0 +1,81 @@ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +import { inject as service } from '@ember/service'; +import { on } from '@ember/modifier'; +import { eq } from 'ember-truth-helpers'; + +export default class NostrConnectComponent extends Component { + @service nostrAuth; + + get hasExtension() { + return typeof window !== 'undefined' && typeof window.nostr !== 'undefined'; + } + + @action + async connectExtension() { + try { + await this.nostrAuth.login('extension'); + if (this.args.onConnect) { + this.args.onConnect(); + } + } catch (e) { + console.error(e); + alert(e.message); + } + } + + @action + async connectApp() { + try { + await this.nostrAuth.login('connect'); + if (this.args.onConnect) { + this.args.onConnect(); + } + } catch (e) { + console.error(e); + alert(e.message); + } + } + + +} diff --git a/app/components/place-details.gjs b/app/components/place-details.gjs index df4d88b..309a516 100644 --- a/app/components/place-details.gjs +++ b/app/components/place-details.gjs @@ -10,6 +10,7 @@ import Icon from '../components/icon'; import PlaceEditForm from './place-edit-form'; import PlaceListsManager from './place-lists-manager'; import PlacePhotoUpload from './place-photo-upload'; +import NostrConnect from './nostr-connect'; import Modal from './modal'; import { tracked } from '@glimmer/tracking'; @@ -17,16 +18,22 @@ import { action } from '@ember/object'; export default class PlaceDetails extends Component { @service storage; + @service nostrAuth; @tracked isEditing = false; @tracked showLists = false; @tracked isPhotoUploadModalOpen = false; + @tracked isNostrConnectModalOpen = false; @action openPhotoUploadModal(e) { if (e) { e.preventDefault(); } - this.isPhotoUploadModalOpen = true; + if (!this.nostrAuth.isConnected) { + this.isNostrConnectModalOpen = true; + } else { + this.isPhotoUploadModalOpen = true; + } } @action @@ -34,6 +41,17 @@ export default class PlaceDetails extends Component { this.isPhotoUploadModalOpen = false; } + @action + closeNostrConnectModal() { + this.isNostrConnectModalOpen = false; + } + + @action + onNostrConnected() { + this.isNostrConnectModalOpen = false; + this.isPhotoUploadModalOpen = true; + } + get isSaved() { return this.storage.isPlaceSaved(this.place.id || this.place.osmId); } @@ -518,7 +536,7 @@ export default class PlaceDetails extends Component { {{#if this.osmUrl}} -
+

@@ -527,7 +545,7 @@ export default class PlaceDetails extends Component {

-
+
{{/if}} @@ -536,5 +554,11 @@ export default class PlaceDetails extends Component { {{/if}} + + {{#if this.isNostrConnectModalOpen}} + + + + {{/if}} } diff --git a/app/components/place-photo-upload.gjs b/app/components/place-photo-upload.gjs index d65337a..5617df3 100644 --- a/app/components/place-photo-upload.gjs +++ b/app/components/place-photo-upload.gjs @@ -22,16 +22,6 @@ export default class PlacePhotoUpload extends Component { return this.place.title || 'this place'; } - @action - async login() { - try { - this.error = ''; - await this.nostrAuth.login(); - } catch (e) { - this.error = e.message; - } - } - @action async uploadPhoto(event) { event.preventDefault(); @@ -133,36 +123,25 @@ export default class PlacePhotoUpload extends Component { {{/if}} - {{#if this.nostrAuth.isConnected}} -
- Connected: - {{this.nostrAuth.pubkey}} -
- -
- {{#if this.photoUrl}} -
-

Photo Preview:

- Preview -
- - {{else}} - - {{/if}} -
- {{else}} - - {{/if}} +
+ {{#if this.photoUrl}} +
+

Photo Preview:

+ Preview +
+ + {{else}} + + {{/if}} +
} diff --git a/app/components/user-menu.gjs b/app/components/user-menu.gjs index 84b9f85..da3fec6 100644 --- a/app/components/user-menu.gjs +++ b/app/components/user-menu.gjs @@ -1,11 +1,11 @@ import Component from '@glimmer/component'; import { action } from '@ember/object'; -import { service } from '@ember/service'; +import { inject as service } from '@ember/service'; import Icon from '#components/icon'; import { on } from '@ember/modifier'; import { tracked } from '@glimmer/tracking'; -import { eq } from 'ember-truth-helpers'; import Modal from './modal'; +import NostrConnect from './nostr-connect'; export default class UserMenuComponent extends Component { @service storage; @@ -46,37 +46,11 @@ export default class UserMenuComponent extends Component { this.isNostrConnectModalOpen = false; } - @action - async connectNostrExtension() { - try { - await this.nostrAuth.login('extension'); - this.closeNostrConnectModal(); - } catch (e) { - console.error(e); - alert(e.message); - } - } - - @action - async connectNostrApp() { - try { - await this.nostrAuth.login('connect'); - this.closeNostrConnectModal(); - } catch (e) { - console.error(e); - alert(e.message); - } - } - @action disconnectNostr() { this.nostrAuth.logout(); } - get hasExtension() { - return typeof window !== 'undefined' && typeof window.nostr !== 'undefined'; - } - diff --git a/app/services/nostr-auth.js b/app/services/nostr-auth.js index 5c10564..25d5c60 100644 --- a/app/services/nostr-auth.js +++ b/app/services/nostr-auth.js @@ -125,7 +125,7 @@ export default class NostrAuthService extends Service { } // We use a specific relay for the connection handshake. - const relay = 'wss://relay.damus.io'; + const relay = 'wss://relay.nsec.app'; localStorage.setItem(STORAGE_KEY_CONNECT_RELAY, relay); this._signerInstance = new NostrConnectSigner({ @@ -190,7 +190,7 @@ export default class NostrAuthService extends Service { STORAGE_KEY_CONNECT_REMOTE_PUBKEY ); const relay = - localStorage.getItem(STORAGE_KEY_CONNECT_RELAY) || 'wss://relay.damus.io'; + localStorage.getItem(STORAGE_KEY_CONNECT_RELAY) || 'wss://relay.nsec.app'; if (!localKeyHex || !remotePubkey) { throw new Error('Missing Nostr Connect local state.');