Compare commits
136 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
cf80c1eea7
|
|||
|
126806fcd4
|
|||
|
f48045c35d
|
|||
|
989173a2e6
|
|||
|
62407f5fa4
|
|||
|
7f1c4b5f61
|
|||
|
59e334c499
|
|||
|
981502e293
|
|||
|
9c5fbca72a
|
|||
|
fd8f04f902
|
|||
|
3e23ec161c
|
|||
|
f2e531c0f6
|
|||
|
96a5a6ac34
|
|||
|
78996b6c61
|
|||
|
bb5b69711c
|
|||
|
ad9c489102
|
|||
|
c11882adfb
|
|||
|
707f4ac11c
|
|||
|
3bada05b63
|
|||
|
f01730fef5
|
|||
|
448c51bab6
|
|||
|
0bcbae374b
|
|||
|
c33fe3b268
|
|||
|
18bda60310
|
|||
|
86d25dc6ba
|
|||
|
5b8bec6a00
|
|||
|
f2c2eb1fdc
|
|||
|
b42c4881f6
|
|||
|
b18e299eca
|
|||
|
401ed41fcd
|
|||
|
504e8fab94
|
|||
|
76897c9e69
|
|||
|
59bc5ca046
|
|||
|
ef4bb8f51a
|
|||
|
f82a797720
|
|||
|
f9cb22ee0e
|
|||
|
a77ea0c97d
|
|||
|
208b77a294
|
|||
|
ea3e4dd0dc
|
|||
|
2c2a3e2a4c
|
|||
|
d266bb92bd
|
|||
|
200100686d
|
|||
|
70d2fe1c6c
|
|||
|
6329ad986d
|
|||
|
bcfa81494e
|
|||
|
bc42694707
|
|||
|
4390b7d699
|
|||
|
7bab8dfa09
|
|||
|
51c9555273
|
|||
|
632efeeab5
|
|||
|
14827fce3e
|
|||
|
deeea9961f
|
|||
|
7a109c9ba5
|
|||
|
10aae3c9b3
|
|||
|
b492e2aa89
|
|||
|
4c4a53ae42
|
|||
|
a240a5d199
|
|||
|
0332cf4c3c
|
|||
|
59c447fe1f
|
|||
|
1140ecfe41
|
|||
|
60936ed2f5
|
|||
|
ca82a029bc
|
|||
|
0630aed73d
|
|||
|
f27a636529
|
|||
|
995ae95b09
|
|||
|
0fb320d996
|
|||
|
4f4ca827b1
|
|||
|
c1d3f25d50
|
|||
|
2087cfc4f7
|
|||
|
8572032481
|
|||
|
b4c3f5c88d
|
|||
|
cff19980d5
|
|||
|
cf251f702b
|
|||
|
d2eb888dcf
|
|||
|
a0b4a4b3f3
|
|||
|
cb3ee48909
|
|||
|
1d022b21bd
|
|||
|
3e831a7686
|
|||
|
2943125dbd
|
|||
|
a32ad7572b
|
|||
|
a1b3957c83
|
|||
|
9f2f233c22
|
|||
|
1ba4afdf08
|
|||
|
d764134513
|
|||
|
e38f540c79
|
|||
|
73ad5b4eb1
|
|||
|
b4a70233cf
|
|||
|
cb4b9c6b40
|
|||
|
98dcb4f25b
|
|||
|
7709634a9a
|
|||
|
3ddc85669f
|
|||
|
95961e680f
|
|||
|
9468a6a0cc
|
|||
|
c9465c8fa8
|
|||
|
6c5c1fea27
|
|||
|
fe41369754
|
|||
|
1498c5a713
|
|||
|
b6e2964f8e
|
|||
|
d1d179bb93
|
|||
|
b83a16bf13
|
|||
|
c853418fbb
|
|||
|
4fed8c05c5
|
|||
|
670128cbda
|
|||
|
d8fa30c74b
|
|||
|
0f8d7046ac
|
|||
|
8ca7481a79
|
|||
|
cd25c55bd7
|
|||
|
32c4f7da57
|
|||
|
71939a30c3
|
|||
|
7285ace882
|
|||
|
94ba33ecc1
|
|||
|
85a8699b78
|
|||
|
99cfd96ca1
|
|||
|
8d40b3bb35
|
|||
|
c5316bf336
|
|||
|
a384e83dd0
|
|||
|
b23d54d74f
|
|||
|
5bd4dba907
|
|||
|
54ba99673f
|
|||
|
54445f249b
|
|||
|
9828ad2714
|
|||
|
a89ba904c8
|
|||
|
4c540bc713
|
|||
|
bb2411972f
|
|||
|
5cd384cf3a
|
|||
|
ec31d1a59b
|
|||
|
4f55f26851
|
|||
|
b7cce6eb7e
|
|||
|
79777fb51a
|
|||
|
1ed66ca744
|
|||
|
a2a61b0fec
|
|||
|
d9ba73559e
|
|||
|
f1ebafc1f0
|
|||
|
10501b64bd
|
|||
|
7607f27013
|
|||
|
8cc579e271
|
@@ -7,15 +7,74 @@ import Icon from '#components/icon';
|
||||
import UserMenu from '#components/user-menu';
|
||||
import SearchBox from '#components/search-box';
|
||||
import CategoryChips from '#components/category-chips';
|
||||
import { and } from 'ember-truth-helpers';
|
||||
import cachedImage from '../modifiers/cached-image';
|
||||
import { POI_CATEGORIES } from '../utils/poi-categories';
|
||||
|
||||
export default class AppHeaderComponent extends Component {
|
||||
@service storage;
|
||||
@service settings;
|
||||
@service nostrAuth;
|
||||
@service nostrData;
|
||||
@service mapUi;
|
||||
@service router;
|
||||
@tracked isUserMenuOpen = false;
|
||||
@tracked searchQuery = '';
|
||||
|
||||
get hasQuery() {
|
||||
return !!this.searchQuery;
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
if (this.router && typeof this.router.on === 'function') {
|
||||
this.router.on('routeDidChange', this.syncSearchQuery);
|
||||
}
|
||||
this.syncSearchQuery();
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
if (this.router && typeof this.router.off === 'function') {
|
||||
this.router.off('routeDidChange', this.syncSearchQuery);
|
||||
}
|
||||
super.willDestroy(...arguments);
|
||||
}
|
||||
|
||||
@action
|
||||
syncSearchQuery() {
|
||||
const qp =
|
||||
this.mapUi.currentSearch || this.router?.currentRoute?.queryParams;
|
||||
if (qp?.q) {
|
||||
this.searchQuery = qp.q;
|
||||
} else if (qp?.category) {
|
||||
const category = POI_CATEGORIES.find((c) => c.id === qp.category);
|
||||
this.searchQuery = category ? category.label : qp.category;
|
||||
} else {
|
||||
this.searchQuery = '';
|
||||
}
|
||||
}
|
||||
|
||||
get isSearching() {
|
||||
// 1. If we are actively focusing/typing in the search box with a query, hide pills
|
||||
if (this.mapUi.searchBoxHasFocus && this.searchQuery) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. If we are on the search route, check loading and results status
|
||||
if (this.router?.currentRouteName === 'search') {
|
||||
if (this.mapUi.loadingState) {
|
||||
return false; // Keep pills visible while loading
|
||||
}
|
||||
return this.mapUi.searchResults && this.mapUi.searchResults.length > 0;
|
||||
}
|
||||
|
||||
// 3. Fallback for integration tests (non-search route with a query)
|
||||
if (this.router?.currentRouteName !== 'search' && this.searchQuery) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
get showQuickSearch() {
|
||||
const zoom = this.mapUi.currentZoom ?? 13;
|
||||
return this.settings.showQuickSearchButtons && zoom >= 12;
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -50,8 +109,8 @@ export default class AppHeaderComponent extends Component {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{{#if this.settings.showQuickSearchButtons}}
|
||||
<div class="header-center {{if this.hasQuery 'searching'}}">
|
||||
{{#if this.showQuickSearch}}
|
||||
<div class="header-center {{if this.isSearching 'searching'}}">
|
||||
<CategoryChips @onSelect={{this.handleChipSelect}} />
|
||||
</div>
|
||||
{{/if}}
|
||||
@@ -64,9 +123,19 @@ export default class AppHeaderComponent extends Component {
|
||||
aria-label="User Menu"
|
||||
{{on "click" this.toggleUserMenu}}
|
||||
>
|
||||
<div class="user-avatar-placeholder">
|
||||
<Icon @name="user" @size={{20}} @color="white" />
|
||||
</div>
|
||||
{{#if
|
||||
(and this.nostrAuth.isConnected this.nostrData.profile.picture)
|
||||
}}
|
||||
<img
|
||||
{{cachedImage this.nostrData.profile.picture}}
|
||||
class="user-avatar"
|
||||
alt="User Avatar"
|
||||
/>
|
||||
{{else}}
|
||||
<div class="user-avatar-placeholder">
|
||||
<Icon @name="user" @size={{20}} @color="white" />
|
||||
</div>
|
||||
{{/if}}
|
||||
</button>
|
||||
|
||||
{{#if this.isUserMenuOpen}}
|
||||
|
||||
@@ -3,11 +3,11 @@ import Icon from '#components/icon';
|
||||
|
||||
<template>
|
||||
{{! template-lint-disable no-nested-interactive }}
|
||||
<div class="sidebar-header">
|
||||
<div class="sidebar-header has-back-btn">
|
||||
<button type="button" class="back-btn" {{on "click" @onBack}}>
|
||||
<Icon @name="arrow-left" @size={{20}} @color="#333" />
|
||||
</button>
|
||||
<h2>About</h2>
|
||||
<h2 class="sidebar-header-text-centered">About</h2>
|
||||
<button type="button" class="close-btn" {{on "click" @onClose}}>
|
||||
<Icon @name="x" @size={{20}} @color="#333" />
|
||||
</button>
|
||||
|
||||
@@ -19,6 +19,12 @@ import iconRounded from '../../icons/icon-rounded.svg?raw';
|
||||
|
||||
<div class="sidebar-content">
|
||||
<ul class="app-menu">
|
||||
<li>
|
||||
<button type="button" {{on "click" @onSavedPlaces}}>
|
||||
<Icon @name="bookmark" @size={{20}} />
|
||||
<span>Collections</span>
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button type="button" {{on "click" (fn @onNavigate "settings")}}>
|
||||
<Icon @name="settings" @size={{20}} />
|
||||
|
||||
@@ -2,6 +2,7 @@ import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { fn } from '@ember/helper';
|
||||
import { service } from '@ember/service';
|
||||
import eq from 'ember-truth-helpers/helpers/eq';
|
||||
|
||||
import AppMenuHome from './home';
|
||||
@@ -9,6 +10,7 @@ import AppMenuSettings from './settings';
|
||||
import AppMenuAbout from './about';
|
||||
|
||||
export default class AppMenu extends Component {
|
||||
@service router;
|
||||
@tracked currentView = 'menu'; // 'menu', 'settings', 'about'
|
||||
|
||||
@action
|
||||
@@ -16,10 +18,19 @@ export default class AppMenu extends Component {
|
||||
this.currentView = view;
|
||||
}
|
||||
|
||||
@action
|
||||
goToSavedPlaces() {
|
||||
this.router.transitionTo('lists.index');
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="sidebar app-menu-pane">
|
||||
{{#if (eq this.currentView "menu")}}
|
||||
<AppMenuHome @onNavigate={{this.setView}} @onClose={{@onClose}} />
|
||||
<AppMenuHome
|
||||
@onNavigate={{this.setView}}
|
||||
@onClose={{@onClose}}
|
||||
@onSavedPlaces={{this.goToSavedPlaces}}
|
||||
/>
|
||||
|
||||
{{else if (eq this.currentView "settings")}}
|
||||
<AppMenuSettings
|
||||
|
||||
@@ -1,39 +1,31 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { service } from '@ember/service';
|
||||
import Icon from '#components/icon';
|
||||
import eq from 'ember-truth-helpers/helpers/eq';
|
||||
import AppMenuSettingsMapUi from './settings/map-ui';
|
||||
import AppMenuSettingsApis from './settings/apis';
|
||||
import AppMenuSettingsNostr from './settings/nostr';
|
||||
import AppMenuSettingsExperimental from './settings/experimental';
|
||||
|
||||
export default class AppMenuSettings extends Component {
|
||||
@service settings;
|
||||
|
||||
@action
|
||||
updateApi(event) {
|
||||
this.settings.updateOverpassApi(event.target.value);
|
||||
}
|
||||
updateSetting(key, event) {
|
||||
let value = event.target.value;
|
||||
if (value === 'true') value = true;
|
||||
if (value === 'false') value = false;
|
||||
|
||||
@action
|
||||
toggleKinetic(event) {
|
||||
this.settings.updateMapKinetic(event.target.value === 'true');
|
||||
}
|
||||
|
||||
@action
|
||||
toggleQuickSearchButtons(event) {
|
||||
this.settings.updateShowQuickSearchButtons(event.target.value === 'true');
|
||||
}
|
||||
|
||||
@action
|
||||
updatePhotonApi(event) {
|
||||
this.settings.updatePhotonApi(event.target.value);
|
||||
this.settings.update(key, value);
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="sidebar-header">
|
||||
<div class="sidebar-header has-back-btn">
|
||||
<button type="button" class="back-btn" {{on "click" @onBack}}>
|
||||
<Icon @name="arrow-left" @size={{20}} @color="#333" />
|
||||
</button>
|
||||
<h2>Settings</h2>
|
||||
<h2 class="sidebar-header-text-centered">Settings</h2>
|
||||
<button type="button" class="close-btn" {{on "click" @onClose}}>
|
||||
<Icon @name="x" @size={{20}} @color="#333" />
|
||||
</button>
|
||||
@@ -41,88 +33,10 @@ export default class AppMenuSettings extends Component {
|
||||
|
||||
<div class="sidebar-content">
|
||||
<section class="settings-section">
|
||||
<div class="form-group">
|
||||
<label for="show-quick-search">Quick search buttons visible</label>
|
||||
<select
|
||||
id="show-quick-search"
|
||||
class="form-control"
|
||||
{{on "change" this.toggleQuickSearchButtons}}
|
||||
>
|
||||
<option
|
||||
value="true"
|
||||
selected={{if this.settings.showQuickSearchButtons "selected"}}
|
||||
>
|
||||
Yes
|
||||
</option>
|
||||
<option
|
||||
value="false"
|
||||
selected={{unless
|
||||
this.settings.showQuickSearchButtons
|
||||
"selected"
|
||||
}}
|
||||
>
|
||||
No
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="map-kinetic">Map Inertia (Kinetic Panning)</label>
|
||||
<select
|
||||
id="map-kinetic"
|
||||
class="form-control"
|
||||
{{on "change" this.toggleKinetic}}
|
||||
>
|
||||
<option
|
||||
value="true"
|
||||
selected={{if this.settings.mapKinetic "selected"}}
|
||||
>
|
||||
On
|
||||
</option>
|
||||
<option
|
||||
value="false"
|
||||
selected={{unless this.settings.mapKinetic "selected"}}
|
||||
>
|
||||
Off
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="overpass-api">Overpass API Provider</label>
|
||||
<select
|
||||
id="overpass-api"
|
||||
class="form-control"
|
||||
{{on "change" this.updateApi}}
|
||||
>
|
||||
{{#each this.settings.overpassApis as |api|}}
|
||||
<option
|
||||
value={{api.url}}
|
||||
selected={{if
|
||||
(eq api.url this.settings.overpassApi)
|
||||
"selected"
|
||||
}}
|
||||
>
|
||||
{{api.name}}
|
||||
</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="photon-api">Photon API Provider</label>
|
||||
<select
|
||||
id="photon-api"
|
||||
class="form-control"
|
||||
{{on "change" this.updatePhotonApi}}
|
||||
>
|
||||
{{#each this.settings.photonApis as |api|}}
|
||||
<option
|
||||
value={{api.url}}
|
||||
selected={{if (eq api.url this.settings.photonApi) "selected"}}
|
||||
>
|
||||
{{api.name}}
|
||||
</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
<AppMenuSettingsMapUi @onChange={{this.updateSetting}} />
|
||||
<AppMenuSettingsApis @onChange={{this.updateSetting}} />
|
||||
<AppMenuSettingsNostr @onChange={{this.updateSetting}} />
|
||||
<AppMenuSettingsExperimental @onChange={{this.updateSetting}} />
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { fn } from '@ember/helper';
|
||||
import Icon from '#components/icon';
|
||||
import eq from 'ember-truth-helpers/helpers/eq';
|
||||
|
||||
export default class AppMenuSettingsApis extends Component {
|
||||
@service settings;
|
||||
|
||||
<template>
|
||||
{{! template-lint-disable no-nested-interactive }}
|
||||
<details>
|
||||
<summary>
|
||||
<Icon @name="server" @size={{20}} />
|
||||
<span>API Providers</span>
|
||||
</summary>
|
||||
<div class="details-content form-layout">
|
||||
<div class="form-group">
|
||||
<label for="overpass-api">Overpass API Provider</label>
|
||||
<select
|
||||
id="overpass-api"
|
||||
class="form-control"
|
||||
{{on "change" (fn @onChange "overpassApi")}}
|
||||
>
|
||||
{{#each this.settings.overpassApis as |api|}}
|
||||
<option
|
||||
value={{api.url}}
|
||||
selected={{if
|
||||
(eq api.url this.settings.overpassApi)
|
||||
"selected"
|
||||
}}
|
||||
>
|
||||
{{api.name}}
|
||||
</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="photon-api">Photon API Provider</label>
|
||||
<select
|
||||
id="photon-api"
|
||||
class="form-control"
|
||||
{{on "change" (fn @onChange "photonApi")}}
|
||||
>
|
||||
{{#each this.settings.photonApis as |api|}}
|
||||
<option
|
||||
value={{api.url}}
|
||||
selected={{if (eq api.url this.settings.photonApi) "selected"}}
|
||||
>
|
||||
{{api.name}}
|
||||
</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { fn } from '@ember/helper';
|
||||
import Icon from '#components/icon';
|
||||
|
||||
export default class AppMenuSettingsExperimental extends Component {
|
||||
@service settings;
|
||||
|
||||
<template>
|
||||
{{! template-lint-disable no-nested-interactive }}
|
||||
<details>
|
||||
<summary>
|
||||
<Icon @name="alert-triangle" @size={{20}} />
|
||||
<span>Experimental</span>
|
||||
</summary>
|
||||
<div class="details-content form-layout">
|
||||
<div class="form-group">
|
||||
<label for="experimental-enable-photo-deletion">Enable photo deletion
|
||||
(own photos)</label>
|
||||
<select
|
||||
id="experimental-enable-photo-deletion"
|
||||
class="form-control"
|
||||
{{on "change" (fn @onChange "experimentalEnablePhotoDeletion")}}
|
||||
>
|
||||
<option
|
||||
value="true"
|
||||
selected={{if
|
||||
this.settings.experimentalEnablePhotoDeletion
|
||||
"selected"
|
||||
}}
|
||||
>
|
||||
On
|
||||
</option>
|
||||
<option
|
||||
value="false"
|
||||
selected={{unless
|
||||
this.settings.experimentalEnablePhotoDeletion
|
||||
"selected"
|
||||
}}
|
||||
>
|
||||
Off
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { on } from '@ember/modifier';
|
||||
import { service } from '@ember/service';
|
||||
import { fn } from '@ember/helper';
|
||||
import Icon from '#components/icon';
|
||||
|
||||
export default class AppMenuSettingsMapUi extends Component {
|
||||
@service settings;
|
||||
|
||||
<template>
|
||||
{{! template-lint-disable no-nested-interactive }}
|
||||
<details>
|
||||
<summary>
|
||||
<Icon @name="map" @size={{20}} />
|
||||
<span>Map & UI</span>
|
||||
</summary>
|
||||
<div class="details-content form-layout">
|
||||
<div class="form-group">
|
||||
<label for="show-quick-search">Quick search buttons visible</label>
|
||||
<select
|
||||
id="show-quick-search"
|
||||
class="form-control"
|
||||
{{on "change" (fn @onChange "showQuickSearchButtons")}}
|
||||
>
|
||||
<option
|
||||
value="true"
|
||||
selected={{if this.settings.showQuickSearchButtons "selected"}}
|
||||
>
|
||||
Yes
|
||||
</option>
|
||||
<option
|
||||
value="false"
|
||||
selected={{unless
|
||||
this.settings.showQuickSearchButtons
|
||||
"selected"
|
||||
}}
|
||||
>
|
||||
No
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="map-kinetic">Map Inertia (Kinetic Panning)</label>
|
||||
<select
|
||||
id="map-kinetic"
|
||||
class="form-control"
|
||||
{{on "change" (fn @onChange "mapKinetic")}}
|
||||
>
|
||||
<option
|
||||
value="true"
|
||||
selected={{if this.settings.mapKinetic "selected"}}
|
||||
>
|
||||
On
|
||||
</option>
|
||||
<option
|
||||
value="false"
|
||||
selected={{unless this.settings.mapKinetic "selected"}}
|
||||
>
|
||||
Off
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { on } from '@ember/modifier';
|
||||
import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { service } from '@ember/service';
|
||||
import { fn } from '@ember/helper';
|
||||
import Icon from '#components/icon';
|
||||
import {
|
||||
excludeRequiredRelays,
|
||||
mergeRequiredRelays,
|
||||
normalizeRelayUrl,
|
||||
} from '../../../utils/nostr';
|
||||
|
||||
const stripProtocol = (url) => (url ? url.replace(/^wss?:\/\//, '') : '');
|
||||
|
||||
export default class AppMenuSettingsNostr extends Component {
|
||||
@service settings;
|
||||
@service nostrData;
|
||||
@service toast;
|
||||
|
||||
@tracked newReadRelay = '';
|
||||
@tracked newWriteRelay = '';
|
||||
|
||||
get customReadRelays() {
|
||||
return excludeRequiredRelays(
|
||||
this.settings.nostrReadRelays || [],
|
||||
this.nostrData.requiredReadRelays
|
||||
);
|
||||
}
|
||||
|
||||
get customWriteRelays() {
|
||||
return excludeRequiredRelays(
|
||||
this.settings.nostrWriteRelays || [],
|
||||
this.nostrData.requiredWriteRelays
|
||||
);
|
||||
}
|
||||
|
||||
get readRelayExclusions() {
|
||||
return this.settings.nostrReadRelayExclusions || [];
|
||||
}
|
||||
|
||||
get writeRelayExclusions() {
|
||||
return this.settings.nostrWriteRelayExclusions || [];
|
||||
}
|
||||
|
||||
get requiredReadRelaySet() {
|
||||
return new Set(this.nostrData.requiredReadRelays.filter(Boolean));
|
||||
}
|
||||
|
||||
get requiredWriteRelaySet() {
|
||||
return new Set(this.nostrData.requiredWriteRelays.filter(Boolean));
|
||||
}
|
||||
|
||||
get mailboxReadRelaySet() {
|
||||
return new Set(this.nostrData.mailboxReadRelays);
|
||||
}
|
||||
|
||||
get mailboxWriteRelaySet() {
|
||||
return new Set(this.nostrData.mailboxWriteRelays);
|
||||
}
|
||||
|
||||
get hasReadOverrides() {
|
||||
return (
|
||||
this.customReadRelays.length > 0 || this.readRelayExclusions.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
get hasWriteOverrides() {
|
||||
return (
|
||||
this.customWriteRelays.length > 0 || this.writeRelayExclusions.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
get readRelaysForDisplay() {
|
||||
return this.nostrData.activeReadRelays.map((url) => {
|
||||
return {
|
||||
url,
|
||||
isRequired: this.requiredReadRelaySet.has(url),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
get writeRelaysForDisplay() {
|
||||
return this.nostrData.activeWriteRelays.map((url) => {
|
||||
return {
|
||||
url,
|
||||
isRequired: this.requiredWriteRelaySet.has(url),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
updateNewReadRelay(event) {
|
||||
this.newReadRelay = event.target.value;
|
||||
}
|
||||
|
||||
@action
|
||||
updateNewWriteRelay(event) {
|
||||
this.newWriteRelay = event.target.value;
|
||||
}
|
||||
|
||||
@action
|
||||
addReadRelay() {
|
||||
const url = normalizeRelayUrl(this.newReadRelay);
|
||||
if (!url) return;
|
||||
|
||||
const merged = mergeRequiredRelays(this.nostrData.requiredReadRelays, [
|
||||
...this.customReadRelays,
|
||||
url,
|
||||
]);
|
||||
const custom = excludeRequiredRelays(
|
||||
merged,
|
||||
this.nostrData.requiredReadRelays
|
||||
);
|
||||
|
||||
const readExclusions = this.readRelayExclusions.filter((relay) => {
|
||||
return normalizeRelayUrl(relay) !== url;
|
||||
});
|
||||
|
||||
this.settings.update('nostrReadRelays', custom.length > 0 ? custom : null);
|
||||
this.settings.update(
|
||||
'nostrReadRelayExclusions',
|
||||
readExclusions.length > 0 ? readExclusions : null
|
||||
);
|
||||
this.newReadRelay = '';
|
||||
}
|
||||
|
||||
@action
|
||||
removeReadRelay(url) {
|
||||
if (this.requiredReadRelaySet.has(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedUrl = normalizeRelayUrl(url);
|
||||
|
||||
const remainingCustom = this.customReadRelays.filter((relay) => {
|
||||
return normalizeRelayUrl(relay) !== normalizedUrl;
|
||||
});
|
||||
|
||||
const nextExclusions = this.mailboxReadRelaySet.has(normalizedUrl)
|
||||
? Array.from(new Set([...this.readRelayExclusions, normalizedUrl]))
|
||||
: this.readRelayExclusions;
|
||||
|
||||
this.settings.update(
|
||||
'nostrReadRelays',
|
||||
remainingCustom.length > 0 ? remainingCustom : null
|
||||
);
|
||||
this.settings.update(
|
||||
'nostrReadRelayExclusions',
|
||||
nextExclusions.length > 0 ? nextExclusions : null
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
handleReadRelayKeydown(event) {
|
||||
if (event.key === 'Enter') {
|
||||
this.addReadRelay();
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
handleWriteRelayKeydown(event) {
|
||||
if (event.key === 'Enter') {
|
||||
this.addWriteRelay();
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
resetReadRelays() {
|
||||
this.settings.update('nostrReadRelays', null);
|
||||
this.settings.update('nostrReadRelayExclusions', null);
|
||||
}
|
||||
|
||||
@action
|
||||
addWriteRelay() {
|
||||
const url = normalizeRelayUrl(this.newWriteRelay);
|
||||
if (!url) return;
|
||||
|
||||
const merged = mergeRequiredRelays(this.nostrData.requiredWriteRelays, [
|
||||
...this.customWriteRelays,
|
||||
url,
|
||||
]);
|
||||
const custom = excludeRequiredRelays(
|
||||
merged,
|
||||
this.nostrData.requiredWriteRelays
|
||||
);
|
||||
|
||||
const writeExclusions = this.writeRelayExclusions.filter((relay) => {
|
||||
return normalizeRelayUrl(relay) !== url;
|
||||
});
|
||||
|
||||
this.settings.update('nostrWriteRelays', custom.length > 0 ? custom : null);
|
||||
this.settings.update(
|
||||
'nostrWriteRelayExclusions',
|
||||
writeExclusions.length > 0 ? writeExclusions : null
|
||||
);
|
||||
this.newWriteRelay = '';
|
||||
}
|
||||
|
||||
@action
|
||||
removeWriteRelay(url) {
|
||||
if (this.requiredWriteRelaySet.has(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedUrl = normalizeRelayUrl(url);
|
||||
|
||||
const remainingCustom = this.customWriteRelays.filter((relay) => {
|
||||
return normalizeRelayUrl(relay) !== normalizedUrl;
|
||||
});
|
||||
|
||||
const nextExclusions = this.mailboxWriteRelaySet.has(normalizedUrl)
|
||||
? Array.from(new Set([...this.writeRelayExclusions, normalizedUrl]))
|
||||
: this.writeRelayExclusions;
|
||||
|
||||
this.settings.update(
|
||||
'nostrWriteRelays',
|
||||
remainingCustom.length > 0 ? remainingCustom : null
|
||||
);
|
||||
this.settings.update(
|
||||
'nostrWriteRelayExclusions',
|
||||
nextExclusions.length > 0 ? nextExclusions : null
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
resetWriteRelays() {
|
||||
this.settings.update('nostrWriteRelays', null);
|
||||
this.settings.update('nostrWriteRelayExclusions', null);
|
||||
}
|
||||
|
||||
@action
|
||||
async clearCache() {
|
||||
try {
|
||||
await this.nostrData.clearCache();
|
||||
this.toast.show('Nostr cache cleared');
|
||||
} catch (e) {
|
||||
this.toast.show(`Failed to clear Nostr cache: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
{{! template-lint-disable no-nested-interactive }}
|
||||
<details>
|
||||
<summary>
|
||||
<Icon @name="zap" @size={{20}} />
|
||||
<span>Nostr</span>
|
||||
</summary>
|
||||
<div class="details-content form-layout">
|
||||
<div class="form-group">
|
||||
<label for="new-read-relay">Read Relays</label>
|
||||
<ul class="relay-list">
|
||||
{{#each this.readRelaysForDisplay as |relay|}}
|
||||
<li>
|
||||
<span>{{stripProtocol relay.url}}</span>
|
||||
{{#unless relay.isRequired}}
|
||||
<button
|
||||
type="button"
|
||||
class="btn-remove-relay"
|
||||
title="Remove relay"
|
||||
aria-label="Remove"
|
||||
{{on "click" (fn this.removeReadRelay relay.url)}}
|
||||
>
|
||||
<Icon @name="x" @size={{14}} @color="currentColor" />
|
||||
</button>
|
||||
{{/unless}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
<div class="add-relay-input">
|
||||
<input
|
||||
id="new-read-relay"
|
||||
type="text"
|
||||
class="form-control"
|
||||
placeholder="relay.example.com"
|
||||
value={{this.newReadRelay}}
|
||||
{{on "input" this.updateNewReadRelay}}
|
||||
{{on "keydown" this.handleReadRelayKeydown}}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary"
|
||||
{{on "click" this.addReadRelay}}
|
||||
>Add</button>
|
||||
</div>
|
||||
{{#if this.hasReadOverrides}}
|
||||
<button
|
||||
type="button"
|
||||
class="btn-link reset-relays"
|
||||
{{on "click" this.resetReadRelays}}
|
||||
>
|
||||
Reset to Defaults
|
||||
</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new-write-relay">Write Relays</label>
|
||||
<ul class="relay-list">
|
||||
{{#each this.writeRelaysForDisplay as |relay|}}
|
||||
<li>
|
||||
<span>{{stripProtocol relay.url}}</span>
|
||||
{{#unless relay.isRequired}}
|
||||
<button
|
||||
type="button"
|
||||
class="btn-remove-relay"
|
||||
title="Remove relay"
|
||||
aria-label="Remove"
|
||||
{{on "click" (fn this.removeWriteRelay relay.url)}}
|
||||
>
|
||||
<Icon @name="x" @size={{14}} @color="currentColor" />
|
||||
</button>
|
||||
{{/unless}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
<div class="add-relay-input">
|
||||
<input
|
||||
id="new-write-relay"
|
||||
type="text"
|
||||
class="form-control"
|
||||
placeholder="relay.example.com"
|
||||
value={{this.newWriteRelay}}
|
||||
{{on "input" this.updateNewWriteRelay}}
|
||||
{{on "keydown" this.handleWriteRelayKeydown}}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary"
|
||||
{{on "click" this.addWriteRelay}}
|
||||
>Add</button>
|
||||
</div>
|
||||
{{#if this.hasWriteOverrides}}
|
||||
<button
|
||||
type="button"
|
||||
class="btn-link reset-relays"
|
||||
{{on "click" this.resetWriteRelays}}
|
||||
>
|
||||
Reset to Defaults
|
||||
</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="nostr-photo-fallback-uploads">Upload photos to fallback
|
||||
servers</label>
|
||||
<select
|
||||
id="nostr-photo-fallback-uploads"
|
||||
class="form-control"
|
||||
{{on "change" (fn @onChange "nostrPhotoFallbackUploads")}}
|
||||
>
|
||||
<option
|
||||
value="true"
|
||||
selected={{if this.settings.nostrPhotoFallbackUploads "selected"}}
|
||||
>
|
||||
Yes
|
||||
</option>
|
||||
<option
|
||||
value="false"
|
||||
selected={{unless
|
||||
this.settings.nostrPhotoFallbackUploads
|
||||
"selected"
|
||||
}}
|
||||
>
|
||||
No
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Cached data</label>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline btn-full"
|
||||
{{on "click" this.clearCache}}
|
||||
>
|
||||
<Icon @name="database" @size={{18}} @color="var(--danger-color)" />
|
||||
Clear profiles, photos, and reviews
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { modifier } from 'ember-modifier';
|
||||
import { decode } from 'blurhash';
|
||||
|
||||
export default class Blurhash extends Component {
|
||||
renderBlurhash = modifier((canvas, [hash, width, height]) => {
|
||||
if (!hash || !canvas) return;
|
||||
|
||||
// Default size to a small multiple of aspect ratio to save CPU
|
||||
// 32x18 is a good balance of speed vs quality for 16:9
|
||||
const renderWidth = width || 32;
|
||||
const renderHeight = height || 18;
|
||||
|
||||
canvas.width = renderWidth;
|
||||
canvas.height = renderHeight;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
try {
|
||||
const pixels = decode(hash, renderWidth, renderHeight);
|
||||
const imageData = ctx.createImageData(renderWidth, renderHeight);
|
||||
imageData.data.set(pixels);
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
} catch (e) {
|
||||
console.warn('Failed to decode blurhash:', e.message || e);
|
||||
}
|
||||
});
|
||||
|
||||
<template>
|
||||
<canvas
|
||||
class="blurhash-canvas"
|
||||
...attributes
|
||||
{{this.renderBlurhash @hash @width @height}}
|
||||
></canvas>
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { on } from '@ember/modifier';
|
||||
import Icon from '#components/icon';
|
||||
|
||||
export default class DropdownMenu extends Component {
|
||||
@tracked isOpen = false;
|
||||
|
||||
@action
|
||||
toggleMenu(e) {
|
||||
e?.stopPropagation();
|
||||
this.isOpen = !this.isOpen;
|
||||
}
|
||||
|
||||
@action
|
||||
closeMenu(e) {
|
||||
e?.stopPropagation();
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
get triggerIcon() {
|
||||
return this.args.triggerIcon || 'more-vertical';
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="dropdown-menu-container">
|
||||
<button
|
||||
class="dropdown-trigger-btn btn-press"
|
||||
type="button"
|
||||
title={{@triggerTitle}}
|
||||
{{on "click" this.toggleMenu}}
|
||||
>
|
||||
<Icon
|
||||
@name={{this.triggerIcon}}
|
||||
@size={{@iconSize}}
|
||||
@color={{@iconColor}}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{{#if this.isOpen}}
|
||||
<div class="dropdown-popover {{@popoverClass}}">
|
||||
{{yield this.closeMenu}}
|
||||
</div>
|
||||
<div
|
||||
class="menu-backdrop"
|
||||
{{on "click" this.closeMenu}}
|
||||
role="button"
|
||||
></div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
+31
-11
@@ -27,6 +27,7 @@ export default class MapComponent extends Component {
|
||||
@service mapUi;
|
||||
@service router;
|
||||
@service settings;
|
||||
@service nostrData;
|
||||
|
||||
mapInstance;
|
||||
bookmarkSource;
|
||||
@@ -283,6 +284,7 @@ export default class MapComponent extends Component {
|
||||
// Initialize the UI service with the map center
|
||||
const initialCenter = toLonLat(view.getCenter());
|
||||
this.mapUi.updateCenter(initialCenter[1], initialCenter[0]);
|
||||
this.mapUi.updateZoom(view.getZoom());
|
||||
|
||||
apply(this.mapInstance, 'https://tiles.openfreemap.org/styles/liberty', {
|
||||
webfonts: 'data:text/css,',
|
||||
@@ -781,14 +783,19 @@ export default class MapComponent extends Component {
|
||||
// Check if mobile (width <= 768px matches CSS)
|
||||
if (size[0] <= 768) {
|
||||
// On mobile, the bottom 50% is covered by the sheet.
|
||||
// We want the pin to be in the center of the TOP 50% (visible area).
|
||||
// That means the pin should be at y = height * 0.25 (25% down from top).
|
||||
// The map center is at y = height * 0.50.
|
||||
// So the pin is "above" the center by 25% of the height in pixels.
|
||||
// To put the pin there, the map center needs to be "below" the pin by that amount.
|
||||
// We want the pin to be in the center of the TOP 50% (visible area), minus the header.
|
||||
|
||||
const height = size[1];
|
||||
const offsetPixels = height * 0.25; // Distance from desired pin pos to map center
|
||||
const headerEl = document.querySelector('.app-header');
|
||||
const headerHeight = headerEl ? headerEl.offsetHeight : 60;
|
||||
|
||||
// Visible area is from headerHeight to height / 2 (bottom sheet covers bottom 50%)
|
||||
const visibleCenterY = headerHeight + (height / 2 - headerHeight) / 2;
|
||||
|
||||
// The map center is at y = height * 0.50.
|
||||
// So the pin is "above" the center by (height/2 - visibleCenterY) pixels.
|
||||
// To put the pin there, the map center needs to be "below" the pin by that amount.
|
||||
const offsetPixels = height / 2 - visibleCenterY; // Distance from desired pin pos to map center
|
||||
const offsetMapUnits = offsetPixels * resolution;
|
||||
|
||||
// Shift center SOUTH (decrease Y).
|
||||
@@ -848,6 +855,9 @@ export default class MapComponent extends Component {
|
||||
let targetPixelY = pixel[1];
|
||||
let needsPan = false;
|
||||
|
||||
const headerEl = document.querySelector('.app-header');
|
||||
const headerHeight = headerEl ? headerEl.offsetHeight : 60;
|
||||
|
||||
// 1. Mobile Bottom Sheet Logic (Screen <= 768px)
|
||||
if (size[0] <= 768) {
|
||||
const height = size[1];
|
||||
@@ -855,7 +865,7 @@ export default class MapComponent extends Component {
|
||||
|
||||
// If in bottom half
|
||||
if (pixel[1] > splitPoint) {
|
||||
targetPixelY = height * 0.25; // Target: Center of top half
|
||||
targetPixelY = headerHeight + (height / 2 - headerHeight) / 2; // Target: Center of visible area above bottom sheet
|
||||
needsPan = true;
|
||||
}
|
||||
}
|
||||
@@ -876,11 +886,10 @@ export default class MapComponent extends Component {
|
||||
|
||||
// 3. Header Logic (Any screen size)
|
||||
// Check if the (potentially new) target Y is under the header
|
||||
const headerHeight = 60;
|
||||
const minTopDistance = headerHeight + 20; // 80px
|
||||
const minTopDistance = headerHeight + 20; // Provide some padding
|
||||
|
||||
if (targetPixelY < minTopDistance) {
|
||||
targetPixelY = minTopDistance + 30; // Move it to ~110px, clear of header
|
||||
targetPixelY = minTopDistance + 30; // Move it clear of header
|
||||
needsPan = true;
|
||||
}
|
||||
|
||||
@@ -1033,11 +1042,12 @@ export default class MapComponent extends Component {
|
||||
}
|
||||
|
||||
handleMapMove = async () => {
|
||||
if (!this.mapInstance) return;
|
||||
if (!this.mapInstance || this.isDestroying || this.isDestroyed) return;
|
||||
|
||||
const view = this.mapInstance.getView();
|
||||
const center = toLonLat(view.getCenter());
|
||||
this.mapUi.updateCenter(center[1], center[0]);
|
||||
this.mapUi.updateZoom(view.getZoom());
|
||||
|
||||
// If in creation mode, update the coordinates in the service AND the URL
|
||||
if (this.mapUi.isCreating) {
|
||||
@@ -1078,6 +1088,8 @@ export default class MapComponent extends Component {
|
||||
const bbox = { minLat, minLon, maxLat, maxLon };
|
||||
this.mapUi.updateBounds(bbox);
|
||||
await this.storage.loadPlacesInBounds(bbox);
|
||||
if (this.isDestroying || this.isDestroyed) return;
|
||||
this.nostrData.loadPlacesInBounds(bbox);
|
||||
this.loadBookmarks(this.storage.placesInView);
|
||||
|
||||
// Persist view to localStorage
|
||||
@@ -1142,6 +1154,8 @@ export default class MapComponent extends Component {
|
||||
this.mapUi.returnToSearch = true;
|
||||
}
|
||||
this.mapUi.preventNextZoom = true;
|
||||
this.mapUi.selectPlace(place, { preventZoom: true });
|
||||
this.mapUi.showSidebar();
|
||||
this.router.transitionTo('place', place);
|
||||
};
|
||||
|
||||
@@ -1178,6 +1192,12 @@ export default class MapComponent extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.mapUi.searchResults && this.mapUi.searchResults.length > 0) {
|
||||
console.debug('Clearing active search and markers on map click');
|
||||
this.router.transitionTo('index');
|
||||
return;
|
||||
}
|
||||
|
||||
// Require Zoom >= 17 for generic map searches
|
||||
// This prevents accidental searches when interacting with the map at a high level
|
||||
const currentZoom = this.mapInstance.getView().getZoom();
|
||||
|
||||
+48
-20
@@ -1,9 +1,39 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { on } from '@ember/modifier';
|
||||
import config from 'marco/config/environment';
|
||||
import Icon from './icon';
|
||||
|
||||
const ModalContent = <template>
|
||||
<div class="modal-overlay" role="dialog" tabindex="-1" {{on "click" @close}}>
|
||||
<div
|
||||
class="modal-content"
|
||||
role="document"
|
||||
tabindex="0"
|
||||
{{on "click" @stopProp}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="close-modal-btn btn-text {{if @disableClose 'disabled'}}"
|
||||
disabled={{@disableClose}}
|
||||
{{on "click" @close}}
|
||||
>
|
||||
<Icon @name="x" @size={{24}} @color="currentColor" />
|
||||
</button>
|
||||
{{yield}}
|
||||
</div>
|
||||
</div>
|
||||
</template>;
|
||||
|
||||
export default class Modal extends Component {
|
||||
get isTesting() {
|
||||
return config.environment === 'test';
|
||||
}
|
||||
|
||||
get destinationElement() {
|
||||
return document.getElementById('modal-portal') || document.body;
|
||||
}
|
||||
|
||||
@action
|
||||
stopProp(e) {
|
||||
e.stopPropagation();
|
||||
@@ -11,33 +41,31 @@ export default class Modal extends Component {
|
||||
|
||||
@action
|
||||
close() {
|
||||
if (this.args.disableClose) return;
|
||||
if (this.args.onClose) {
|
||||
this.args.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="modal-overlay"
|
||||
role="dialog"
|
||||
tabindex="-1"
|
||||
{{on "click" this.close}}
|
||||
>
|
||||
<div
|
||||
class="modal-content"
|
||||
role="document"
|
||||
tabindex="0"
|
||||
{{on "click" this.stopProp}}
|
||||
{{#if this.isTesting}}
|
||||
<ModalContent
|
||||
@close={{this.close}}
|
||||
@stopProp={{this.stopProp}}
|
||||
@disableClose={{@disableClose}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="close-modal-btn btn-text"
|
||||
{{on "click" this.close}}
|
||||
>
|
||||
<Icon @name="x" @size={{24}} />
|
||||
</button>
|
||||
{{yield}}
|
||||
</div>
|
||||
</div>
|
||||
</ModalContent>
|
||||
{{else}}
|
||||
{{#in-element this.destinationElement}}
|
||||
<ModalContent
|
||||
@close={{this.close}}
|
||||
@stopProp={{this.stopProp}}
|
||||
@disableClose={{@disableClose}}
|
||||
>
|
||||
{{yield}}
|
||||
</ModalContent>
|
||||
{{/in-element}}
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { service } from '@ember/service';
|
||||
import { on } from '@ember/modifier';
|
||||
import { eq } from 'ember-truth-helpers';
|
||||
import qrCode from '../modifiers/qr-code';
|
||||
@@ -41,6 +41,40 @@ export default class NostrConnectComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
async copyConnectUri() {
|
||||
const text = this.nostrAuth.connectUri;
|
||||
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.top = '0';
|
||||
textArea.style.left = '0';
|
||||
textArea.style.opacity = '0';
|
||||
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
|
||||
const successful = document.execCommand('copy');
|
||||
document.body.removeChild(textArea);
|
||||
|
||||
if (!successful) {
|
||||
throw new Error('Fallback copy failed');
|
||||
}
|
||||
}
|
||||
this.toast.show('Connection link copied to clipboard');
|
||||
} catch (err) {
|
||||
console.error('Failed to copy text: ', err);
|
||||
alert('Failed to copy link');
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="nostr-connect-modal">
|
||||
<h2>Connect with Nostr</h2>
|
||||
@@ -59,7 +93,7 @@ export default class NostrConnectComponent extends Component {
|
||||
class="btn btn-outline"
|
||||
type="button"
|
||||
disabled
|
||||
title="No Nostr extension found in your browser."
|
||||
title="No Nostr extension found in your browser"
|
||||
>
|
||||
Browser Extension (Not Found)
|
||||
</button>
|
||||
@@ -79,9 +113,20 @@ export default class NostrConnectComponent extends Component {
|
||||
{{#if this.nostrAuth.isMobile}}
|
||||
<p>Waiting for you to approve the connection in your mobile signer
|
||||
app...</p>
|
||||
<div class="mobile-connect-actions">
|
||||
<a href={{this.nostrAuth.connectUri}} class="btn btn-primary">
|
||||
Open Signer App
|
||||
</a>
|
||||
<button
|
||||
class="btn btn-outline"
|
||||
type="button"
|
||||
{{on "click" this.copyConnectUri}}
|
||||
>
|
||||
Copy Connection Link
|
||||
</button>
|
||||
</div>
|
||||
{{else}}
|
||||
<p>Scan this QR code with a compatible Nostr signer app (like
|
||||
Amber):</p>
|
||||
<p>Scan this QR code with a Nostr signer app (like Amber):</p>
|
||||
<div class="qr-code-container">
|
||||
<canvas {{qrCode this.nostrAuth.connectUri}}></canvas>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { fn } from '@ember/helper';
|
||||
import { and, eq } from 'ember-truth-helpers';
|
||||
import Blurhash from './blurhash';
|
||||
import Icon from './icon';
|
||||
import fadeInImage from '../modifiers/fade-in-image';
|
||||
import { on } from '@ember/modifier';
|
||||
import { modifier } from 'ember-modifier';
|
||||
import config from 'marco/config/environment';
|
||||
|
||||
export default class PhotoCarousel extends Component {
|
||||
@tracked canScrollLeft = false;
|
||||
@tracked canScrollRight = false;
|
||||
|
||||
internalEventId = null;
|
||||
carouselElement = null;
|
||||
|
||||
get photos() {
|
||||
return this.args.photos || [];
|
||||
}
|
||||
|
||||
get showChevrons() {
|
||||
// Only show chevrons if there's more than one photo
|
||||
return this.photos.length > 1;
|
||||
}
|
||||
|
||||
get cannotScrollLeft() {
|
||||
return !this.canScrollLeft;
|
||||
}
|
||||
|
||||
get cannotScrollRight() {
|
||||
return !this.canScrollRight;
|
||||
}
|
||||
|
||||
get isGalleryMain() {
|
||||
return this.args.variant === 'gallery-main';
|
||||
}
|
||||
|
||||
get isGalleryThumbnails() {
|
||||
return this.args.variant === 'gallery-thumbnails';
|
||||
}
|
||||
|
||||
get variantClass() {
|
||||
return this.args.variant || 'inline';
|
||||
}
|
||||
|
||||
lastResetKey = null;
|
||||
|
||||
resetScrollPosition = modifier((element, [resetKey]) => {
|
||||
if (resetKey !== undefined && resetKey !== this.lastResetKey) {
|
||||
this.lastResetKey = resetKey;
|
||||
element.scrollLeft = 0;
|
||||
setTimeout(() => this.updateScrollState(), 50);
|
||||
}
|
||||
});
|
||||
|
||||
isProgrammaticScroll = false;
|
||||
|
||||
scrollToNewPhoto = modifier((element, [eventId]) => {
|
||||
if (eventId && eventId !== this.lastEventId) {
|
||||
const isInitial = !this.lastEventId;
|
||||
this.lastEventId = eventId;
|
||||
|
||||
// Prevent feedback loop if this carousel initiated the change
|
||||
if (this.internalEventId === eventId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.internalEventId = eventId;
|
||||
this.isProgrammaticScroll = true;
|
||||
|
||||
const scrollAction = () => {
|
||||
const targetSlide = element.querySelector(
|
||||
`[data-event-id="${eventId}"]`
|
||||
);
|
||||
if (targetSlide) {
|
||||
if (isInitial) {
|
||||
const originalScrollBehavior = element.style.scrollBehavior;
|
||||
element.style.scrollBehavior = 'auto';
|
||||
element.scrollLeft = targetSlide.offsetLeft;
|
||||
|
||||
// Restore smooth scroll after the jump
|
||||
setTimeout(() => {
|
||||
element.style.scrollBehavior = originalScrollBehavior;
|
||||
this.isProgrammaticScroll = false;
|
||||
}, 50);
|
||||
} else {
|
||||
// Use native CSS smooth scrolling for subsequent clicks
|
||||
element.scrollLeft = targetSlide.offsetLeft;
|
||||
// Clear programmatic scroll flag after a delay to let scroll finish
|
||||
setTimeout(() => {
|
||||
this.isProgrammaticScroll = false;
|
||||
}, 500);
|
||||
}
|
||||
} else {
|
||||
this.isProgrammaticScroll = false;
|
||||
}
|
||||
};
|
||||
|
||||
if (isInitial) {
|
||||
// Execute immediately for the first render to prevent flash
|
||||
scrollAction();
|
||||
} else {
|
||||
// Allow DOM to update first for subsequent clicks
|
||||
setTimeout(scrollAction, 100);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setupCarousel = modifier((element) => {
|
||||
this.carouselElement = element;
|
||||
|
||||
// Defer the initial calculation slightly to ensure CSS and images have applied
|
||||
setTimeout(() => {
|
||||
this.updateScrollState();
|
||||
}, 50);
|
||||
|
||||
let resizeObserver;
|
||||
if (window.ResizeObserver) {
|
||||
resizeObserver = new ResizeObserver(() => this.updateScrollState());
|
||||
resizeObserver.observe(element);
|
||||
}
|
||||
|
||||
let intersectionObserver;
|
||||
if (
|
||||
this.args.onVisiblePhotoChange &&
|
||||
window.IntersectionObserver &&
|
||||
config.environment !== 'test'
|
||||
) {
|
||||
// Set up intersection observer to track which photo is currently "most" visible
|
||||
intersectionObserver = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (this.isProgrammaticScroll) return;
|
||||
|
||||
for (let entry of entries) {
|
||||
if (entry.isIntersecting && entry.intersectionRatio >= 0.5) {
|
||||
const eventId = entry.target.dataset.eventId;
|
||||
this.internalEventId = eventId;
|
||||
const photo = this.photos.find((p) => p.eventId === eventId);
|
||||
if (photo) {
|
||||
this.args.onVisiblePhotoChange(photo);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
root: element,
|
||||
threshold: 0.5,
|
||||
}
|
||||
);
|
||||
|
||||
const slides = element.querySelectorAll('.carousel-slide');
|
||||
slides.forEach((slide) => intersectionObserver.observe(slide));
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (resizeObserver) {
|
||||
resizeObserver.unobserve(element);
|
||||
}
|
||||
if (intersectionObserver) {
|
||||
intersectionObserver.disconnect();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@action
|
||||
updateScrollState() {
|
||||
if (!this.carouselElement) return;
|
||||
|
||||
const { scrollLeft, scrollWidth, clientWidth } = this.carouselElement;
|
||||
// tolerance of 1px for floating point rounding issues
|
||||
this.canScrollLeft = scrollLeft > 1;
|
||||
this.canScrollRight = scrollLeft + clientWidth < scrollWidth - 1;
|
||||
}
|
||||
|
||||
@action
|
||||
scrollLeft() {
|
||||
if (!this.carouselElement) return;
|
||||
this.carouselElement.scrollBy({
|
||||
left: -this.carouselElement.clientWidth,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
scrollRight() {
|
||||
if (!this.carouselElement) return;
|
||||
this.carouselElement.scrollBy({
|
||||
left: this.carouselElement.clientWidth,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
handlePhotoClick(photo) {
|
||||
if (this.args.onPhotoClick) {
|
||||
this.args.onPhotoClick(photo);
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if this.photos.length}}
|
||||
<div class="photo-carousel {{this.variantClass}}">
|
||||
<div
|
||||
class="photo-carousel-track"
|
||||
{{this.setupCarousel}}
|
||||
{{this.resetScrollPosition @resetKey}}
|
||||
{{this.scrollToNewPhoto @scrollToEventId}}
|
||||
{{on "scroll" this.updateScrollState}}
|
||||
>
|
||||
{{#each this.photos as |photo|}}
|
||||
{{! template-lint-disable no-inline-styles no-invalid-interactive }}
|
||||
<div
|
||||
class="carousel-slide
|
||||
{{if photo.isLandscape 'landscape' 'portrait'}}
|
||||
{{if
|
||||
(and @scrollToEventId (eq photo.eventId @scrollToEventId))
|
||||
'active'
|
||||
}}"
|
||||
style={{photo.style}}
|
||||
data-event-id={{photo.eventId}}
|
||||
{{on "click" (fn this.handlePhotoClick photo)}}
|
||||
>
|
||||
{{#if photo.blurhash}}
|
||||
<Blurhash
|
||||
@hash={{photo.blurhash}}
|
||||
@width={{32}}
|
||||
@height={{18}}
|
||||
class="place-header-photo-blur"
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.isGalleryMain}}
|
||||
<img
|
||||
data-src={{photo.url}}
|
||||
class="place-header-photo
|
||||
{{if photo.isLandscape 'landscape' 'portrait'}}"
|
||||
alt={{@name}}
|
||||
{{fadeInImage photo.url}}
|
||||
/>
|
||||
{{else if this.isGalleryThumbnails}}
|
||||
<img
|
||||
data-src={{if photo.thumbUrl photo.thumbUrl photo.url}}
|
||||
class="place-header-photo
|
||||
{{if photo.isLandscape 'landscape' 'portrait'}}"
|
||||
alt={{@name}}
|
||||
{{fadeInImage (if photo.thumbUrl photo.thumbUrl photo.url)}}
|
||||
/>
|
||||
{{else}}
|
||||
{{#if photo.isLandscape}}
|
||||
<picture>
|
||||
{{#if photo.thumbUrl}}
|
||||
<source
|
||||
media="(max-width: 768px)"
|
||||
data-srcset={{photo.thumbUrl}}
|
||||
/>
|
||||
{{/if}}
|
||||
<img
|
||||
data-src={{photo.url}}
|
||||
class="place-header-photo landscape"
|
||||
alt={{@name}}
|
||||
{{fadeInImage photo.url}}
|
||||
/>
|
||||
</picture>
|
||||
{{else}}
|
||||
{{! Portrait uses thumb everywhere if available }}
|
||||
<img
|
||||
data-src={{if photo.thumbUrl photo.thumbUrl photo.url}}
|
||||
class="place-header-photo portrait"
|
||||
alt={{@name}}
|
||||
{{fadeInImage (if photo.thumbUrl photo.thumbUrl photo.url)}}
|
||||
/>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/each}}
|
||||
|
||||
<div class="carousel-placeholder"></div>
|
||||
</div>
|
||||
|
||||
{{#if this.showChevrons}}
|
||||
<button
|
||||
type="button"
|
||||
class="carousel-nav-btn prev
|
||||
{{if this.cannotScrollLeft 'disabled'}}"
|
||||
{{on "click" this.scrollLeft}}
|
||||
disabled={{this.cannotScrollLeft}}
|
||||
aria-label="Previous photo"
|
||||
>
|
||||
<Icon
|
||||
@name="chevron-left"
|
||||
@color="currentColor"
|
||||
@size={{if (eq @variant "gallery-main") 24 16}}
|
||||
/>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="carousel-nav-btn next
|
||||
{{if this.cannotScrollRight 'disabled'}}"
|
||||
{{on "click" this.scrollRight}}
|
||||
disabled={{this.cannotScrollRight}}
|
||||
aria-label="Next photo"
|
||||
>
|
||||
<Icon
|
||||
@name="chevron-right"
|
||||
@color="currentColor"
|
||||
@size={{if (eq @variant "gallery-main") 24 16}}
|
||||
/>
|
||||
</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { on } from '@ember/modifier';
|
||||
import { fn } from '@ember/helper';
|
||||
import { service } from '@ember/service';
|
||||
import { modifier } from 'ember-modifier';
|
||||
import { task } from 'ember-concurrency';
|
||||
import { EventFactory } from 'applesauce-factory';
|
||||
import config from 'marco/config/environment';
|
||||
import DropdownMenu from './dropdown-menu';
|
||||
import PhotoCarousel from './photo-carousel';
|
||||
import Icon from './icon';
|
||||
|
||||
const GalleryContent = <template>
|
||||
<div
|
||||
class="photo-gallery-overlay"
|
||||
role="dialog"
|
||||
tabindex="-1"
|
||||
{{on "click" @handleBackgroundClick}}
|
||||
{{@bindKeyboard @handleKeydown}}
|
||||
>
|
||||
{{! template-lint-disable no-invalid-interactive }}
|
||||
<div
|
||||
class="photo-gallery-content"
|
||||
data-current-event-id={{@currentPhoto.eventId}}
|
||||
>
|
||||
<div class="actions-btn-container">
|
||||
<DropdownMenu
|
||||
@iconSize={{24}}
|
||||
@triggerIcon="more-horizontal"
|
||||
@iconColor="white"
|
||||
as |closeMenu|
|
||||
>
|
||||
<button
|
||||
class="dropdown-item"
|
||||
type="button"
|
||||
{{on "click" (fn @copyEventId closeMenu)}}
|
||||
>Copy Photo Event ID</button>
|
||||
{{#if @canDeletePhoto}}
|
||||
<button
|
||||
class="dropdown-item text-danger"
|
||||
type="button"
|
||||
{{on "click" (fn @deletePhotoTask.perform closeMenu)}}
|
||||
>Delete Photo</button>
|
||||
{{/if}}
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="close-btn btn-text"
|
||||
{{on "click" @handleClose}}
|
||||
aria-label="Close gallery"
|
||||
title="Close"
|
||||
>
|
||||
<Icon @name="x" @size={{24}} @color="white" />
|
||||
</button>
|
||||
|
||||
<div class="main-photo-container">
|
||||
<PhotoCarousel
|
||||
@variant="gallery-main"
|
||||
@photos={{@photos}}
|
||||
@scrollToEventId={{@currentPhoto.eventId}}
|
||||
@onVisiblePhotoChange={{@handleVisiblePhotoChange}}
|
||||
@name={{@placeName}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="thumbnail-strip-container">
|
||||
<PhotoCarousel
|
||||
@variant="gallery-thumbnails"
|
||||
@photos={{@photos}}
|
||||
@scrollToEventId={{@currentPhoto.eventId}}
|
||||
@onPhotoClick={{@selectPhoto}}
|
||||
@name={{@placeName}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>;
|
||||
|
||||
export default class PhotoGallery extends Component {
|
||||
get isTesting() {
|
||||
return config.environment === 'test';
|
||||
}
|
||||
|
||||
get destinationElement() {
|
||||
return document.getElementById('modal-portal') || document.body;
|
||||
}
|
||||
|
||||
@service toast;
|
||||
@service nostrAuth;
|
||||
@service nostrData;
|
||||
@service nostrRelay;
|
||||
@service blossom;
|
||||
@service settings;
|
||||
|
||||
@tracked currentPhoto = this.args.selectedPhoto || this.args.photos?.[0];
|
||||
|
||||
get isCreator() {
|
||||
return (
|
||||
this.currentPhoto?.pubkey &&
|
||||
this.nostrAuth.pubkey &&
|
||||
this.currentPhoto.pubkey === this.nostrAuth.pubkey
|
||||
);
|
||||
}
|
||||
|
||||
get canDeletePhoto() {
|
||||
return (
|
||||
this.isCreator && this.settings.experimentalEnablePhotoDeletion === true
|
||||
);
|
||||
}
|
||||
|
||||
bindKeyboard = modifier((element, [handler]) => {
|
||||
document.addEventListener('keydown', handler);
|
||||
return () => document.removeEventListener('keydown', handler);
|
||||
});
|
||||
|
||||
@action
|
||||
handleClose() {
|
||||
if (this.args.onClose) {
|
||||
this.args.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
handleBackgroundClick(e) {
|
||||
// Don't close if clicking on thumbnails, nav buttons, or the close button itself
|
||||
if (
|
||||
e.target.closest('.thumbnail-strip-container') ||
|
||||
e.target.closest('.carousel-nav-btn') ||
|
||||
e.target.closest('.close-btn') ||
|
||||
e.target.closest('.actions-btn-container')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.handleClose();
|
||||
}
|
||||
|
||||
@action
|
||||
selectPhoto(photo) {
|
||||
this.currentPhoto = photo;
|
||||
}
|
||||
|
||||
@action
|
||||
handleVisiblePhotoChange(photo) {
|
||||
if (this.currentPhoto !== photo) {
|
||||
this.currentPhoto = photo;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
handleKeydown(e) {
|
||||
if (!this.args.photos || this.args.photos.length === 0) return;
|
||||
|
||||
if (e.key === 'Escape') {
|
||||
this.handleClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const currentIndex = this.args.photos.indexOf(this.currentPhoto);
|
||||
if (currentIndex === -1) return;
|
||||
|
||||
if (e.key === 'ArrowLeft' && currentIndex > 0) {
|
||||
this.currentPhoto = this.args.photos[currentIndex - 1];
|
||||
} else if (
|
||||
e.key === 'ArrowRight' &&
|
||||
currentIndex < this.args.photos.length - 1
|
||||
) {
|
||||
this.currentPhoto = this.args.photos[currentIndex + 1];
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
async copyEventId(closeMenu) {
|
||||
if (this.currentPhoto?.eventId) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(this.currentPhoto.eventId);
|
||||
this.toast.show('Event ID copied to clipboard');
|
||||
} catch (err) {
|
||||
console.error('Failed to copy event ID:', err);
|
||||
this.toast.show('Failed to copy event ID');
|
||||
}
|
||||
}
|
||||
closeMenu();
|
||||
}
|
||||
|
||||
deletePhotoTask = task(async (closeMenu) => {
|
||||
if (
|
||||
!confirm(
|
||||
'Are you sure you want to delete this photo? This cannot be undone.'
|
||||
)
|
||||
) {
|
||||
if (closeMenu) closeMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const eventId = this.currentPhoto.eventId;
|
||||
|
||||
// Publish Nostr kind: 5 deletion event first so we don't end up with dead blossom links on a failure
|
||||
const factory = new EventFactory({ signer: this.nostrAuth.signer });
|
||||
const tags = [['e', eventId]];
|
||||
|
||||
if (this.currentPhoto.placeIdentifier) {
|
||||
tags.push(['i', this.currentPhoto.placeIdentifier]);
|
||||
}
|
||||
|
||||
const template = {
|
||||
kind: 5,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
content: 'Deleted photo',
|
||||
tags,
|
||||
};
|
||||
|
||||
const event = await factory.sign(template);
|
||||
await this.nostrRelay.publish(this.nostrData.activeWriteRelays, event);
|
||||
|
||||
// Remove from local store by adding the kind 5 to it
|
||||
this.nostrData.store.add(event);
|
||||
|
||||
// Now that the event is published, try to delete from Blossom
|
||||
const hashRegex = /[0-9a-f]{64}/i;
|
||||
|
||||
if (this.currentPhoto.url) {
|
||||
const match = this.currentPhoto.url.match(hashRegex);
|
||||
if (match) {
|
||||
try {
|
||||
await this.blossom.delete(match[0]);
|
||||
} catch (e) {
|
||||
console.warn('Failed to delete main image from blossom:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.currentPhoto.thumbUrl) {
|
||||
const match = this.currentPhoto.thumbUrl.match(hashRegex);
|
||||
if (match) {
|
||||
try {
|
||||
await this.blossom.delete(match[0]);
|
||||
} catch (e) {
|
||||
console.warn('Failed to delete thumb image from blossom:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.toast.show('Photo deleted successfully');
|
||||
|
||||
if (closeMenu) closeMenu();
|
||||
this.handleClose();
|
||||
} catch (e) {
|
||||
console.error('Failed to delete photo:', e);
|
||||
this.toast.show('Failed to delete photo: ' + e.message);
|
||||
if (closeMenu) closeMenu();
|
||||
}
|
||||
});
|
||||
|
||||
<template>
|
||||
{{#if this.isTesting}}
|
||||
<GalleryContent
|
||||
@handleBackgroundClick={{this.handleBackgroundClick}}
|
||||
@bindKeyboard={{this.bindKeyboard}}
|
||||
@handleKeydown={{this.handleKeydown}}
|
||||
@copyEventId={{this.copyEventId}}
|
||||
@canDeletePhoto={{this.canDeletePhoto}}
|
||||
@deletePhotoTask={{this.deletePhotoTask}}
|
||||
@handleClose={{this.handleClose}}
|
||||
@photos={{@photos}}
|
||||
@currentPhoto={{this.currentPhoto}}
|
||||
@handleVisiblePhotoChange={{this.handleVisiblePhotoChange}}
|
||||
@placeName={{@placeName}}
|
||||
@selectPhoto={{this.selectPhoto}}
|
||||
/>
|
||||
{{else}}
|
||||
{{#in-element this.destinationElement}}
|
||||
<GalleryContent
|
||||
@handleBackgroundClick={{this.handleBackgroundClick}}
|
||||
@bindKeyboard={{this.bindKeyboard}}
|
||||
@handleKeydown={{this.handleKeydown}}
|
||||
@copyEventId={{this.copyEventId}}
|
||||
@canDeletePhoto={{this.canDeletePhoto}}
|
||||
@deletePhotoTask={{this.deletePhotoTask}}
|
||||
@handleClose={{this.handleClose}}
|
||||
@photos={{@photos}}
|
||||
@currentPhoto={{this.currentPhoto}}
|
||||
@handleVisiblePhotoChange={{this.handleVisiblePhotoChange}}
|
||||
@placeName={{@placeName}}
|
||||
@selectPhoto={{this.selectPhoto}}
|
||||
/>
|
||||
{{/in-element}}
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -6,12 +6,15 @@ import { humanizeOsmTag } from '../utils/format-text';
|
||||
import { getLocalizedName, getPlaceType } from '../utils/osm';
|
||||
import { mapToStorageSchema } from '../utils/place-mapping';
|
||||
import { getSocialInfo } from '../utils/social-links';
|
||||
import { parsePlacePhotos } from '../utils/nostr';
|
||||
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 PhotoCarousel from './photo-carousel';
|
||||
import PhotoGallery from './photo-gallery';
|
||||
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
@@ -19,10 +22,22 @@ import { action } from '@ember/object';
|
||||
export default class PlaceDetails extends Component {
|
||||
@service storage;
|
||||
@service nostrAuth;
|
||||
@service nostrData;
|
||||
@service mapUi;
|
||||
@tracked isEditing = false;
|
||||
@tracked showLists = false;
|
||||
@tracked isPhotoUploadActive = false;
|
||||
@tracked isConnectingNostr = false;
|
||||
@tracked isGalleryOpen = false;
|
||||
@tracked selectedGalleryPhoto = null;
|
||||
@tracked isPhotoUploadModalOpen = false;
|
||||
@tracked isNostrConnectModalOpen = false;
|
||||
@tracked newlyUploadedPhotoId = null;
|
||||
|
||||
@action
|
||||
handleUploadStateChange(isActive) {
|
||||
this.isPhotoUploadActive = isActive;
|
||||
}
|
||||
|
||||
@action
|
||||
openPhotoUploadModal(e) {
|
||||
@@ -37,8 +52,20 @@ export default class PlaceDetails extends Component {
|
||||
}
|
||||
|
||||
@action
|
||||
closePhotoUploadModal() {
|
||||
closePhotoUploadModal(eventId) {
|
||||
if (this.isPhotoUploadActive) return;
|
||||
this.isPhotoUploadModalOpen = false;
|
||||
if (typeof eventId === 'string') {
|
||||
this.newlyUploadedPhotoId = eventId;
|
||||
|
||||
// Allow DOM to update first, then scroll to the top to show the new photo in the carousel
|
||||
setTimeout(() => {
|
||||
const sidebar = document.querySelector('.sidebar-content');
|
||||
if (sidebar) {
|
||||
sidebar.scrollTop = 0;
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -76,6 +103,16 @@ export default class PlaceDetails extends Component {
|
||||
return this.place.title || getLocalizedName(this.tags) || 'Unnamed Place';
|
||||
}
|
||||
|
||||
get photos() {
|
||||
const rawPhotos = this.nostrData.placePhotos;
|
||||
const parsedPhotos = parsePlacePhotos(rawPhotos);
|
||||
|
||||
return parsedPhotos.map((photo) => ({
|
||||
...photo,
|
||||
style: htmlSafe(`--slide-ratio: ${photo.aspectRatio};`),
|
||||
}));
|
||||
}
|
||||
|
||||
@action
|
||||
startEditing() {
|
||||
if (!this.isSaved) return; // Only allow editing saved places
|
||||
@@ -309,9 +346,21 @@ export default class PlaceDetails extends Component {
|
||||
|
||||
get osmUrl() {
|
||||
const id = this.place.osmId;
|
||||
if (!id) return null;
|
||||
const type = this.place.osmType || 'node';
|
||||
return `https://www.openstreetmap.org/${type}/${id}`;
|
||||
if (id) {
|
||||
const type = this.place.osmType || 'node';
|
||||
return `https://www.openstreetmap.org/${type}/${id}`;
|
||||
}
|
||||
|
||||
const lat = this.place.lat;
|
||||
const lon = this.place.lon;
|
||||
if (!lat || !lon) return null;
|
||||
|
||||
const viewLat = this.mapUi.currentCenter?.lat ?? lat;
|
||||
const viewLon = this.mapUi.currentCenter?.lon ?? lon;
|
||||
const zoom = this.mapUi.currentZoom ?? 17;
|
||||
const roundedZoom = Math.round(zoom);
|
||||
|
||||
return `https://www.openstreetmap.org/search?lat=${lat}&lon=${lon}&zoom=${roundedZoom}#map=${roundedZoom}/${Number(viewLat).toFixed(5)}/${Number(viewLon).toFixed(5)}`;
|
||||
}
|
||||
|
||||
get gmapsUrl() {
|
||||
@@ -330,6 +379,18 @@ export default class PlaceDetails extends Component {
|
||||
return !!this.place.description;
|
||||
}
|
||||
|
||||
@action
|
||||
openGallery(photo) {
|
||||
this.selectedGalleryPhoto = photo;
|
||||
this.isGalleryOpen = true;
|
||||
}
|
||||
|
||||
@action
|
||||
closeGallery() {
|
||||
this.isGalleryOpen = false;
|
||||
this.selectedGalleryPhoto = null;
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="place-details">
|
||||
{{#if this.isEditing}}
|
||||
@@ -339,6 +400,14 @@ export default class PlaceDetails extends Component {
|
||||
@onCancel={{this.cancelEditing}}
|
||||
/>
|
||||
{{else}}
|
||||
<PhotoCarousel
|
||||
@variant="inline"
|
||||
@photos={{this.photos}}
|
||||
@name={{this.name}}
|
||||
@resetKey={{this.place.osmId}}
|
||||
@scrollToEventId={{this.newlyUploadedPhotoId}}
|
||||
@onPhotoClick={{this.openGallery}}
|
||||
/>
|
||||
<h3>{{this.name}}</h3>
|
||||
<p class="place-type">
|
||||
{{this.type}}
|
||||
@@ -535,14 +604,18 @@ export default class PlaceDetails extends Component {
|
||||
|
||||
</div>
|
||||
|
||||
{{#if this.osmUrl}}
|
||||
{{#if this.place.osmId}}
|
||||
<div class="meta-info">
|
||||
<p class="content-with-icon">
|
||||
<Icon @name="camera" />
|
||||
<Icon @name="feather-camera" />
|
||||
<span>
|
||||
<a href="#" {{on "click" this.openPhotoUploadModal}}>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-link"
|
||||
{{on "click" this.openPhotoUploadModal}}
|
||||
>
|
||||
Add a photo
|
||||
</a>
|
||||
</button>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
@@ -550,8 +623,15 @@ export default class PlaceDetails extends Component {
|
||||
</div>
|
||||
|
||||
{{#if this.isPhotoUploadModalOpen}}
|
||||
<Modal @onClose={{this.closePhotoUploadModal}}>
|
||||
<PlacePhotoUpload @place={{this.saveablePlace}} />
|
||||
<Modal
|
||||
@onClose={{this.closePhotoUploadModal}}
|
||||
@disableClose={{this.isPhotoUploadActive}}
|
||||
>
|
||||
<PlacePhotoUpload
|
||||
@place={{this.saveablePlace}}
|
||||
@onClose={{this.closePhotoUploadModal}}
|
||||
@onUploadStateChange={{this.handleUploadStateChange}}
|
||||
/>
|
||||
</Modal>
|
||||
{{/if}}
|
||||
|
||||
@@ -560,5 +640,14 @@ export default class PlaceDetails extends Component {
|
||||
<NostrConnect @onConnect={{this.onNostrConnected}} />
|
||||
</Modal>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.isGalleryOpen}}
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedGalleryPhoto}}
|
||||
@placeName={{this.name}}
|
||||
@onClose={{this.closeGallery}}
|
||||
/>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ export default class PlaceListsManager extends Component {
|
||||
checked={{this.isSaved}}
|
||||
{{on "change" this.toggleSaved}}
|
||||
/>
|
||||
<span class="list-color"></span>
|
||||
<span class="list-color-dot"></span>
|
||||
<span class="list-name">Saved places</span>
|
||||
</label>
|
||||
</div>
|
||||
@@ -122,7 +122,7 @@ export default class PlaceListsManager extends Component {
|
||||
/>
|
||||
{{! template-lint-disable no-inline-styles }}
|
||||
<span
|
||||
class="list-color"
|
||||
class="list-color-dot"
|
||||
style={{this.styleFor list.color}}
|
||||
></span>
|
||||
<span class="list-name">{{list.title}}</span>
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { task } from 'ember-concurrency';
|
||||
import Icon from '#components/icon';
|
||||
import { on } from '@ember/modifier';
|
||||
import { fn } from '@ember/helper';
|
||||
import { isMobile } from '../utils/device';
|
||||
import Blurhash from './blurhash';
|
||||
|
||||
const MAX_IMAGE_DIMENSION = 1920;
|
||||
const IMAGE_QUALITY = 0.9;
|
||||
const MAX_THUMBNAIL_DIMENSION = 350;
|
||||
const THUMBNAIL_QUALITY = 0.9;
|
||||
|
||||
export default class PlacePhotoUploadItem extends Component {
|
||||
@service blossom;
|
||||
@service imageProcessor;
|
||||
@service toast;
|
||||
|
||||
@tracked thumbnailUrl = '';
|
||||
@tracked blurhash = '';
|
||||
@tracked error = '';
|
||||
@tracked statusText = '';
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
if (this.args.file) {
|
||||
this.thumbnailUrl = URL.createObjectURL(this.args.file);
|
||||
this.uploadTask.perform(this.args.file);
|
||||
}
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
super.willDestroy(...arguments);
|
||||
if (this.thumbnailUrl) {
|
||||
URL.revokeObjectURL(this.thumbnailUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
showErrorToast() {
|
||||
if (this.error) {
|
||||
this.toast.show(this.error);
|
||||
}
|
||||
}
|
||||
|
||||
uploadTask = task(async (file) => {
|
||||
this.error = '';
|
||||
this.statusText = 'Processing';
|
||||
try {
|
||||
// 1. Process main image and generate blurhash in worker
|
||||
const mainData = await this.imageProcessor.process(
|
||||
file,
|
||||
MAX_IMAGE_DIMENSION,
|
||||
IMAGE_QUALITY,
|
||||
true // computeBlurhash
|
||||
);
|
||||
|
||||
this.blurhash = mainData.blurhash;
|
||||
|
||||
// 2. Process thumbnail (no blurhash needed)
|
||||
const thumbData = await this.imageProcessor.process(
|
||||
file,
|
||||
MAX_THUMBNAIL_DIMENSION,
|
||||
THUMBNAIL_QUALITY,
|
||||
false
|
||||
);
|
||||
|
||||
// 3. Upload main image
|
||||
// 4. Upload thumbnail
|
||||
let mainResult, thumbResult;
|
||||
const isMobileDevice = isMobile();
|
||||
|
||||
const mainProgress = (status) => {
|
||||
if (status === 'signing') this.statusText = 'Signing photo upload';
|
||||
if (status === 'uploading') this.statusText = 'Uploading photo';
|
||||
};
|
||||
|
||||
const thumbProgress = (status) => {
|
||||
if (status === 'signing') this.statusText = 'Signing thumbnail upload';
|
||||
if (status === 'uploading') this.statusText = 'Uploading thumbnail';
|
||||
};
|
||||
|
||||
if (isMobileDevice) {
|
||||
// Mobile: sequential uploads to preserve bandwidth and memory
|
||||
mainResult = await this.blossom.upload(mainData.blob, {
|
||||
sequential: true,
|
||||
onProgress: mainProgress,
|
||||
});
|
||||
thumbResult = await this.blossom.upload(thumbData.blob, {
|
||||
sequential: true,
|
||||
onProgress: thumbProgress,
|
||||
});
|
||||
} else {
|
||||
// Desktop: concurrent uploads
|
||||
const mainUploadPromise = this.blossom.upload(mainData.blob, {
|
||||
onProgress: mainProgress,
|
||||
});
|
||||
const thumbUploadPromise = this.blossom.upload(thumbData.blob, {
|
||||
onProgress: thumbProgress,
|
||||
});
|
||||
|
||||
[mainResult, thumbResult] = await Promise.all([
|
||||
mainUploadPromise,
|
||||
thumbUploadPromise,
|
||||
]);
|
||||
}
|
||||
|
||||
if (this.args.onSuccess) {
|
||||
this.args.onSuccess({
|
||||
file,
|
||||
url: mainResult.url,
|
||||
fallbackUrls: mainResult.fallbackUrls,
|
||||
thumbUrl: thumbResult.url,
|
||||
blurhash: mainData.blurhash,
|
||||
type: 'image/jpeg',
|
||||
dim: mainData.dim,
|
||||
hash: mainResult.hash,
|
||||
thumbHash: thumbResult.hash,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
this.error = e.message;
|
||||
}
|
||||
});
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="photo-upload-item
|
||||
{{if this.uploadTask.isRunning 'is-uploading'}}
|
||||
{{if this.error 'has-error'}}"
|
||||
>
|
||||
{{#if this.blurhash}}
|
||||
<Blurhash @hash={{this.blurhash}} class="place-header-photo-blur" />
|
||||
{{/if}}
|
||||
<img src={{this.thumbnailUrl}} alt="thumbnail" />
|
||||
|
||||
{{#if this.uploadTask.isRunning}}
|
||||
<div class="overlay">
|
||||
<Icon
|
||||
@name="loading-ring"
|
||||
@size={{24}}
|
||||
@color="white"
|
||||
class="spin-animation"
|
||||
/>
|
||||
{{#if this.statusText}}
|
||||
<span class="upload-status-text">{{this.statusText}}</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.error}}
|
||||
<button
|
||||
type="button"
|
||||
class="overlay error-overlay"
|
||||
title={{this.error}}
|
||||
{{on "click" this.showErrorToast}}
|
||||
>
|
||||
<Icon @name="alert-circle" @size={{24}} @color="white" />
|
||||
</button>
|
||||
{{/if}}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn-remove-photo"
|
||||
title="Remove photo"
|
||||
{{on "click" (fn @onRemove @file)}}
|
||||
>
|
||||
<Icon @name="x" @size={{16}} @color="white" />
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
@@ -1,18 +1,32 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { service } from '@ember/service';
|
||||
import { on } from '@ember/modifier';
|
||||
import { EventFactory } from 'applesauce-core';
|
||||
import { task } from 'ember-concurrency';
|
||||
import Geohash from 'latlon-geohash';
|
||||
import PlacePhotoUploadItem from './place-photo-upload-item';
|
||||
import Icon from '#components/icon';
|
||||
import { getSuggestedPhotoTags } from '../utils/photo-tag-suggestions';
|
||||
import capitalize from '../helpers/capitalize';
|
||||
import includes from '../helpers/includes';
|
||||
import { fn } from '@ember/helper';
|
||||
import { or, not } from 'ember-truth-helpers';
|
||||
|
||||
export default class PlacePhotoUpload extends Component {
|
||||
@service nostrAuth;
|
||||
@service nostrRelay;
|
||||
@service nostrData;
|
||||
@service blossom;
|
||||
@service toast;
|
||||
|
||||
@tracked photoUrl = '';
|
||||
@tracked status = '';
|
||||
@tracked file = null;
|
||||
@tracked uploadedPhoto = null;
|
||||
@tracked error = '';
|
||||
@tracked isPublishing = false;
|
||||
@tracked isDragging = false;
|
||||
@tracked selectedTags = [];
|
||||
|
||||
get place() {
|
||||
return this.args.place || {};
|
||||
@@ -22,24 +36,101 @@ export default class PlacePhotoUpload extends Component {
|
||||
return this.place.title || 'this place';
|
||||
}
|
||||
|
||||
@action
|
||||
async uploadPhoto(event) {
|
||||
event.preventDefault();
|
||||
this.error = '';
|
||||
this.status = 'Uploading...';
|
||||
get allUploaded() {
|
||||
return (
|
||||
this.file && this.uploadedPhoto && this.file === this.uploadedPhoto.file
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
// Mock upload
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
this.photoUrl =
|
||||
'https://dummyimage.com/600x400/000/fff.jpg&text=Mock+Place+Photo';
|
||||
this.status = 'Photo uploaded! Ready to publish.';
|
||||
} catch (e) {
|
||||
this.error = 'Upload failed: ' + e.message;
|
||||
this.status = '';
|
||||
get suggestedTags() {
|
||||
return getSuggestedPhotoTags(this.place);
|
||||
}
|
||||
|
||||
@action
|
||||
handleFileSelect(event) {
|
||||
this.addFile(event.target.files[0]);
|
||||
event.target.value = ''; // Reset input
|
||||
}
|
||||
|
||||
@action
|
||||
handleDragOver(event) {
|
||||
event.preventDefault();
|
||||
this.isDragging = true;
|
||||
}
|
||||
|
||||
@action
|
||||
handleDragLeave(event) {
|
||||
event.preventDefault();
|
||||
this.isDragging = false;
|
||||
}
|
||||
|
||||
@action
|
||||
handleDrop(event) {
|
||||
event.preventDefault();
|
||||
this.isDragging = false;
|
||||
if (event.dataTransfer.files.length > 0) {
|
||||
this.addFile(event.dataTransfer.files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
addFile(file) {
|
||||
if (!file || !file.type.startsWith('image/')) {
|
||||
this.error = 'Please select a valid image file.';
|
||||
return;
|
||||
}
|
||||
this.error = '';
|
||||
// If a photo was already uploaded but not published, delete it from the server
|
||||
if (this.uploadedPhoto) {
|
||||
this.deletePhotoTask.perform(this.uploadedPhoto);
|
||||
}
|
||||
this.file = file;
|
||||
this.uploadedPhoto = null;
|
||||
if (this.args.onUploadStateChange) {
|
||||
this.args.onUploadStateChange(true);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
handleUploadSuccess(photoData) {
|
||||
this.uploadedPhoto = photoData;
|
||||
}
|
||||
|
||||
@action
|
||||
removeFile() {
|
||||
if (this.uploadedPhoto) {
|
||||
this.deletePhotoTask.perform(this.uploadedPhoto);
|
||||
}
|
||||
this.file = null;
|
||||
this.uploadedPhoto = null;
|
||||
this.selectedTags = [];
|
||||
if (this.args.onUploadStateChange) {
|
||||
this.args.onUploadStateChange(false);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
toggleTag(tag) {
|
||||
if (this.selectedTags.includes(tag)) {
|
||||
this.selectedTags = [];
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedTags = [tag];
|
||||
}
|
||||
|
||||
deletePhotoTask = task(async (photoData) => {
|
||||
try {
|
||||
if (photoData.hash) {
|
||||
await this.blossom.delete(photoData.hash);
|
||||
}
|
||||
if (photoData.thumbHash) {
|
||||
await this.blossom.delete(photoData.thumbHash);
|
||||
}
|
||||
} catch (e) {
|
||||
this.toast.show(`Failed to delete photo from server: ${e.message}`, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
@action
|
||||
async publish() {
|
||||
if (!this.nostrAuth.isConnected) {
|
||||
@@ -47,8 +138,8 @@ export default class PlacePhotoUpload extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.photoUrl) {
|
||||
this.error = 'Please upload a photo.';
|
||||
if (!this.allUploaded) {
|
||||
this.error = 'Please wait for all photos to finish uploading.';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,14 +151,18 @@ export default class PlacePhotoUpload extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
this.status = 'Publishing event...';
|
||||
this.error = '';
|
||||
this.isPublishing = true;
|
||||
|
||||
try {
|
||||
const factory = new EventFactory({ signer: this.nostrAuth.signer });
|
||||
|
||||
const tags = [['i', `osm:${osmType}:${osmId}`]];
|
||||
|
||||
for (const tag of this.selectedTags) {
|
||||
tags.push(['t', tag]);
|
||||
}
|
||||
|
||||
if (lat && lon) {
|
||||
tags.push(['g', Geohash.encode(lat, lon, 4)]);
|
||||
tags.push(['g', Geohash.encode(lat, lon, 6)]);
|
||||
@@ -75,13 +170,32 @@ export default class PlacePhotoUpload extends Component {
|
||||
tags.push(['g', Geohash.encode(lat, lon, 9)]);
|
||||
}
|
||||
|
||||
tags.push([
|
||||
'imeta',
|
||||
`url ${this.photoUrl}`,
|
||||
'm image/jpeg',
|
||||
'dim 600x400',
|
||||
'alt A photo of a place',
|
||||
]);
|
||||
const photo = this.uploadedPhoto;
|
||||
const imeta = ['imeta', `url ${photo.url}`];
|
||||
|
||||
imeta.push(`m ${photo.type}`);
|
||||
|
||||
if (photo.dim) {
|
||||
imeta.push(`dim ${photo.dim}`);
|
||||
}
|
||||
|
||||
imeta.push('alt A photo of a place');
|
||||
|
||||
if (photo.fallbackUrls && photo.fallbackUrls.length > 0) {
|
||||
for (const fallbackUrl of photo.fallbackUrls) {
|
||||
imeta.push(`fallback ${fallbackUrl}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (photo.thumbUrl) {
|
||||
imeta.push(`thumb ${photo.thumbUrl}`);
|
||||
}
|
||||
|
||||
if (photo.blurhash) {
|
||||
imeta.push(`blurhash ${photo.blurhash}`);
|
||||
}
|
||||
|
||||
tags.push(imeta);
|
||||
|
||||
// NIP-XX draft Place Photo event
|
||||
const template = {
|
||||
@@ -90,20 +204,31 @@ export default class PlacePhotoUpload extends Component {
|
||||
tags,
|
||||
};
|
||||
|
||||
// Ensure created_at is present before signing
|
||||
if (!template.created_at) {
|
||||
template.created_at = Math.floor(Date.now() / 1000);
|
||||
}
|
||||
|
||||
const event = await factory.sign(template);
|
||||
await this.nostrRelay.publish(event);
|
||||
await this.nostrRelay.publish(this.nostrData.activeWriteRelays, event);
|
||||
this.nostrData.store.add(event);
|
||||
|
||||
this.status = 'Published successfully!';
|
||||
// Reset form
|
||||
this.photoUrl = '';
|
||||
this.toast.show('Photo published successfully');
|
||||
|
||||
// Clear out the file so user can upload more or be done
|
||||
this.file = null;
|
||||
this.uploadedPhoto = null;
|
||||
|
||||
if (this.args.onUploadStateChange) {
|
||||
this.args.onUploadStateChange(false);
|
||||
}
|
||||
|
||||
if (this.args.onClose) {
|
||||
this.args.onClose(event.id);
|
||||
}
|
||||
} catch (e) {
|
||||
this.error = 'Failed to publish: ' + e.message;
|
||||
this.status = '';
|
||||
} finally {
|
||||
this.isPublishing = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,31 +242,68 @@ export default class PlacePhotoUpload extends Component {
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.status}}
|
||||
<div class="alert alert-info">
|
||||
{{this.status}}
|
||||
{{#if this.file}}
|
||||
<div class="photo-grid">
|
||||
<PlacePhotoUploadItem
|
||||
@file={{this.file}}
|
||||
@onSuccess={{this.handleUploadSuccess}}
|
||||
@onRemove={{this.removeFile}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{{#if this.suggestedTags.length}}
|
||||
<div class="photo-tag-suggestions">
|
||||
<p class="photo-tag-suggestions-title">
|
||||
Choose a tag/category (optional):
|
||||
</p>
|
||||
<div class="photo-tag-suggestions-list">
|
||||
{{#each this.suggestedTags as |tag|}}
|
||||
<button
|
||||
type="button"
|
||||
class="photo-tag-chip
|
||||
{{if (includes this.selectedTags tag) 'is-selected'}}"
|
||||
{{on "click" (fn this.toggleTag tag)}}
|
||||
>
|
||||
{{capitalize tag}}
|
||||
</button>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary btn-publish"
|
||||
disabled={{or (not this.allUploaded) this.isPublishing}}
|
||||
{{on "click" this.publish}}
|
||||
>
|
||||
{{#if this.isPublishing}}
|
||||
Publishing...
|
||||
{{else}}
|
||||
Publish Photo
|
||||
{{/if}}
|
||||
</button>
|
||||
{{else}}
|
||||
<div
|
||||
class="dropzone {{if this.isDragging 'is-dragging'}}"
|
||||
{{on "dragover" this.handleDragOver}}
|
||||
{{on "dragleave" this.handleDragLeave}}
|
||||
{{on "drop" this.handleDrop}}
|
||||
>
|
||||
<label for="photo-upload-input" class="dropzone-label">
|
||||
<Icon @name="upload-cloud" @size={{48}} @color="#ccc" />
|
||||
<p>Drag and drop a photo here, or click to browse</p>
|
||||
</label>
|
||||
<input
|
||||
id="photo-upload-input"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
class="file-input-hidden"
|
||||
disabled={{this.isPublishing}}
|
||||
{{on "change" this.handleFileSelect}}
|
||||
/>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<form {{on "submit" this.uploadPhoto}}>
|
||||
{{#if this.photoUrl}}
|
||||
<div class="preview-group">
|
||||
<p>Photo Preview:</p>
|
||||
<img src={{this.photoUrl}} alt="Preview" />
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
{{on "click" this.publish}}
|
||||
>
|
||||
Publish Event (kind: 360)
|
||||
</button>
|
||||
{{else}}
|
||||
<button type="submit" class="btn btn-secondary">
|
||||
Mock Upload Photo
|
||||
</button>
|
||||
{{/if}}
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -5,15 +5,19 @@ import { on } from '@ember/modifier';
|
||||
import { fn } from '@ember/helper';
|
||||
import or from 'ember-truth-helpers/helpers/or';
|
||||
import eq from 'ember-truth-helpers/helpers/eq';
|
||||
import and from 'ember-truth-helpers/helpers/and';
|
||||
import not from 'ember-truth-helpers/helpers/not';
|
||||
import PlaceDetails from './place-details';
|
||||
import Icon from './icon';
|
||||
import humanizeOsmTag from '../helpers/humanize-osm-tag';
|
||||
import { getLocalizedName, getPlaceType } from '../utils/osm';
|
||||
import restoreScroll from '../modifiers/restore-scroll';
|
||||
|
||||
export default class PlacesSidebar extends Component {
|
||||
@service storage;
|
||||
@service router;
|
||||
@service mapUi;
|
||||
@service nostrData;
|
||||
|
||||
@action
|
||||
createNewPlace() {
|
||||
@@ -149,9 +153,21 @@ export default class PlacesSidebar extends Component {
|
||||
return !qp.q && !qp.category && qp.lat && qp.lon;
|
||||
}
|
||||
|
||||
get hasHeaderPhoto() {
|
||||
return (
|
||||
this.args.selectedPlace &&
|
||||
this.nostrData.placePhotos &&
|
||||
this.nostrData.placePhotos.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<div
|
||||
class="sidebar-header
|
||||
{{if this.hasHeaderPhoto 'no-border'}}
|
||||
{{if (and (not @selectedPlace) @onBack) 'has-back-btn'}}"
|
||||
>
|
||||
{{#if @selectedPlace}}
|
||||
<button
|
||||
type="button"
|
||||
@@ -159,11 +175,32 @@ export default class PlacesSidebar extends Component {
|
||||
{{on "click" this.clearSelection}}
|
||||
><Icon @name="arrow-left" @size={{20}} @color="#333" /></button>
|
||||
{{else}}
|
||||
{{#if this.isNearbySearch}}
|
||||
<h2><Icon @name="target" @size={{20}} @color="#ea4335" />
|
||||
Nearby</h2>
|
||||
{{#if @onBack}}
|
||||
<button type="button" class="back-btn" {{on "click" @onBack}}><Icon
|
||||
@name="arrow-left"
|
||||
@size={{20}}
|
||||
@color="#333"
|
||||
/></button>
|
||||
{{/if}}
|
||||
{{#if @onBack}}
|
||||
<h2 class="sidebar-header-text-centered">
|
||||
<span class="sidebar-header-icon-wrapper">
|
||||
<Icon
|
||||
@name="bookmark"
|
||||
@size={{20}}
|
||||
@color={{or @color "#898989"}}
|
||||
/>
|
||||
</span>
|
||||
{{@title}}
|
||||
</h2>
|
||||
{{else}}
|
||||
<h2><Icon @name="search" @size={{20}} @color="#333" /> Results</h2>
|
||||
{{#if this.isNearbySearch}}
|
||||
<h2><Icon @name="target" @size={{20}} @color="#ea4335" />
|
||||
Nearby</h2>
|
||||
{{else}}
|
||||
<h2><Icon @name="search" @size={{20}} @color="#333" />
|
||||
Results</h2>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<button type="button" class="close-btn" {{on "click" @onClose}}><Icon
|
||||
@@ -173,7 +210,7 @@ export default class PlacesSidebar extends Component {
|
||||
/></button>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-content">
|
||||
<div class="sidebar-content" {{restoreScroll @scrollTop}}>
|
||||
{{#if @selectedPlace}}
|
||||
<PlaceDetails
|
||||
@place={{@selectedPlace}}
|
||||
@@ -181,54 +218,58 @@ export default class PlacesSidebar extends Component {
|
||||
@onSave={{this.updateBookmark}}
|
||||
/>
|
||||
{{else}}
|
||||
{{#if @places}}
|
||||
<ul class="places-list">
|
||||
{{#each @places as |place|}}
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
class="place-item"
|
||||
{{on "click" (fn this.selectPlace place)}}
|
||||
>
|
||||
<div class="place-name">{{or
|
||||
place.title
|
||||
place.osmTags.name
|
||||
place.osmTags.name:en
|
||||
"Unnamed Place"
|
||||
}}</div>
|
||||
<div class="place-type">
|
||||
{{#if (eq place.source "osm")}}
|
||||
{{humanizeOsmTag place.type}}
|
||||
{{else if (eq place.source "photon")}}
|
||||
{{place.description}}
|
||||
{{else}}
|
||||
{{#if place.osmTags}}
|
||||
{{humanizeOsmTag (getPlaceType place.osmTags)}}
|
||||
{{else if place.description}}
|
||||
{{place.description}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</button>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{#if @isLoading}}
|
||||
<div class="sidebar-loading">
|
||||
<Icon @name="loading-ring" @size={{24}} @color="#898989" />
|
||||
</div>
|
||||
{{else}}
|
||||
{{#if this.isNearbySearch}}
|
||||
<p class="empty-state">No places found nearby.</p>
|
||||
{{#if @places}}
|
||||
<ul class="places-list">
|
||||
{{#each @places as |place|}}
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
class="place-item"
|
||||
{{on "click" (fn this.selectPlace place)}}
|
||||
>
|
||||
<div class="place-name">{{or
|
||||
place.title
|
||||
place.osmTags.name
|
||||
place.osmTags.name:en
|
||||
"Unnamed Place"
|
||||
}}</div>
|
||||
<div class="place-type">
|
||||
{{#if (eq place.source "osm")}}
|
||||
{{humanizeOsmTag place.type}}
|
||||
{{else if (eq place.source "photon")}}
|
||||
{{place.description}}
|
||||
{{else if (getPlaceType place.osmTags)}}
|
||||
{{getPlaceType place.osmTags}}
|
||||
{{else}}
|
||||
Saved place
|
||||
{{/if}}
|
||||
</div>
|
||||
</button>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{else}}
|
||||
<p class="empty-state">No results found.</p>
|
||||
{{#if this.isNearbySearch}}
|
||||
<p class="empty-state">No places found nearby.</p>
|
||||
{{else}}
|
||||
<p class="empty-state">No results found.</p>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline create-place"
|
||||
{{on "click" this.createNewPlace}}
|
||||
>
|
||||
<Icon @name="plus" @size={{18}} @color="var(--link-color)" />
|
||||
Create new place
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline create-place"
|
||||
{{on "click" this.createNewPlace}}
|
||||
>
|
||||
<Icon @name="plus" @size={{18}} @color="var(--link-color)" />
|
||||
Create new place
|
||||
</button>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +13,7 @@ import { eq, or } from 'ember-truth-helpers';
|
||||
export default class SearchBoxComponent extends Component {
|
||||
@service photon;
|
||||
@service osm;
|
||||
@service storage;
|
||||
@service router;
|
||||
@service mapUi;
|
||||
@service map; // Assuming we might need map context, but mostly we use router
|
||||
@@ -50,6 +51,29 @@ export default class SearchBoxComponent extends Component {
|
||||
this.searchTask.perform(value);
|
||||
}
|
||||
|
||||
formatSavedPlace(place) {
|
||||
const listNames = (place._listIds || [])
|
||||
.map((id) => this.storage.lists?.find((l) => l.id === id)?.title)
|
||||
.filter(Boolean)
|
||||
.join(', ');
|
||||
|
||||
const description = listNames
|
||||
? `Saved place (${listNames})`
|
||||
: 'Saved place';
|
||||
|
||||
return {
|
||||
source: 'saved',
|
||||
id: place.id,
|
||||
title: place.title,
|
||||
icon: 'bookmark',
|
||||
description,
|
||||
osmId: place.osmId,
|
||||
osmType: place.osmType,
|
||||
lat: place.lat,
|
||||
lon: place.lon,
|
||||
};
|
||||
}
|
||||
|
||||
searchTask = task({ restartable: true }, async (term) => {
|
||||
await timeout(300);
|
||||
|
||||
@@ -76,8 +100,29 @@ export default class SearchBoxComponent extends Component {
|
||||
icon: 'search',
|
||||
}));
|
||||
|
||||
// Filter saved places (minimum 3 characters)
|
||||
let savedMatches = [];
|
||||
if (q.length >= 3) {
|
||||
savedMatches = this.storage.savedPlaces
|
||||
.filter((p) => p.title && p.title.toLowerCase().includes(q))
|
||||
.map((p) => this.formatSavedPlace(p));
|
||||
}
|
||||
|
||||
const results = await this.photon.search(query, lat, lon);
|
||||
this.results = [...categoryMatches, ...results];
|
||||
|
||||
// Deduplicate Photon results that are already in saved matches
|
||||
const savedOsmIds = new Set(
|
||||
savedMatches.map((s) => s.osmId).filter(Boolean)
|
||||
);
|
||||
const filteredPhotonResults = results.filter(
|
||||
(r) => !savedOsmIds.has(r.osmId)
|
||||
);
|
||||
|
||||
this.results = [
|
||||
...categoryMatches,
|
||||
...savedMatches,
|
||||
...filteredPhotonResults,
|
||||
];
|
||||
} catch (e) {
|
||||
console.error('Search failed', e);
|
||||
this.results = [];
|
||||
@@ -156,8 +201,12 @@ export default class SearchBoxComponent extends Component {
|
||||
}
|
||||
this.results = []; // Hide popover
|
||||
|
||||
// If it has an OSM ID, go to place details
|
||||
if (place.osmId) {
|
||||
// If it's a custom saved place without an OSM ID, go to place details via internal ID
|
||||
if (place.source === 'saved' && place.id && !place.osmId) {
|
||||
this.router.transitionTo('place', place.id);
|
||||
}
|
||||
// If it has an OSM ID, go to place details via OSM ID
|
||||
else if (place.osmId) {
|
||||
// Format: osm:node:123
|
||||
// place.osmType is already normalized to 'node', 'way', or 'relation' by PhotonService
|
||||
const id = `osm:${place.osmType}:${place.osmId}`;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { service } from '@ember/service';
|
||||
import Icon from '#components/icon';
|
||||
import { on } from '@ember/modifier';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
@@ -11,6 +11,7 @@ export default class UserMenuComponent extends Component {
|
||||
@service storage;
|
||||
@service osmAuth;
|
||||
@service nostrAuth;
|
||||
@service nostrData;
|
||||
|
||||
@tracked isNostrConnectModalOpen = false;
|
||||
|
||||
@@ -135,7 +136,7 @@ export default class UserMenuComponent extends Component {
|
||||
<div class="account-status">
|
||||
{{#if this.nostrAuth.isConnected}}
|
||||
<strong title={{this.nostrAuth.pubkey}}>
|
||||
{{this.nostrAuth.pubkey}}
|
||||
{{this.nostrData.userDisplayName}}
|
||||
</strong>
|
||||
{{else}}
|
||||
Not connected
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { task } from 'ember-concurrency';
|
||||
|
||||
export default class ListsListController extends Controller {
|
||||
@service router;
|
||||
@service mapUi;
|
||||
@service storage;
|
||||
|
||||
@tracked model;
|
||||
@tracked loadedPlaces = [];
|
||||
|
||||
get listId() {
|
||||
return this.model?.list_id;
|
||||
}
|
||||
|
||||
loadPlacesTask = task({ restartable: true }, async (listId) => {
|
||||
this.loadedPlaces = []; // Clear previous elements immediately to show fresh loader
|
||||
try {
|
||||
this.loadedPlaces = await this.storage.getPlacesInList(listId);
|
||||
} catch (e) {
|
||||
console.error('Failed to load places in list', listId, e);
|
||||
this.loadedPlaces = [];
|
||||
}
|
||||
});
|
||||
|
||||
get scrollTop() {
|
||||
return this.mapUi.getScrollPosition(`list-${this.listId}`);
|
||||
}
|
||||
|
||||
get listColor() {
|
||||
const list = this.storage.lists.find((l) => l.id === this.listId);
|
||||
if (list && list.color) {
|
||||
return list.color;
|
||||
}
|
||||
return getComputedStyle(document.documentElement)
|
||||
.getPropertyValue('--default-list-color')
|
||||
.trim();
|
||||
}
|
||||
|
||||
get listTitle() {
|
||||
const list = this.storage.lists.find((l) => l.id === this.listId);
|
||||
return list ? list.title : 'Collections';
|
||||
}
|
||||
|
||||
get places() {
|
||||
const currentList = this.storage.lists.find((l) => l.id === this.listId);
|
||||
const placeRefsIds = new Set(
|
||||
currentList?.placeRefs?.map((ref) => ref.id) || []
|
||||
);
|
||||
|
||||
// Filter live tracked savedPlaces that are in this list
|
||||
const livePlaces = this.storage.savedPlaces.filter((p) =>
|
||||
placeRefsIds.has(p.id)
|
||||
);
|
||||
|
||||
const merged = [];
|
||||
const seen = new Set();
|
||||
|
||||
// Process live state first to reflect deletions/edits immediately
|
||||
livePlaces.forEach((p) => {
|
||||
merged.push(p);
|
||||
seen.add(p.id);
|
||||
});
|
||||
|
||||
// Supplement with any background-fetched places that are still valid but not in live state yet
|
||||
this.loadedPlaces.forEach((p) => {
|
||||
if (placeRefsIds.has(p.id) && !seen.has(p.id)) {
|
||||
merged.push(p);
|
||||
seen.add(p.id);
|
||||
}
|
||||
});
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
@action
|
||||
selectPlace(place) {
|
||||
if (place) {
|
||||
const sidebarContent = document.querySelector('.sidebar-content');
|
||||
if (sidebarContent) {
|
||||
this.mapUi.saveScrollPosition(
|
||||
`list-${this.listId}`,
|
||||
sidebarContent.scrollTop
|
||||
);
|
||||
}
|
||||
this.mapUi.returnToRoute = {
|
||||
name: 'lists.list',
|
||||
model: this.listId,
|
||||
};
|
||||
this.mapUi.showSidebar();
|
||||
this.mapUi.preventNextZoom = true;
|
||||
this.router.transitionTo('place', place);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
close() {
|
||||
this.router.transitionTo('index');
|
||||
}
|
||||
|
||||
@action
|
||||
backToLists() {
|
||||
this.router.transitionTo('lists.index');
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,16 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { service } from '@ember/service';
|
||||
import { task } from 'ember-concurrency';
|
||||
import { getDistance } from '../utils/geo';
|
||||
|
||||
export default class SearchController extends Controller {
|
||||
@service osm;
|
||||
@service photon;
|
||||
@service mapUi;
|
||||
@service storage;
|
||||
@service router;
|
||||
@service toast;
|
||||
|
||||
queryParams = ['lat', 'lon', 'q', 'selected', 'category'];
|
||||
|
||||
lat = null;
|
||||
@@ -8,4 +18,197 @@ export default class SearchController extends Controller {
|
||||
q = null;
|
||||
selected = null;
|
||||
category = null;
|
||||
|
||||
fetchResultsTask = task({ restartable: true }, async (params) => {
|
||||
// 1. Check if the incoming parameters match our currently loaded search
|
||||
const isSameSearch =
|
||||
this.mapUi.currentSearch &&
|
||||
params.q === this.mapUi.currentSearch.q &&
|
||||
params.category === this.mapUi.currentSearch.category &&
|
||||
params.lat === this.mapUi.currentSearch.lat &&
|
||||
params.lon === this.mapUi.currentSearch.lon;
|
||||
|
||||
const hasResults =
|
||||
this.mapUi.searchResults && this.mapUi.searchResults.length > 0;
|
||||
|
||||
// 2. If it's a back navigation to the exact same search, resolve instantly with no animation
|
||||
if (isSameSearch && hasResults) {
|
||||
if (this.mapUi.isSidebarVisible) {
|
||||
this.mapUi.showSidebar();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Otherwise, this is a brand new search: hide the sidebar and clear previous results immediately to signal a new search
|
||||
this.mapUi.hideSidebar();
|
||||
this.mapUi.clearSearchResults();
|
||||
|
||||
const lat = params.lat ? parseFloat(params.lat) : null;
|
||||
const lon = params.lon ? parseFloat(params.lon) : null;
|
||||
let pois = [];
|
||||
let loadingType = null;
|
||||
let loadingValue = null;
|
||||
|
||||
try {
|
||||
// Case 0: Category Search (category parameter present)
|
||||
if (params.category && lat && lon) {
|
||||
loadingType = 'category';
|
||||
loadingValue = params.category;
|
||||
this.mapUi.startLoading(loadingType, loadingValue);
|
||||
|
||||
// We need bounds. If we have active map state, use it.
|
||||
let bounds = this.mapUi.currentBounds;
|
||||
|
||||
// If we don't have bounds (direct URL visit), estimate them from lat/lon/zoom(16)
|
||||
// or just use a fixed box around the center.
|
||||
if (!bounds) {
|
||||
// Approximate 0.01 degrees ~ 1km at equator. A viewport is roughly 0.02x0.01 at zoom 16?
|
||||
// Let's take a safe box of ~1km radius.
|
||||
const delta = 0.01;
|
||||
bounds = {
|
||||
minLat: lat - delta,
|
||||
maxLat: lat + delta,
|
||||
minLon: lon - delta,
|
||||
maxLon: lon + delta,
|
||||
};
|
||||
}
|
||||
|
||||
pois = await this.osm.getCategoryPois(
|
||||
bounds,
|
||||
params.category,
|
||||
lat,
|
||||
lon
|
||||
);
|
||||
|
||||
// Sort by distance from center
|
||||
pois = pois
|
||||
.map((p) => ({
|
||||
...p,
|
||||
_distance: getDistance(lat, lon, p.lat, p.lon),
|
||||
}))
|
||||
.sort((a, b) => a._distance - b._distance);
|
||||
}
|
||||
// Case 1: Text Search (q parameter present)
|
||||
else if (params.q) {
|
||||
loadingType = 'text';
|
||||
loadingValue = params.q;
|
||||
this.mapUi.startLoading(loadingType, loadingValue);
|
||||
|
||||
// Search with Photon (using lat/lon for bias if available)
|
||||
pois = await this.photon.search(params.q, lat, lon);
|
||||
|
||||
// Search local bookmarks by name (minimum 3 characters)
|
||||
const queryLower = params.q.toLowerCase();
|
||||
let localMatches = [];
|
||||
if (queryLower.length >= 3) {
|
||||
localMatches = this.storage.savedPlaces.filter((p) => {
|
||||
return (
|
||||
p.title?.toLowerCase().includes(queryLower) ||
|
||||
p.description?.toLowerCase().includes(queryLower)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Merge local matches
|
||||
localMatches.forEach((local) => {
|
||||
const exists = pois.find(
|
||||
(poi) =>
|
||||
(local.osmId && poi.osmId === local.osmId) ||
|
||||
(poi.id && poi.id === local.id)
|
||||
);
|
||||
if (!exists) {
|
||||
pois.push(local);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Case 2: Nearby Search (lat/lon present, no q)
|
||||
else if (lat && lon) {
|
||||
// Nearby search does NOT trigger loading state (pulse is used instead)
|
||||
const searchRadius = 50; // Default radius
|
||||
|
||||
// Fetch POIs from Overpass
|
||||
pois = await this.osm.getNearbyPois(lat, lon, searchRadius);
|
||||
|
||||
// Get cached/saved places in search radius
|
||||
const localMatches = this.storage.savedPlaces.filter((p) => {
|
||||
const dist = getDistance(lat, lon, p.lat, p.lon);
|
||||
return dist <= searchRadius;
|
||||
});
|
||||
|
||||
// Merge local matches
|
||||
localMatches.forEach((local) => {
|
||||
const exists = pois.find(
|
||||
(poi) =>
|
||||
(local.osmId && poi.osmId === local.osmId) ||
|
||||
(poi.id && poi.id === local.id)
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
pois.push(local);
|
||||
}
|
||||
});
|
||||
|
||||
// Sort by distance from click
|
||||
pois = pois
|
||||
.map((p) => {
|
||||
return {
|
||||
...p,
|
||||
_distance: getDistance(lat, lon, p.lat, p.lon),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a._distance - b._distance);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Search request failed.', error);
|
||||
this.toast.show('Search request failed. Please try again.');
|
||||
this.mapUi.stopSearch();
|
||||
return;
|
||||
} finally {
|
||||
if (loadingType && loadingValue) {
|
||||
this.mapUi.stopLoading(loadingType, loadingValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any of these are already bookmarked
|
||||
// We resolve them to the bookmark version if they exist
|
||||
pois = pois.map((p) => {
|
||||
const saved = this.storage.findPlaceById(p.osmId);
|
||||
return saved || p;
|
||||
});
|
||||
|
||||
const targetName = params.selected || params.q;
|
||||
|
||||
if (targetName && pois.length > 0) {
|
||||
let matchedPlace = null;
|
||||
|
||||
// 1. Exact Name Match
|
||||
matchedPlace = pois.find(
|
||||
(p) =>
|
||||
p.osmTags &&
|
||||
(p.osmTags.name === targetName || p.osmTags['name:en'] === targetName)
|
||||
);
|
||||
|
||||
// 2. High Proximity Match (<= 10m) - Only if we don't have a name match
|
||||
// Note: MapComponent had logic for <=20m + type match.
|
||||
// We might want to pass the 'type' in queryParams if we want to be that precise.
|
||||
// For now, let's stick to name or very close proximity.
|
||||
if (!matchedPlace) {
|
||||
const topCandidate = pois[0];
|
||||
if (topCandidate._distance <= 10) {
|
||||
matchedPlace = topCandidate;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedPlace) {
|
||||
// Direct transition!
|
||||
this.router.replaceWith('place', matchedPlace);
|
||||
this.mapUi.stopSearch();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.mapUi.setSearchResults(pois);
|
||||
this.mapUi.showSidebar();
|
||||
this.mapUi.stopSearch();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { helper } from '@ember/component/helper';
|
||||
import { capitalize as format } from '../utils/format-text';
|
||||
|
||||
export default helper(function capitalize([text]) {
|
||||
return format(text);
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import { helper } from '@ember/component/helper';
|
||||
|
||||
export default helper(function includes([collection, value]) {
|
||||
if (!Array.isArray(collection)) return false;
|
||||
return collection.includes(value);
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import { modifier } from 'ember-modifier';
|
||||
|
||||
const CACHE_NAME = 'nostr-image-cache-v1';
|
||||
|
||||
export default modifier((element, [url]) => {
|
||||
let objectUrl = null;
|
||||
|
||||
async function loadImage() {
|
||||
if (!url) {
|
||||
element.src = '';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
const cachedResponse = await cache.match(url);
|
||||
|
||||
if (cachedResponse) {
|
||||
const blob = await cachedResponse.blob();
|
||||
objectUrl = URL.createObjectURL(blob);
|
||||
element.src = objectUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Not in cache, try to fetch it
|
||||
// eslint-disable-next-line warp-drive/no-external-request-patterns
|
||||
const response = await fetch(url, {
|
||||
mode: 'cors', // Required to read the blob for caching
|
||||
credentials: 'omit',
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
// Clone the response before reading the blob because a response stream can only be read once
|
||||
const cacheResponse = response.clone();
|
||||
await cache.put(url, cacheResponse);
|
||||
|
||||
const blob = await response.blob();
|
||||
objectUrl = URL.createObjectURL(blob);
|
||||
element.src = objectUrl;
|
||||
} else {
|
||||
// Fetch failed (e.g. 404), fallback to standard browser loading
|
||||
element.src = url;
|
||||
}
|
||||
} catch (error) {
|
||||
// CORS errors or network failures will land here.
|
||||
// Fallback to letting the browser handle it directly.
|
||||
console.warn(
|
||||
`Failed to cache image ${url}, falling back to standard src`,
|
||||
error
|
||||
);
|
||||
element.src = url;
|
||||
}
|
||||
}
|
||||
|
||||
loadImage();
|
||||
|
||||
// Cleanup: revoke the object URL when the element is destroyed or the URL changes
|
||||
return () => {
|
||||
if (objectUrl) {
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
objectUrl = null;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
import { modifier } from 'ember-modifier';
|
||||
|
||||
export default modifier((element, [url]) => {
|
||||
if (!url) return;
|
||||
|
||||
// Remove classes when URL changes
|
||||
element.classList.remove('loaded');
|
||||
element.classList.remove('loaded-instant');
|
||||
|
||||
let observer;
|
||||
|
||||
const hideBlurhash = () => {
|
||||
const parent = element.parentElement;
|
||||
const slide =
|
||||
parent && parent.tagName === 'PICTURE' ? parent.parentElement : parent;
|
||||
|
||||
// Only hide the blurhash if we're in the gallery-main view.
|
||||
// In the inline view, we want to keep the blurhash visible behind portrait photos
|
||||
// to fill the 16:9 container gracefully.
|
||||
if (slide && slide.closest('.photo-carousel.gallery-main')) {
|
||||
const blur = slide.querySelector('.place-header-photo-blur');
|
||||
if (blur) {
|
||||
blur.style.opacity = '0';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleLoad = () => {
|
||||
// Only apply the fade-in animation if it wasn't already loaded instantly
|
||||
if (!element.classList.contains('loaded-instant')) {
|
||||
element.classList.add('loaded');
|
||||
}
|
||||
hideBlurhash();
|
||||
};
|
||||
|
||||
element.addEventListener('load', handleLoad);
|
||||
|
||||
const loadWhenVisible = (entries, obs) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
// Stop observing once we start loading
|
||||
obs.unobserve(element);
|
||||
|
||||
// Check if the image is already in the browser cache
|
||||
// Create an off-DOM image to reliably check cache status
|
||||
// without waiting for the actual DOM element to load it
|
||||
const img = new Image();
|
||||
img.src = url;
|
||||
|
||||
if (img.complete) {
|
||||
// Already in browser cache, skip the animation
|
||||
element.classList.add('loaded-instant');
|
||||
hideBlurhash();
|
||||
}
|
||||
|
||||
// If this image is inside a <picture> tag, we also need to swap <source> tags
|
||||
const parent = element.parentElement;
|
||||
if (parent && parent.tagName === 'PICTURE') {
|
||||
const sources = parent.querySelectorAll('source');
|
||||
sources.forEach((source) => {
|
||||
if (source.dataset.srcset) {
|
||||
source.srcset = source.dataset.srcset;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Swap data-src to src to trigger the actual network fetch (or render from cache)
|
||||
if (element.dataset.src) {
|
||||
element.src = element.dataset.src;
|
||||
} else {
|
||||
// Fallback if data-src wasn't used but the modifier was called
|
||||
element.src = url;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Setup Intersection Observer to only load when the image enters the viewport
|
||||
observer = new IntersectionObserver(loadWhenVisible, {
|
||||
root: null, // Use the viewport as the root
|
||||
rootMargin: '100px 100%', // Load one full viewport width ahead/behind
|
||||
threshold: 0, // Trigger immediately when any part enters the expanded margin
|
||||
});
|
||||
|
||||
observer.observe(element);
|
||||
|
||||
return () => {
|
||||
element.removeEventListener('load', handleLoad);
|
||||
if (observer) {
|
||||
observer.disconnect();
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { modifier } from 'ember-modifier';
|
||||
|
||||
export default modifier((element, [scrollTop]) => {
|
||||
if (element && typeof scrollTop === 'number' && scrollTop > 0) {
|
||||
// Restore inside requestAnimationFrame to guarantee layout rendering is ready
|
||||
requestAnimationFrame(() => {
|
||||
element.scrollTop = scrollTop;
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -10,6 +10,10 @@ Router.map(function () {
|
||||
this.route('place', { path: '/place/:place_id' });
|
||||
this.route('place.new', { path: '/place/new' });
|
||||
this.route('search');
|
||||
this.route('menu');
|
||||
this.route('lists', function () {
|
||||
this.route('list', { path: '/:list_id' });
|
||||
});
|
||||
this.route('oauth', function () {
|
||||
this.route('osm-callback', { path: '/osm/callback' });
|
||||
});
|
||||
|
||||
@@ -6,5 +6,6 @@ export default class IndexRoute extends Route {
|
||||
|
||||
activate() {
|
||||
this.mapUi.clearSearchResults();
|
||||
this.mapUi.hideSidebar();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
export default class ListsRoute extends Route {
|
||||
@service mapUi;
|
||||
|
||||
activate() {
|
||||
this.mapUi.showSidebar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ListsIndexRoute extends Route {}
|
||||
@@ -0,0 +1,26 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
export default class ListsListRoute extends Route {
|
||||
@service storage;
|
||||
|
||||
model(params) {
|
||||
// Resolve instantly so transition happens in 0ms!
|
||||
return { list_id: params.list_id };
|
||||
}
|
||||
|
||||
setupController(controller, model) {
|
||||
console.debug('DEBUG: setupController controller is:', controller);
|
||||
console.debug(
|
||||
'DEBUG: controller.loadPlacesTask is:',
|
||||
controller?.loadPlacesTask
|
||||
);
|
||||
controller.model = model;
|
||||
super.setupController(controller, model);
|
||||
if (controller && controller.loadPlacesTask) {
|
||||
controller.loadPlacesTask.perform(model.list_id);
|
||||
} else {
|
||||
console.error('DEBUG: ERROR! controller.loadPlacesTask is undefined!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
export default class MenuRoute extends Route {
|
||||
@service mapUi;
|
||||
|
||||
activate() {
|
||||
this.mapUi.showSidebar();
|
||||
}
|
||||
}
|
||||
+32
-8
@@ -9,25 +9,47 @@ export default class PlaceRoute extends Route {
|
||||
async model(params) {
|
||||
const id = params.place_id;
|
||||
|
||||
let type, osmId;
|
||||
let isExplicitOsm = false;
|
||||
|
||||
if (
|
||||
id.startsWith('osm:node:') ||
|
||||
id.startsWith('osm:way:') ||
|
||||
id.startsWith('osm:relation:')
|
||||
) {
|
||||
const [, type, osmId] = id.split(':');
|
||||
isExplicitOsm = true;
|
||||
[, type, osmId] = id.split(':');
|
||||
console.debug(`Fetching explicit OSM ${type}:`, osmId);
|
||||
return this.loadOsmPlace(osmId, type);
|
||||
}
|
||||
|
||||
let backgroundFetchPromise = null;
|
||||
if (isExplicitOsm) {
|
||||
backgroundFetchPromise = this.loadOsmPlace(osmId, type);
|
||||
}
|
||||
|
||||
await this.waitForSync();
|
||||
|
||||
let bookmark = this.storage.findPlaceById(id);
|
||||
let lookupId = isExplicitOsm ? osmId : id;
|
||||
let bookmark = this.storage.findPlaceById(lookupId);
|
||||
|
||||
// Ensure type matches if we are looking up by osmId
|
||||
if (bookmark && isExplicitOsm && bookmark.osmType !== type) {
|
||||
bookmark = null; // Type mismatch, not the same OSM object
|
||||
}
|
||||
|
||||
if (bookmark) {
|
||||
console.debug('Found in bookmarks:', bookmark.title);
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
if (isExplicitOsm) {
|
||||
console.debug(
|
||||
`Not in bookmarks, using explicitly fetched OSM ${type}:`,
|
||||
osmId
|
||||
);
|
||||
return await backgroundFetchPromise;
|
||||
}
|
||||
|
||||
console.warn('Not in bookmarks:', id);
|
||||
return null;
|
||||
}
|
||||
@@ -74,6 +96,7 @@ export default class PlaceRoute extends Route {
|
||||
if (model) {
|
||||
const options = { preventZoom: this.mapUi.preventNextZoom };
|
||||
this.mapUi.selectPlace(model, options);
|
||||
this.mapUi.showSidebar();
|
||||
this.mapUi.preventNextZoom = false;
|
||||
}
|
||||
// Stop the pulse animation if it was running (e.g. redirected from search)
|
||||
@@ -85,6 +108,7 @@ export default class PlaceRoute extends Route {
|
||||
this.mapUi.clearSelection();
|
||||
// Reset the "return to search" flag so it doesn't persist to subsequent navigations
|
||||
this.mapUi.returnToSearch = false;
|
||||
this.mapUi.returnToRoute = null;
|
||||
}
|
||||
|
||||
async loadOsmPlace(id, type = null) {
|
||||
@@ -119,14 +143,14 @@ export default class PlaceRoute extends Route {
|
||||
}
|
||||
|
||||
serialize(model) {
|
||||
// If the model is a saved bookmark, use its ID
|
||||
if (model.id) {
|
||||
return { place_id: model.id };
|
||||
}
|
||||
// If it's an OSM POI, use the explicit format
|
||||
// If it's an OSM POI, use the explicit format first
|
||||
if (model.osmId && model.osmType) {
|
||||
return { place_id: `osm:${model.osmType}:${model.osmId}` };
|
||||
}
|
||||
// If the model is a saved bookmark (and not OSM, e.g. custom place), use its ID
|
||||
if (model.id) {
|
||||
return { place_id: model.id };
|
||||
}
|
||||
// Fallback
|
||||
return { place_id: model.osmId };
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ export default class PlaceNewRoute extends Route {
|
||||
this.mapUi.updateCreationCoordinates(model.lat, model.lon);
|
||||
}
|
||||
this.mapUi.startCreating();
|
||||
this.mapUi.showSidebar();
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
|
||||
+14
-176
@@ -1,14 +1,9 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { getDistance } from '../utils/geo';
|
||||
|
||||
export default class SearchRoute extends Route {
|
||||
@service osm;
|
||||
@service photon;
|
||||
@service mapUi;
|
||||
@service storage;
|
||||
@service router;
|
||||
@service toast;
|
||||
|
||||
queryParams = {
|
||||
@@ -19,186 +14,29 @@ export default class SearchRoute extends Route {
|
||||
category: { refreshModel: true },
|
||||
};
|
||||
|
||||
async model(params) {
|
||||
const lat = params.lat ? parseFloat(params.lat) : null;
|
||||
const lon = params.lon ? parseFloat(params.lon) : null;
|
||||
let pois = [];
|
||||
let loadingType = null;
|
||||
let loadingValue = null;
|
||||
|
||||
try {
|
||||
// Case 0: Category Search (category parameter present)
|
||||
if (params.category && lat && lon) {
|
||||
loadingType = 'category';
|
||||
loadingValue = params.category;
|
||||
this.mapUi.startLoading(loadingType, loadingValue);
|
||||
|
||||
// We need bounds. If we have active map state, use it.
|
||||
let bounds = this.mapUi.currentBounds;
|
||||
|
||||
// If we don't have bounds (direct URL visit), estimate them from lat/lon/zoom(16)
|
||||
// or just use a fixed box around the center.
|
||||
if (!bounds) {
|
||||
// Approximate 0.01 degrees ~ 1km at equator. A viewport is roughly 0.02x0.01 at zoom 16?
|
||||
// Let's take a safe box of ~1km radius.
|
||||
const delta = 0.01;
|
||||
bounds = {
|
||||
minLat: lat - delta,
|
||||
maxLat: lat + delta,
|
||||
minLon: lon - delta,
|
||||
maxLon: lon + delta,
|
||||
};
|
||||
}
|
||||
|
||||
pois = await this.osm.getCategoryPois(
|
||||
bounds,
|
||||
params.category,
|
||||
lat,
|
||||
lon
|
||||
);
|
||||
|
||||
// Sort by distance from center
|
||||
pois = pois
|
||||
.map((p) => ({
|
||||
...p,
|
||||
_distance: getDistance(lat, lon, p.lat, p.lon),
|
||||
}))
|
||||
.sort((a, b) => a._distance - b._distance);
|
||||
}
|
||||
// Case 1: Text Search (q parameter present)
|
||||
else if (params.q) {
|
||||
loadingType = 'text';
|
||||
loadingValue = params.q;
|
||||
this.mapUi.startLoading(loadingType, loadingValue);
|
||||
|
||||
// Search with Photon (using lat/lon for bias if available)
|
||||
pois = await this.photon.search(params.q, lat, lon);
|
||||
|
||||
// Search local bookmarks by name
|
||||
const queryLower = params.q.toLowerCase();
|
||||
const localMatches = this.storage.savedPlaces.filter((p) => {
|
||||
return (
|
||||
p.title?.toLowerCase().includes(queryLower) ||
|
||||
p.description?.toLowerCase().includes(queryLower)
|
||||
);
|
||||
});
|
||||
|
||||
// Merge local matches
|
||||
localMatches.forEach((local) => {
|
||||
const exists = pois.find(
|
||||
(poi) =>
|
||||
(local.osmId && poi.osmId === local.osmId) ||
|
||||
(poi.id && poi.id === local.id)
|
||||
);
|
||||
if (!exists) {
|
||||
pois.push(local);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Case 2: Nearby Search (lat/lon present, no q)
|
||||
else if (lat && lon) {
|
||||
// Nearby search does NOT trigger loading state (pulse is used instead)
|
||||
const searchRadius = 50; // Default radius
|
||||
|
||||
// Fetch POIs from Overpass
|
||||
pois = await this.osm.getNearbyPois(lat, lon, searchRadius);
|
||||
|
||||
// Get cached/saved places in search radius
|
||||
const localMatches = this.storage.savedPlaces.filter((p) => {
|
||||
const dist = getDistance(lat, lon, p.lat, p.lon);
|
||||
return dist <= searchRadius;
|
||||
});
|
||||
|
||||
// Merge local matches
|
||||
localMatches.forEach((local) => {
|
||||
const exists = pois.find(
|
||||
(poi) =>
|
||||
(local.osmId && poi.osmId === local.osmId) ||
|
||||
(poi.id && poi.id === local.id)
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
pois.push(local);
|
||||
}
|
||||
});
|
||||
|
||||
// Sort by distance from click
|
||||
pois = pois
|
||||
.map((p) => {
|
||||
return {
|
||||
...p,
|
||||
_distance: getDistance(lat, lon, p.lat, p.lon),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a._distance - b._distance);
|
||||
}
|
||||
} finally {
|
||||
if (loadingType && loadingValue) {
|
||||
this.mapUi.stopLoading(loadingType, loadingValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any of these are already bookmarked
|
||||
// We resolve them to the bookmark version if they exist
|
||||
pois = pois.map((p) => {
|
||||
const saved = this.storage.findPlaceById(p.osmId);
|
||||
return saved || p;
|
||||
});
|
||||
|
||||
return pois;
|
||||
}
|
||||
|
||||
afterModel(model, transition) {
|
||||
const { q, selected } = transition.to.queryParams;
|
||||
|
||||
// Heuristic Match Logic (ported from MapComponent)
|
||||
// If 'selected' is provided (from map click), try to find that specific feature.
|
||||
// If 'q' is provided (from text search), try to find an exact match to auto-select.
|
||||
const targetName = selected || q;
|
||||
|
||||
if (targetName && model.length > 0) {
|
||||
let matchedPlace = null;
|
||||
|
||||
// 1. Exact Name Match
|
||||
matchedPlace = model.find(
|
||||
(p) =>
|
||||
p.osmTags &&
|
||||
(p.osmTags.name === targetName || p.osmTags['name:en'] === targetName)
|
||||
);
|
||||
|
||||
// 2. High Proximity Match (<= 10m) - Only if we don't have a name match
|
||||
// Note: MapComponent had logic for <=20m + type match.
|
||||
// We might want to pass the 'type' in queryParams if we want to be that precise.
|
||||
// For now, let's stick to name or very close proximity.
|
||||
if (!matchedPlace) {
|
||||
const topCandidate = model[0];
|
||||
if (topCandidate._distance <= 10) {
|
||||
matchedPlace = topCandidate;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedPlace) {
|
||||
// Direct transition!
|
||||
this.router.replaceWith('place', matchedPlace);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the pulse animation since search is done (and we are staying here)
|
||||
this.mapUi.stopSearch();
|
||||
model(params) {
|
||||
// Just return params, doing the async fetch in the controller
|
||||
return params;
|
||||
}
|
||||
|
||||
setupController(controller, model) {
|
||||
super.setupController(controller, model);
|
||||
// Ensure pulse is stopped if we reach here
|
||||
this.mapUi.stopSearch();
|
||||
this.mapUi.setSearchResults(model);
|
||||
|
||||
// Trigger the background task to fetch results
|
||||
controller.fetchResultsTask.perform(model);
|
||||
|
||||
// Store current search params to allow "Up" navigation from place details
|
||||
const { q, category, lat, lon } = this.paramsFor('search');
|
||||
this.mapUi.currentSearch = { q, category, lat, lon };
|
||||
}
|
||||
|
||||
resetController(controller, isExiting) {
|
||||
if (isExiting) {
|
||||
controller.fetchResultsTask.cancelAll();
|
||||
this.mapUi.stopSearch();
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
error(error, transition) {
|
||||
this.mapUi.stopSearch();
|
||||
@@ -206,6 +44,6 @@ export default class SearchRoute extends Route {
|
||||
if (transition) {
|
||||
transition.abort();
|
||||
}
|
||||
return false; // Prevent bubble and stop transition
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import Service, { service } from '@ember/service';
|
||||
import { EventFactory } from 'applesauce-core';
|
||||
import { sha256 } from '@noble/hashes/sha2.js';
|
||||
|
||||
export const DEFAULT_BLOSSOM_SERVER = 'https://blossom.nostr.build';
|
||||
|
||||
function bufferToHex(buffer) {
|
||||
return Array.from(new Uint8Array(buffer))
|
||||
.map((b) => b.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
}
|
||||
|
||||
function getBlossomUrl(serverUrl, path) {
|
||||
let url = serverUrl || DEFAULT_BLOSSOM_SERVER;
|
||||
if (url.endsWith('/')) {
|
||||
url = url.slice(0, -1);
|
||||
}
|
||||
return path.startsWith('/') ? `${url}${path}` : `${url}/${path}`;
|
||||
}
|
||||
|
||||
export default class BlossomService extends Service {
|
||||
@service nostrAuth;
|
||||
@service nostrData;
|
||||
@service settings;
|
||||
|
||||
get servers() {
|
||||
const servers = this.nostrData.blossomServers;
|
||||
const allServers = servers.length ? servers : [DEFAULT_BLOSSOM_SERVER];
|
||||
|
||||
if (!this.settings.nostrPhotoFallbackUploads) {
|
||||
return [allServers[0]];
|
||||
}
|
||||
|
||||
return allServers;
|
||||
}
|
||||
|
||||
async _getAuthHeader(action, hash, serverUrl) {
|
||||
const factory = new EventFactory({ signer: this.nostrAuth.signer });
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const serverHostname = new URL(serverUrl).hostname;
|
||||
|
||||
const authTemplate = {
|
||||
kind: 24242,
|
||||
created_at: now,
|
||||
content: action === 'upload' ? 'Upload photo for place' : 'Delete photo',
|
||||
tags: [
|
||||
['t', action],
|
||||
['x', hash],
|
||||
['expiration', String(now + 3600)],
|
||||
['server', serverHostname],
|
||||
],
|
||||
};
|
||||
|
||||
const authEvent = await factory.sign(authTemplate);
|
||||
const base64 = btoa(JSON.stringify(authEvent));
|
||||
const base64url = base64
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=+$/, '');
|
||||
return `Nostr ${base64url}`;
|
||||
}
|
||||
|
||||
async _uploadToServer(file, hash, serverUrl, onProgress) {
|
||||
const uploadUrl = getBlossomUrl(serverUrl, 'upload');
|
||||
|
||||
if (onProgress) onProgress('signing');
|
||||
const authHeader = await this._getAuthHeader('upload', hash, serverUrl);
|
||||
|
||||
if (onProgress) onProgress('uploading');
|
||||
// eslint-disable-next-line warp-drive/no-external-request-patterns
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
Authorization: authHeader,
|
||||
'X-SHA-256': hash,
|
||||
},
|
||||
body: file,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Upload failed (${response.status}): ${text}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async upload(file, options = { sequential: false }) {
|
||||
if (!this.nostrAuth.isConnected) throw new Error('Not connected');
|
||||
|
||||
const buffer = await file.arrayBuffer();
|
||||
let hashBuffer;
|
||||
|
||||
if (
|
||||
typeof crypto !== 'undefined' &&
|
||||
crypto.subtle &&
|
||||
crypto.subtle.digest
|
||||
) {
|
||||
hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
|
||||
} else {
|
||||
hashBuffer = sha256(new Uint8Array(buffer));
|
||||
}
|
||||
|
||||
const payloadHash = bufferToHex(hashBuffer);
|
||||
|
||||
const servers = this.servers;
|
||||
const mainServer = servers[0];
|
||||
const fallbackServers = servers.slice(1);
|
||||
|
||||
const fallbackUrls = [];
|
||||
let mainResult;
|
||||
|
||||
if (options.sequential) {
|
||||
// Sequential upload logic
|
||||
mainResult = await this._uploadToServer(
|
||||
file,
|
||||
payloadHash,
|
||||
mainServer,
|
||||
options.onProgress
|
||||
);
|
||||
|
||||
for (const serverUrl of fallbackServers) {
|
||||
try {
|
||||
const result = await this._uploadToServer(
|
||||
file,
|
||||
payloadHash,
|
||||
serverUrl,
|
||||
options.onProgress
|
||||
);
|
||||
fallbackUrls.push(result.url);
|
||||
} catch (error) {
|
||||
console.warn(`Fallback upload to ${serverUrl} failed:`, error);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Concurrent upload logic
|
||||
const mainPromise = this._uploadToServer(
|
||||
file,
|
||||
payloadHash,
|
||||
mainServer,
|
||||
options.onProgress
|
||||
);
|
||||
const fallbackPromises = fallbackServers.map((serverUrl) =>
|
||||
this._uploadToServer(file, payloadHash, serverUrl, options.onProgress)
|
||||
);
|
||||
|
||||
// Main server MUST succeed
|
||||
mainResult = await mainPromise;
|
||||
|
||||
// Fallback servers can fail, but we log the warnings
|
||||
const fallbackResults = await Promise.allSettled(fallbackPromises);
|
||||
|
||||
for (let i = 0; i < fallbackResults.length; i++) {
|
||||
const result = fallbackResults[i];
|
||||
if (result.status === 'fulfilled') {
|
||||
fallbackUrls.push(result.value.url);
|
||||
} else {
|
||||
console.warn(
|
||||
`Fallback upload to ${fallbackServers[i]} failed:`,
|
||||
result.reason
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
url: mainResult.url,
|
||||
fallbackUrls,
|
||||
hash: payloadHash,
|
||||
type: file.type,
|
||||
};
|
||||
}
|
||||
|
||||
async _deleteFromServer(hash, serverUrl) {
|
||||
const deleteUrl = getBlossomUrl(serverUrl, hash);
|
||||
const authHeader = await this._getAuthHeader('delete', hash, serverUrl);
|
||||
|
||||
// eslint-disable-next-line warp-drive/no-external-request-patterns
|
||||
const response = await fetch(deleteUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: authHeader,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
throw new Error(text || response.statusText);
|
||||
}
|
||||
}
|
||||
|
||||
async delete(hash) {
|
||||
if (!this.nostrAuth.isConnected) throw new Error('Not connected');
|
||||
|
||||
const servers = this.servers;
|
||||
const mainServer = servers[0];
|
||||
const fallbackServers = servers.slice(1);
|
||||
|
||||
const mainPromise = this._deleteFromServer(hash, mainServer);
|
||||
const fallbackPromises = fallbackServers.map((serverUrl) =>
|
||||
this._deleteFromServer(hash, serverUrl)
|
||||
);
|
||||
|
||||
// Main server MUST succeed
|
||||
await mainPromise;
|
||||
|
||||
// Fallback servers can fail, log warnings
|
||||
const fallbackResults = await Promise.allSettled(fallbackPromises);
|
||||
for (let i = 0; i < fallbackResults.length; i++) {
|
||||
const result = fallbackResults[i];
|
||||
if (result.status === 'rejected') {
|
||||
console.warn(
|
||||
`Fallback delete from ${fallbackServers[i]} failed:`,
|
||||
result.reason
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import Service from '@ember/service';
|
||||
// We use the special Vite query parameter to load this as a web worker
|
||||
import Worker from '../workers/image-processor?worker';
|
||||
|
||||
export default class ImageProcessorService extends Service {
|
||||
_worker = null;
|
||||
_callbacks = new Map();
|
||||
_msgId = 0;
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this._initWorker();
|
||||
}
|
||||
|
||||
_initWorker() {
|
||||
if (!this._worker && typeof Worker !== 'undefined') {
|
||||
try {
|
||||
this._worker = new Worker();
|
||||
this._worker.onmessage = this._handleMessage.bind(this);
|
||||
this._worker.onerror = this._handleError.bind(this);
|
||||
} catch (e) {
|
||||
console.warn('Failed to initialize image-processor worker:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_handleMessage(e) {
|
||||
const { id, success, blob, dim, blurhash, error } = e.data;
|
||||
const resolver = this._callbacks.get(id);
|
||||
|
||||
if (resolver) {
|
||||
this._callbacks.delete(id);
|
||||
if (success) {
|
||||
resolver.resolve({ blob, dim, blurhash });
|
||||
} else {
|
||||
resolver.reject(new Error(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_handleError(error) {
|
||||
console.error('Image Processor Worker Error:', error);
|
||||
// Reject all pending jobs
|
||||
for (const [, resolver] of this._callbacks.entries()) {
|
||||
resolver.reject(new Error('Worker crashed'));
|
||||
}
|
||||
this._callbacks.clear();
|
||||
// Restart the worker for future jobs
|
||||
this._worker.terminate();
|
||||
this._worker = null;
|
||||
this._initWorker();
|
||||
}
|
||||
|
||||
_getImageDimensions(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
const url = URL.createObjectURL(file);
|
||||
|
||||
img.onload = () => {
|
||||
const dimensions = { width: img.width, height: img.height };
|
||||
URL.revokeObjectURL(url);
|
||||
resolve(dimensions);
|
||||
};
|
||||
|
||||
img.onerror = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
reject(new Error('Could not read image dimensions'));
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
async process(file, maxDimension, quality, computeBlurhash = false) {
|
||||
if (!this._worker) {
|
||||
// Fallback if worker initialization failed (e.g. incredibly old browsers)
|
||||
throw new Error('Image processor worker is not available.');
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Get dimensions safely on the main thread
|
||||
const { width: origWidth, height: origHeight } =
|
||||
await this._getImageDimensions(file);
|
||||
|
||||
// 2. Calculate aspect-ratio preserving dimensions
|
||||
let targetWidth = origWidth;
|
||||
let targetHeight = origHeight;
|
||||
|
||||
if (origWidth > origHeight) {
|
||||
if (origWidth > maxDimension) {
|
||||
targetHeight = Math.round(origHeight * (maxDimension / origWidth));
|
||||
targetWidth = maxDimension;
|
||||
}
|
||||
} else {
|
||||
if (origHeight > maxDimension) {
|
||||
targetWidth = Math.round(origWidth * (maxDimension / origHeight));
|
||||
targetHeight = maxDimension;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Send to worker for processing
|
||||
return new Promise((resolve, reject) => {
|
||||
const id = ++this._msgId;
|
||||
this._callbacks.set(id, { resolve, reject });
|
||||
|
||||
this._worker.postMessage({
|
||||
type: 'PROCESS_IMAGE',
|
||||
id,
|
||||
file,
|
||||
targetWidth,
|
||||
targetHeight,
|
||||
quality,
|
||||
computeBlurhash,
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to process image: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
super.willDestroy(...arguments);
|
||||
if (this._worker) {
|
||||
this._worker.terminate();
|
||||
this._worker = null;
|
||||
}
|
||||
this._callbacks.clear();
|
||||
}
|
||||
}
|
||||
+41
-1
@@ -1,30 +1,66 @@
|
||||
import Service from '@ember/service';
|
||||
import Service, { service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class MapUiService extends Service {
|
||||
@service nostrData;
|
||||
|
||||
@tracked selectedPlace = null;
|
||||
@tracked isSearching = false;
|
||||
@tracked isCreating = false;
|
||||
@tracked creationCoordinates = null;
|
||||
@tracked returnToSearch = false;
|
||||
@tracked returnToRoute = null;
|
||||
@tracked currentCenter = null;
|
||||
@tracked currentBounds = null;
|
||||
@tracked currentZoom = null;
|
||||
@tracked searchBoxHasFocus = false;
|
||||
@tracked selectionOptions = {};
|
||||
@tracked preventNextZoom = false;
|
||||
@tracked searchResults = [];
|
||||
@tracked currentSearch = null;
|
||||
@tracked loadingState = null;
|
||||
@tracked isSidebarVisible = false;
|
||||
@tracked isSidebarOpening = false;
|
||||
|
||||
scrollPositions = {};
|
||||
|
||||
@action
|
||||
saveScrollPosition(key, value) {
|
||||
this.scrollPositions[key] = value;
|
||||
}
|
||||
|
||||
@action
|
||||
getScrollPosition(key) {
|
||||
return this.scrollPositions[key] || 0;
|
||||
}
|
||||
|
||||
showSidebar() {
|
||||
if (!this.isSidebarVisible) {
|
||||
this.isSidebarVisible = true;
|
||||
this.isSidebarOpening = true;
|
||||
setTimeout(() => {
|
||||
this.isSidebarOpening = false;
|
||||
}, 250);
|
||||
}
|
||||
}
|
||||
|
||||
hideSidebar() {
|
||||
this.isSidebarVisible = false;
|
||||
this.isSidebarOpening = false;
|
||||
}
|
||||
|
||||
selectPlace(place, options = {}) {
|
||||
this.selectedPlace = place;
|
||||
this.selectionOptions = options;
|
||||
this.nostrData.loadPhotosForPlace(place);
|
||||
}
|
||||
|
||||
clearSelection() {
|
||||
this.selectedPlace = null;
|
||||
this.selectionOptions = {};
|
||||
this.preventNextZoom = false;
|
||||
this.nostrData.loadPhotosForPlace(null);
|
||||
}
|
||||
|
||||
setSearchResults(results) {
|
||||
@@ -68,6 +104,10 @@ export default class MapUiService extends Service {
|
||||
this.currentCenter = { lat, lon };
|
||||
}
|
||||
|
||||
updateZoom(zoom) {
|
||||
this.currentZoom = zoom;
|
||||
}
|
||||
|
||||
updateBounds(bounds) {
|
||||
this.currentBounds = bounds;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Service, { inject as service } from '@ember/service';
|
||||
import Service, { service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import {
|
||||
ExtensionSigner,
|
||||
@@ -14,8 +14,11 @@ const STORAGE_KEY_CONNECT_RELAY = 'marco:nostr_connect_relay';
|
||||
|
||||
const DEFAULT_CONNECT_RELAY = 'wss://relay.nsec.app';
|
||||
|
||||
import { isMobile } from '../utils/device';
|
||||
|
||||
export default class NostrAuthService extends Service {
|
||||
@service nostrRelay;
|
||||
@service nostrData;
|
||||
|
||||
@tracked pubkey = null;
|
||||
@tracked signerType = null; // 'extension' or 'connect'
|
||||
@@ -56,6 +59,7 @@ export default class NostrAuthService extends Service {
|
||||
this.pubkey = extensionPubkey;
|
||||
localStorage.setItem(STORAGE_KEY, this.pubkey);
|
||||
}
|
||||
this.nostrData.loadProfile(this.pubkey);
|
||||
} catch (e) {
|
||||
console.warn('Failed to verify extension nostr pubkey, logging out', e);
|
||||
this.disconnect();
|
||||
@@ -71,7 +75,7 @@ export default class NostrAuthService extends Service {
|
||||
}
|
||||
|
||||
get isMobile() {
|
||||
return /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
|
||||
return isMobile();
|
||||
}
|
||||
|
||||
get isConnected() {
|
||||
@@ -112,6 +116,7 @@ export default class NostrAuthService extends Service {
|
||||
this.signerType = 'extension';
|
||||
localStorage.setItem(STORAGE_KEY, this.pubkey);
|
||||
localStorage.setItem(STORAGE_KEY_TYPE, 'extension');
|
||||
this.nostrData.loadProfile(this.pubkey);
|
||||
return this.pubkey;
|
||||
} catch (error) {
|
||||
console.error('Failed to get public key from extension:', error);
|
||||
@@ -207,6 +212,8 @@ export default class NostrAuthService extends Service {
|
||||
this._signerInstance.remote
|
||||
);
|
||||
|
||||
this.nostrData.loadProfile(this.pubkey);
|
||||
|
||||
return this.pubkey;
|
||||
} catch (error) {
|
||||
this.connectStatus = null;
|
||||
@@ -253,6 +260,7 @@ export default class NostrAuthService extends Service {
|
||||
if (pubkey !== this.pubkey) {
|
||||
throw new Error('Remote signer pubkey mismatch');
|
||||
}
|
||||
this.nostrData.loadProfile(this.pubkey);
|
||||
}
|
||||
|
||||
async signEvent(event) {
|
||||
@@ -266,6 +274,7 @@ export default class NostrAuthService extends Service {
|
||||
|
||||
async disconnect() {
|
||||
this.pubkey = null;
|
||||
this.nostrData?.loadProfile(null);
|
||||
this.signerType = null;
|
||||
this.connectStatus = null;
|
||||
this.connectUri = null;
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
import Service, { service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { EventStore } from 'applesauce-core/event-store';
|
||||
import { ProfileModel } from 'applesauce-core/models/profile';
|
||||
import { MailboxesModel } from 'applesauce-core/models/mailboxes';
|
||||
import { npubEncode } from 'applesauce-core/helpers/pointers';
|
||||
import { persistEventsToCache } from 'applesauce-core/helpers/event-cache';
|
||||
import { NostrIDB, openDB } from 'nostr-idb';
|
||||
import {
|
||||
excludeRequiredRelays,
|
||||
mergeRequiredRelays,
|
||||
normalizeRelayUrl,
|
||||
uniqNormalizedRelays,
|
||||
} from '../utils/nostr';
|
||||
import { getGeohashPrefixesInBbox } from '../utils/geohash-coverage';
|
||||
|
||||
const DIRECTORY_RELAYS = [
|
||||
'wss://purplepag.es',
|
||||
'wss://relay.damus.io',
|
||||
'wss://nos.lol',
|
||||
];
|
||||
|
||||
const DEFAULT_READ_RELAYS = ['wss://nostr.kosmos.org'];
|
||||
const DEFAULT_WRITE_RELAYS = [];
|
||||
|
||||
export default class NostrDataService extends Service {
|
||||
@service nostrRelay;
|
||||
@service nostrAuth;
|
||||
@service settings;
|
||||
|
||||
store = new EventStore();
|
||||
|
||||
@tracked profile = null;
|
||||
@tracked mailboxes = null;
|
||||
@tracked blossomServers = [];
|
||||
@tracked placePhotos = [];
|
||||
|
||||
_profileSub = null;
|
||||
_mailboxesSub = null;
|
||||
_blossomSub = null;
|
||||
_photosSub = null;
|
||||
|
||||
_requestSub = null;
|
||||
_cachePromise = null;
|
||||
loadedGeohashPrefixes = new Set();
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
|
||||
// Initialize the IndexedDB cache
|
||||
this._cachePromise = openDB('applesauce-events').then(async (db) => {
|
||||
this.cache = new NostrIDB(db, {
|
||||
cacheIndexes: 1000,
|
||||
maxEvents: 10000,
|
||||
});
|
||||
|
||||
await this.cache.start();
|
||||
|
||||
// Automatically persist new events to the cache
|
||||
this._stopPersisting = persistEventsToCache(
|
||||
this.store,
|
||||
async (events) => {
|
||||
// Only cache profiles, mailboxes, blossom servers, and place photos, and deletions
|
||||
const toCache = events.filter(
|
||||
(e) =>
|
||||
e.kind === 0 ||
|
||||
e.kind === 5 ||
|
||||
e.kind === 10002 ||
|
||||
e.kind === 10063 ||
|
||||
e.kind === 360
|
||||
);
|
||||
|
||||
if (toCache.length > 0) {
|
||||
await Promise.all(toCache.map((event) => this.cache.add(event)));
|
||||
}
|
||||
},
|
||||
{
|
||||
batchTime: 1000, // Batch writes every 1 second
|
||||
maxBatchSize: 100,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Feed events from the relay pool into the event store
|
||||
this.nostrRelay.pool.relays$.subscribe(() => {
|
||||
// Setup relay subscription tracking if needed, or we just rely on request()
|
||||
// which returns an Observable<NostrEvent>
|
||||
});
|
||||
}
|
||||
|
||||
get requiredReadRelays() {
|
||||
return DEFAULT_READ_RELAYS;
|
||||
}
|
||||
|
||||
get requiredWriteRelays() {
|
||||
return DEFAULT_WRITE_RELAYS;
|
||||
}
|
||||
|
||||
get mailboxReadRelays() {
|
||||
return (this.mailboxes?.inboxes || [])
|
||||
.map(normalizeRelayUrl)
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
get mailboxWriteRelays() {
|
||||
return (this.mailboxes?.outboxes || [])
|
||||
.map(normalizeRelayUrl)
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
get configuredReadRelays() {
|
||||
const configured = uniqNormalizedRelays([
|
||||
...this.mailboxReadRelays,
|
||||
...(this.settings.nostrReadRelays || []),
|
||||
]);
|
||||
|
||||
return excludeRequiredRelays(
|
||||
configured,
|
||||
this.settings.nostrReadRelayExclusions || []
|
||||
);
|
||||
}
|
||||
|
||||
get configuredWriteRelays() {
|
||||
const configured = uniqNormalizedRelays([
|
||||
...this.mailboxWriteRelays,
|
||||
...(this.settings.nostrWriteRelays || []),
|
||||
]);
|
||||
|
||||
return excludeRequiredRelays(
|
||||
configured,
|
||||
this.settings.nostrWriteRelayExclusions || []
|
||||
);
|
||||
}
|
||||
|
||||
get activeReadRelays() {
|
||||
return mergeRequiredRelays(
|
||||
this.requiredReadRelays,
|
||||
this.configuredReadRelays
|
||||
);
|
||||
}
|
||||
|
||||
get activeWriteRelays() {
|
||||
return mergeRequiredRelays(
|
||||
this.requiredWriteRelays,
|
||||
this.configuredWriteRelays
|
||||
);
|
||||
}
|
||||
|
||||
async loadPlacesInBounds(bbox) {
|
||||
const requiredPrefixes = getGeohashPrefixesInBbox(bbox);
|
||||
|
||||
const missingPrefixes = requiredPrefixes.filter(
|
||||
(p) => !this.loadedGeohashPrefixes.has(p)
|
||||
);
|
||||
|
||||
if (missingPrefixes.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.debug(
|
||||
'[nostr-data] Loading place photos for prefixes:',
|
||||
missingPrefixes
|
||||
);
|
||||
|
||||
try {
|
||||
await this._cachePromise;
|
||||
|
||||
const cachedEvents = await this.cache.query([
|
||||
{
|
||||
kinds: [360],
|
||||
'#g': missingPrefixes,
|
||||
},
|
||||
]);
|
||||
|
||||
if (cachedEvents && cachedEvents.length > 0) {
|
||||
for (const event of cachedEvents) {
|
||||
this.store.add(event);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
'[nostr-data] Failed to read photos from local Nostr IDB cache',
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
// Fire network request for new prefixes
|
||||
this.nostrRelay.pool
|
||||
.request(this.activeReadRelays, [
|
||||
{
|
||||
kinds: [360],
|
||||
'#g': missingPrefixes,
|
||||
},
|
||||
])
|
||||
.subscribe({
|
||||
next: (event) => {
|
||||
this.store.add(event);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error(
|
||||
'[nostr-data] Error fetching place photos by geohash:',
|
||||
err
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
for (const p of missingPrefixes) {
|
||||
this.loadedGeohashPrefixes.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
async loadPhotosForPlace(place) {
|
||||
if (this._photosSub) {
|
||||
this._photosSub.unsubscribe();
|
||||
this._photosSub = null;
|
||||
}
|
||||
|
||||
this.placePhotos = [];
|
||||
|
||||
if (!place || !place.osmId || !place.osmType) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entityId = `osm:${place.osmType}:${place.osmId}`;
|
||||
|
||||
// Setup reactive store query
|
||||
this._photosSub = this.store
|
||||
.timeline([
|
||||
{
|
||||
kinds: [360],
|
||||
'#i': [entityId],
|
||||
},
|
||||
])
|
||||
.subscribe((events) => {
|
||||
this.placePhotos = events;
|
||||
});
|
||||
|
||||
try {
|
||||
await this._cachePromise;
|
||||
|
||||
const cachedEvents = await this.cache.query([
|
||||
{
|
||||
kinds: [360, 5],
|
||||
'#i': [entityId],
|
||||
},
|
||||
]);
|
||||
|
||||
if (cachedEvents && cachedEvents.length > 0) {
|
||||
for (const event of cachedEvents) {
|
||||
this.store.add(event);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
'[nostr-data] Failed to read photos for place from local Nostr IDB cache',
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
// Fire network request specifically for this place
|
||||
this.nostrRelay.pool
|
||||
.request(this.activeReadRelays, [
|
||||
{
|
||||
kinds: [360, 5],
|
||||
'#i': [entityId],
|
||||
},
|
||||
])
|
||||
.subscribe({
|
||||
next: (event) => {
|
||||
this.store.add(event);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error(
|
||||
'[nostr-data] Error fetching place photos for place:',
|
||||
err
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async loadProfile(pubkey) {
|
||||
if (!pubkey) return;
|
||||
|
||||
// Reset state
|
||||
this.profile = null;
|
||||
this.mailboxes = null;
|
||||
this.blossomServers = [];
|
||||
|
||||
this._cleanupSubscriptions();
|
||||
|
||||
// Setup models to track state reactively FIRST
|
||||
// This way, if cached events populate the store, the UI updates instantly.
|
||||
this._profileSub = this.store
|
||||
.model(ProfileModel, pubkey)
|
||||
.subscribe((profileContent) => {
|
||||
this.profile = profileContent;
|
||||
});
|
||||
|
||||
this._mailboxesSub = this.store
|
||||
.model(MailboxesModel, pubkey)
|
||||
.subscribe((mailboxesData) => {
|
||||
this.mailboxes = mailboxesData;
|
||||
});
|
||||
|
||||
this._blossomSub = this.store
|
||||
.replaceable(10063, pubkey)
|
||||
.subscribe((event) => {
|
||||
if (event && event.tags) {
|
||||
this.blossomServers = event.tags
|
||||
.filter((t) => t[0] === 'server' && t[1])
|
||||
.map((t) => t[1]);
|
||||
} else {
|
||||
this.blossomServers = [];
|
||||
}
|
||||
});
|
||||
|
||||
// 1. Await cache initialization and populate the EventStore with local data
|
||||
try {
|
||||
await this._cachePromise;
|
||||
|
||||
const cachedEvents = await this.cache.query([
|
||||
{
|
||||
authors: [pubkey],
|
||||
kinds: [0, 10002, 10063],
|
||||
},
|
||||
]);
|
||||
|
||||
if (cachedEvents && cachedEvents.length > 0) {
|
||||
for (const event of cachedEvents) {
|
||||
this.store.add(event);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to read from local Nostr IDB cache', e);
|
||||
}
|
||||
|
||||
// 2. Request new events from the network in the background and dump them into the store
|
||||
const profileRelays = Array.from(
|
||||
new Set([...DIRECTORY_RELAYS, ...this.activeWriteRelays])
|
||||
);
|
||||
this._requestSub = this.nostrRelay.pool
|
||||
.request(profileRelays, [
|
||||
{
|
||||
authors: [pubkey],
|
||||
kinds: [0, 10002, 10063],
|
||||
},
|
||||
])
|
||||
.subscribe({
|
||||
next: (event) => {
|
||||
this.store.add(event);
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error fetching profile events:', err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get userDisplayName() {
|
||||
if (this.profile) {
|
||||
if (this.profile.nip05) {
|
||||
return this.profile.nip05;
|
||||
}
|
||||
if (this.profile.displayName || this.profile.display_name) {
|
||||
return this.profile.displayName || this.profile.display_name;
|
||||
}
|
||||
if (this.profile.name) {
|
||||
return this.profile.name;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to npub
|
||||
if (this.nostrAuth.pubkey) {
|
||||
try {
|
||||
const npub = npubEncode(this.nostrAuth.pubkey);
|
||||
return `${npub.slice(0, 9)}...${npub.slice(-4)}`;
|
||||
} catch {
|
||||
return this.nostrAuth.pubkey;
|
||||
}
|
||||
}
|
||||
|
||||
return 'Not connected';
|
||||
}
|
||||
|
||||
async clearCache() {
|
||||
await this._cachePromise;
|
||||
if (this.cache) {
|
||||
await this.cache.deleteAllEvents();
|
||||
}
|
||||
}
|
||||
|
||||
_cleanupSubscriptions() {
|
||||
if (this._requestSub) {
|
||||
this._requestSub.unsubscribe();
|
||||
this._requestSub = null;
|
||||
}
|
||||
if (this._profileSub) {
|
||||
this._profileSub.unsubscribe();
|
||||
this._profileSub = null;
|
||||
}
|
||||
if (this._mailboxesSub) {
|
||||
this._mailboxesSub.unsubscribe();
|
||||
this._mailboxesSub = null;
|
||||
}
|
||||
if (this._blossomSub) {
|
||||
this._blossomSub.unsubscribe();
|
||||
this._blossomSub = null;
|
||||
}
|
||||
if (this._photosSub) {
|
||||
this._photosSub.unsubscribe();
|
||||
this._photosSub = null;
|
||||
}
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
super.willDestroy(...arguments);
|
||||
this._cleanupSubscriptions();
|
||||
|
||||
if (this._stopPersisting) {
|
||||
this._stopPersisting();
|
||||
}
|
||||
|
||||
if (this.cache) {
|
||||
this.cache.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,15 @@ import Service from '@ember/service';
|
||||
import { RelayPool } from 'applesauce-relay';
|
||||
|
||||
export default class NostrRelayService extends Service {
|
||||
pool = new RelayPool();
|
||||
pool = new RelayPool({ enablePing: true });
|
||||
|
||||
// For Phase 1, we hardcode the local relay
|
||||
relays = ['ws://127.0.0.1:7777'];
|
||||
|
||||
async publish(event) {
|
||||
async publish(relays, event) {
|
||||
if (!relays || relays.length === 0) {
|
||||
throw new Error('No relays provided to publish the event.');
|
||||
}
|
||||
// The publish method is a wrapper around the event method that returns a Promise<PublishResponse[]>
|
||||
// and automatically handles reconnecting and retrying.
|
||||
const responses = await this.pool.publish(this.relays, event);
|
||||
const responses = await this.pool.publish(relays, event);
|
||||
|
||||
// Check if at least one relay accepted the event
|
||||
const success = responses.some((res) => res.ok);
|
||||
|
||||
+26
-1
@@ -8,6 +8,7 @@ export default class OsmService extends Service {
|
||||
controller = null;
|
||||
cachedResults = null;
|
||||
lastQueryKey = null;
|
||||
cachedPlaces = new Map();
|
||||
|
||||
cancelAll() {
|
||||
if (this.controller) {
|
||||
@@ -232,6 +233,13 @@ out center;
|
||||
async fetchOsmObject(osmId, osmType) {
|
||||
if (!osmId || !osmType) return null;
|
||||
|
||||
const cacheKey = `${osmType}:${osmId}`;
|
||||
const cached = this.cachedPlaces.get(cacheKey);
|
||||
if (cached && Date.now() - cached.timestamp < 10000) {
|
||||
console.debug(`Using in-memory cached OSM object for ${cacheKey}`);
|
||||
return cached.data;
|
||||
}
|
||||
|
||||
let url;
|
||||
if (osmType === 'node') {
|
||||
url = `https://www.openstreetmap.org/api/0.6/node/${osmId}.json`;
|
||||
@@ -253,8 +261,25 @@ out center;
|
||||
}
|
||||
throw new Error(`OSM API request failed: ${res.status}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
return this.normalizeOsmApiData(data.elements, osmId, osmType);
|
||||
const normalizedData = this.normalizeOsmApiData(
|
||||
data.elements,
|
||||
osmId,
|
||||
osmType
|
||||
);
|
||||
|
||||
this.cachedPlaces.set(cacheKey, {
|
||||
data: normalizedData,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
|
||||
// Cleanup cache entry automatically after 10 seconds
|
||||
setTimeout(() => {
|
||||
this.cachedPlaces.delete(cacheKey);
|
||||
}, 10000);
|
||||
|
||||
return normalizedData;
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch OSM object:', e);
|
||||
return null;
|
||||
|
||||
+101
-38
@@ -1,11 +1,33 @@
|
||||
import Service from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
overpassApi: 'https://overpass-api.de/api/interpreter',
|
||||
mapKinetic: true,
|
||||
photonApi: 'https://photon.komoot.io/api/',
|
||||
showQuickSearchButtons: true,
|
||||
nostrPhotoFallbackUploads: false,
|
||||
nostrReadRelays: null,
|
||||
nostrWriteRelays: null,
|
||||
nostrReadRelayExclusions: null,
|
||||
nostrWriteRelayExclusions: null,
|
||||
experimentalEnablePhotoDeletion: false,
|
||||
};
|
||||
|
||||
export default class SettingsService extends Service {
|
||||
@tracked overpassApi = 'https://overpass-api.de/api/interpreter';
|
||||
@tracked mapKinetic = true;
|
||||
@tracked photonApi = 'https://photon.komoot.io/api/';
|
||||
@tracked showQuickSearchButtons = true;
|
||||
@tracked overpassApi = DEFAULT_SETTINGS.overpassApi;
|
||||
@tracked mapKinetic = DEFAULT_SETTINGS.mapKinetic;
|
||||
@tracked photonApi = DEFAULT_SETTINGS.photonApi;
|
||||
@tracked showQuickSearchButtons = DEFAULT_SETTINGS.showQuickSearchButtons;
|
||||
@tracked nostrPhotoFallbackUploads =
|
||||
DEFAULT_SETTINGS.nostrPhotoFallbackUploads;
|
||||
@tracked nostrReadRelays = DEFAULT_SETTINGS.nostrReadRelays;
|
||||
@tracked nostrWriteRelays = DEFAULT_SETTINGS.nostrWriteRelays;
|
||||
@tracked nostrReadRelayExclusions = DEFAULT_SETTINGS.nostrReadRelayExclusions;
|
||||
@tracked nostrWriteRelayExclusions =
|
||||
DEFAULT_SETTINGS.nostrWriteRelayExclusions;
|
||||
@tracked experimentalEnablePhotoDeletion =
|
||||
DEFAULT_SETTINGS.experimentalEnablePhotoDeletion;
|
||||
|
||||
overpassApis = [
|
||||
{
|
||||
@@ -39,49 +61,90 @@ export default class SettingsService extends Service {
|
||||
}
|
||||
|
||||
loadSettings() {
|
||||
const savedApi = localStorage.getItem('marco:overpass-api');
|
||||
if (savedApi) {
|
||||
// Check if saved API is still in the allowed list
|
||||
const isValid = this.overpassApis.some((api) => api.url === savedApi);
|
||||
if (isValid) {
|
||||
this.overpassApi = savedApi;
|
||||
} else {
|
||||
// If not valid, revert to default
|
||||
this.overpassApi = 'https://overpass-api.de/api/interpreter';
|
||||
localStorage.setItem('marco:overpass-api', this.overpassApi);
|
||||
let settings = {};
|
||||
const savedSettings = localStorage.getItem('marco:settings');
|
||||
|
||||
if (savedSettings) {
|
||||
try {
|
||||
settings = JSON.parse(savedSettings);
|
||||
} catch (e) {
|
||||
console.error('Failed to parse settings from localStorage', e);
|
||||
}
|
||||
} else {
|
||||
// Migration from old individual keys
|
||||
const savedApi = localStorage.getItem('marco:overpass-api');
|
||||
if (savedApi) settings.overpassApi = savedApi;
|
||||
|
||||
const savedKinetic = localStorage.getItem('marco:map-kinetic');
|
||||
if (savedKinetic !== null) settings.mapKinetic = savedKinetic === 'true';
|
||||
|
||||
const savedShowQuickSearch = localStorage.getItem(
|
||||
'marco:show-quick-search'
|
||||
);
|
||||
if (savedShowQuickSearch !== null) {
|
||||
settings.showQuickSearchButtons = savedShowQuickSearch === 'true';
|
||||
}
|
||||
|
||||
const savedNostrPhotoFallbackUploads = localStorage.getItem(
|
||||
'marco:nostr-photo-fallback-uploads'
|
||||
);
|
||||
if (savedNostrPhotoFallbackUploads !== null) {
|
||||
settings.nostrPhotoFallbackUploads =
|
||||
savedNostrPhotoFallbackUploads === 'true';
|
||||
}
|
||||
|
||||
const savedPhotonApi = localStorage.getItem('marco:photon-api');
|
||||
if (savedPhotonApi) settings.photonApi = savedPhotonApi;
|
||||
}
|
||||
|
||||
const savedKinetic = localStorage.getItem('marco:map-kinetic');
|
||||
if (savedKinetic !== null) {
|
||||
this.mapKinetic = savedKinetic === 'true';
|
||||
}
|
||||
// Default is true (initialized in class field)
|
||||
// Merge with defaults
|
||||
const finalSettings = { ...DEFAULT_SETTINGS, ...settings };
|
||||
|
||||
const savedShowQuickSearch = localStorage.getItem(
|
||||
'marco:show-quick-search'
|
||||
// Validate overpass API
|
||||
const isValid = this.overpassApis.some(
|
||||
(api) => api.url === finalSettings.overpassApi
|
||||
);
|
||||
if (savedShowQuickSearch !== null) {
|
||||
this.showQuickSearchButtons = savedShowQuickSearch === 'true';
|
||||
if (!isValid) {
|
||||
finalSettings.overpassApi = DEFAULT_SETTINGS.overpassApi;
|
||||
}
|
||||
|
||||
// Apply to tracked properties
|
||||
this.overpassApi = finalSettings.overpassApi;
|
||||
this.mapKinetic = finalSettings.mapKinetic;
|
||||
this.photonApi = finalSettings.photonApi;
|
||||
this.showQuickSearchButtons = finalSettings.showQuickSearchButtons;
|
||||
this.nostrPhotoFallbackUploads = finalSettings.nostrPhotoFallbackUploads;
|
||||
this.nostrReadRelays = finalSettings.nostrReadRelays;
|
||||
this.nostrWriteRelays = finalSettings.nostrWriteRelays;
|
||||
this.nostrReadRelayExclusions = finalSettings.nostrReadRelayExclusions;
|
||||
this.nostrWriteRelayExclusions = finalSettings.nostrWriteRelayExclusions;
|
||||
this.experimentalEnablePhotoDeletion =
|
||||
finalSettings.experimentalEnablePhotoDeletion;
|
||||
|
||||
// Save to ensure migrated settings are stored in the new format
|
||||
this.saveSettings();
|
||||
}
|
||||
|
||||
updateOverpassApi(url) {
|
||||
this.overpassApi = url;
|
||||
localStorage.setItem('marco:overpass-api', url);
|
||||
saveSettings() {
|
||||
const settings = {
|
||||
overpassApi: this.overpassApi,
|
||||
mapKinetic: this.mapKinetic,
|
||||
photonApi: this.photonApi,
|
||||
showQuickSearchButtons: this.showQuickSearchButtons,
|
||||
nostrPhotoFallbackUploads: this.nostrPhotoFallbackUploads,
|
||||
nostrReadRelays: this.nostrReadRelays,
|
||||
nostrWriteRelays: this.nostrWriteRelays,
|
||||
nostrReadRelayExclusions: this.nostrReadRelayExclusions,
|
||||
nostrWriteRelayExclusions: this.nostrWriteRelayExclusions,
|
||||
experimentalEnablePhotoDeletion: this.experimentalEnablePhotoDeletion,
|
||||
};
|
||||
localStorage.setItem('marco:settings', JSON.stringify(settings));
|
||||
}
|
||||
|
||||
updateMapKinetic(enabled) {
|
||||
this.mapKinetic = enabled;
|
||||
localStorage.setItem('marco:map-kinetic', String(enabled));
|
||||
}
|
||||
|
||||
updateShowQuickSearchButtons(enabled) {
|
||||
this.showQuickSearchButtons = enabled;
|
||||
localStorage.setItem('marco:show-quick-search', String(enabled));
|
||||
}
|
||||
|
||||
updatePhotonApi(url) {
|
||||
this.photonApi = url;
|
||||
update(key, value) {
|
||||
if (key in DEFAULT_SETTINGS) {
|
||||
this[key] = value;
|
||||
this.saveSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { getLocalizedName } from '../utils/osm';
|
||||
|
||||
export default class StorageService extends Service {
|
||||
@service osm;
|
||||
@service toast;
|
||||
rs;
|
||||
widget;
|
||||
@tracked placesInView = [];
|
||||
@@ -23,10 +24,13 @@ export default class StorageService extends Service {
|
||||
@tracked connected = false;
|
||||
@tracked userAddress = null;
|
||||
@tracked isWidgetOpen = false;
|
||||
isNewConnection = true;
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
|
||||
this.checkInitialConnectionState();
|
||||
|
||||
this.rs = new RemoteStorage({
|
||||
modules: [Places],
|
||||
});
|
||||
@@ -57,6 +61,12 @@ export default class StorageService extends Service {
|
||||
this.rs.on('connected', () => {
|
||||
this.connected = true;
|
||||
this.userAddress = this.rs.remote.userAddress;
|
||||
|
||||
if (this.isNewConnection) {
|
||||
this.toast.show('Remote storage connected', 3000);
|
||||
this.isNewConnection = false;
|
||||
}
|
||||
|
||||
this.loadLists();
|
||||
});
|
||||
|
||||
@@ -72,6 +82,7 @@ export default class StorageService extends Service {
|
||||
this.loadedPrefixes = [];
|
||||
this.lists = [];
|
||||
this.initialSyncDone = false;
|
||||
this.isNewConnection = true;
|
||||
});
|
||||
|
||||
this.rs.on('sync-done', () => {
|
||||
@@ -93,6 +104,31 @@ export default class StorageService extends Service {
|
||||
});
|
||||
}
|
||||
|
||||
checkInitialConnectionState() {
|
||||
this.isNewConnection = true;
|
||||
try {
|
||||
if (window.localStorage) {
|
||||
const keys = [
|
||||
'remotestorage:wireclient',
|
||||
'remotestorage:dropbox',
|
||||
'remotestorage:googledrive',
|
||||
];
|
||||
for (const key of keys) {
|
||||
const data = window.localStorage.getItem(key);
|
||||
if (data) {
|
||||
const parsed = JSON.parse(data);
|
||||
if (parsed && parsed.token) {
|
||||
this.isNewConnection = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to check localStorage for existing connection:', e);
|
||||
}
|
||||
}
|
||||
|
||||
handlePlaceChange(event) {
|
||||
const { newValue, relativePath } = event;
|
||||
|
||||
@@ -234,6 +270,11 @@ export default class StorageService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
async getPlacesInList(listId) {
|
||||
if (!this.places || !this.places.lists) return [];
|
||||
return this.places.lists.getPlaces(listId);
|
||||
}
|
||||
|
||||
async loadPlacesInBounds(bbox) {
|
||||
// 1. Calculate required prefixes
|
||||
const requiredPrefixes = getGeohashPrefixesInBbox(bbox);
|
||||
|
||||
+839
-52
File diff suppressed because it is too large
Load Diff
@@ -2,12 +2,9 @@ import Component from '@glimmer/component';
|
||||
import { pageTitle } from 'ember-page-title';
|
||||
import Map from '#components/map';
|
||||
import AppHeader from '#components/app-header';
|
||||
import AppMenu from '#components/app-menu/index';
|
||||
import Toast from '#components/toast';
|
||||
import { service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { or } from 'ember-truth-helpers';
|
||||
import { on } from '@ember/modifier';
|
||||
|
||||
export default class ApplicationComponent extends Component {
|
||||
@@ -15,15 +12,17 @@ export default class ApplicationComponent extends Component {
|
||||
@service mapUi;
|
||||
@service router;
|
||||
|
||||
@tracked isAppMenuOpen = false;
|
||||
|
||||
get isSidebarOpen() {
|
||||
// We consider the sidebar "open" if we are in search or place routes.
|
||||
// We consider the sidebar "open" if we are in search, menu, lists or place routes AND it's visible.
|
||||
// This helps the map know if it should shift the center or adjust view.
|
||||
const name = this.router.currentRouteName;
|
||||
return (
|
||||
this.router.currentRouteName === 'place' ||
|
||||
this.router.currentRouteName === 'place.new' ||
|
||||
this.router.currentRouteName === 'search'
|
||||
this.mapUi.isSidebarVisible &&
|
||||
(name === 'place' ||
|
||||
name === 'place.new' ||
|
||||
name === 'search' ||
|
||||
name === 'menu' ||
|
||||
name.startsWith('lists'))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,25 +35,35 @@ export default class ApplicationComponent extends Component {
|
||||
|
||||
@action
|
||||
toggleAppMenu() {
|
||||
this.isAppMenuOpen = !this.isAppMenuOpen;
|
||||
}
|
||||
|
||||
@action
|
||||
closeAppMenu() {
|
||||
this.isAppMenuOpen = false;
|
||||
if (this.router.currentRouteName === 'menu') {
|
||||
this.router.transitionTo('index');
|
||||
} else {
|
||||
this.router.transitionTo('menu');
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
handleOutsideClick() {
|
||||
if (this.isAppMenuOpen) {
|
||||
this.closeAppMenu();
|
||||
} else if (this.router.currentRouteName === 'search') {
|
||||
this.router.transitionTo('index');
|
||||
} else if (this.router.currentRouteName === 'place') {
|
||||
// If in place route, decide if we want to go back to search or index
|
||||
// For now, let's go to index or maybe back to search if search params exist?
|
||||
// Simplest behavior: clear selection
|
||||
this.router.transitionTo('index');
|
||||
const name = this.router.currentRouteName;
|
||||
if (
|
||||
name === 'search' ||
|
||||
name === 'place' ||
|
||||
name === 'menu' ||
|
||||
name.startsWith('lists')
|
||||
) {
|
||||
this.mapUi.clearSelection();
|
||||
this.mapUi.hideSidebar();
|
||||
if (name === 'menu' || name.startsWith('lists')) {
|
||||
this.router.transitionTo('index');
|
||||
} else if (name === 'place') {
|
||||
if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
|
||||
this.router.transitionTo('search', {
|
||||
queryParams: this.mapUi.currentSearch,
|
||||
});
|
||||
} else {
|
||||
this.router.transitionTo('index');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,32 +75,30 @@ export default class ApplicationComponent extends Component {
|
||||
<template>
|
||||
{{pageTitle "Marco"}}
|
||||
|
||||
<AppHeader @onToggleMenu={{this.toggleAppMenu}} />
|
||||
<div class={{if this.mapUi.isSidebarOpening "sidebar-opening"}}>
|
||||
<AppHeader @onToggleMenu={{this.toggleAppMenu}} />
|
||||
|
||||
<div
|
||||
id="rs-widget-container"
|
||||
class={{if this.storage.isWidgetOpen "visible"}}
|
||||
></div>
|
||||
|
||||
{{#if this.storage.isWidgetOpen}}
|
||||
<div
|
||||
class="rs-backdrop"
|
||||
role="button"
|
||||
{{on "click" this.storage.closeWidget}}
|
||||
id="rs-widget-container"
|
||||
class={{if this.storage.isWidgetOpen "visible"}}
|
||||
></div>
|
||||
{{/if}}
|
||||
|
||||
<Map
|
||||
@isSidebarOpen={{or this.isSidebarOpen this.isAppMenuOpen}}
|
||||
@onOutsideClick={{this.handleOutsideClick}}
|
||||
/>
|
||||
{{#if this.storage.isWidgetOpen}}
|
||||
<div
|
||||
class="rs-backdrop"
|
||||
role="button"
|
||||
{{on "click" this.storage.closeWidget}}
|
||||
></div>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.isAppMenuOpen}}
|
||||
<AppMenu @onClose={{this.closeAppMenu}} />
|
||||
{{/if}}
|
||||
<Map
|
||||
@isSidebarOpen={{this.isSidebarOpen}}
|
||||
@onOutsideClick={{this.handleOutsideClick}}
|
||||
/>
|
||||
|
||||
<Toast />
|
||||
<Toast />
|
||||
|
||||
{{outlet}}
|
||||
{{outlet}}
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<template>{{outlet}}</template>
|
||||
@@ -0,0 +1,89 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { fn } from '@ember/helper';
|
||||
import { on } from '@ember/modifier';
|
||||
import Icon from '#components/icon';
|
||||
import { htmlSafe } from '@ember/template';
|
||||
|
||||
export default class ListsIndexTemplate extends Component {
|
||||
@service storage;
|
||||
@service router;
|
||||
@service mapUi;
|
||||
|
||||
styleFor(color) {
|
||||
const finalColor =
|
||||
color ||
|
||||
getComputedStyle(document.documentElement)
|
||||
.getPropertyValue('--default-list-color')
|
||||
.trim();
|
||||
return htmlSafe(`background-color: ${finalColor}`);
|
||||
}
|
||||
|
||||
@action
|
||||
selectList(listId) {
|
||||
this.router.transitionTo('lists.list', listId);
|
||||
}
|
||||
|
||||
@action
|
||||
close() {
|
||||
this.router.transitionTo('index');
|
||||
}
|
||||
|
||||
@action
|
||||
backToMenu() {
|
||||
this.router.transitionTo('menu');
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if this.mapUi.isSidebarVisible}}
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header has-back-btn">
|
||||
<button type="button" class="back-btn" {{on "click" this.backToMenu}}>
|
||||
<Icon @name="arrow-left" @size={{20}} @color="#333" />
|
||||
</button>
|
||||
<h2 class="sidebar-header-text-centered">
|
||||
<span class="sidebar-header-icon-wrapper">
|
||||
<Icon @name="bookmark" @size={{20}} @color="#898989" />
|
||||
</span>
|
||||
Collections
|
||||
</h2>
|
||||
<button type="button" class="close-btn" {{on "click" this.close}}>
|
||||
<Icon @name="x" @size={{20}} @color="#333" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-content">
|
||||
<ul class="places-list">
|
||||
{{#each this.storage.lists as |list|}}
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
class="lists-index-item"
|
||||
{{on "click" (fn this.selectList list.id)}}
|
||||
>
|
||||
<div class="lists-index-item-left">
|
||||
{{! template-lint-disable no-inline-styles }}
|
||||
<span
|
||||
class="list-color-dot"
|
||||
style={{this.styleFor list.color}}
|
||||
></span>
|
||||
<div class="lists-index-name">{{list.title}}</div>
|
||||
</div>
|
||||
<div class="lists-index-count">
|
||||
{{#if list.placeRefs.length}}
|
||||
{{list.placeRefs.length}}
|
||||
places
|
||||
{{else}}
|
||||
empty
|
||||
{{/if}}
|
||||
</div>
|
||||
</button>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import PlacesSidebar from '#components/places-sidebar';
|
||||
|
||||
<template>
|
||||
{{#if @controller.mapUi.isSidebarVisible}}
|
||||
<PlacesSidebar
|
||||
@places={{@controller.places}}
|
||||
@title={{@controller.listTitle}}
|
||||
@color={{@controller.listColor}}
|
||||
@scrollTop={{@controller.scrollTop}}
|
||||
@isLoading={{@controller.loadPlacesTask.isRunning}}
|
||||
@onSelect={{@controller.selectPlace}}
|
||||
@onClose={{@controller.close}}
|
||||
@onBack={{@controller.backToLists}}
|
||||
/>
|
||||
{{/if}}
|
||||
</template>
|
||||
@@ -0,0 +1,15 @@
|
||||
import Component from '@glimmer/component';
|
||||
import AppMenu from '#components/app-menu/index';
|
||||
import { service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class MenuTemplate extends Component {
|
||||
@service router;
|
||||
|
||||
@action
|
||||
close() {
|
||||
this.router.transitionTo('index');
|
||||
}
|
||||
|
||||
<template><AppMenu @onClose={{this.close}} /></template>
|
||||
}
|
||||
+27
-10
@@ -77,8 +77,15 @@ export default class PlaceTemplate extends Component {
|
||||
navigateBack(place) {
|
||||
// The sidebar calls this with null when "Back" is clicked.
|
||||
if (place === null) {
|
||||
// If we have an active route context (e.g. lists), return to it
|
||||
if (this.mapUi.returnToRoute) {
|
||||
this.mapUi.showSidebar();
|
||||
const { name, model } = this.mapUi.returnToRoute;
|
||||
this.router.transitionTo(name, model);
|
||||
}
|
||||
// If we have an active search context, return to it (UP navigation)
|
||||
if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
|
||||
else if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
|
||||
this.mapUi.showSidebar();
|
||||
this.router.transitionTo('search', {
|
||||
queryParams: this.mapUi.currentSearch,
|
||||
});
|
||||
@@ -88,23 +95,33 @@ export default class PlaceTemplate extends Component {
|
||||
}
|
||||
} else {
|
||||
// If a place is selected (unlikely in this view, but possible if we add related links)
|
||||
this.mapUi.showSidebar();
|
||||
this.router.transitionTo('place', place);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
close() {
|
||||
// Clear search results so we don't fall back to the list
|
||||
this.router.transitionTo('index');
|
||||
this.mapUi.clearSelection();
|
||||
this.mapUi.hideSidebar();
|
||||
if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
|
||||
this.router.transitionTo('search', {
|
||||
queryParams: this.mapUi.currentSearch,
|
||||
});
|
||||
} else {
|
||||
this.router.transitionTo('index');
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
<PlacesSidebar
|
||||
@selectedPlace={{this.place}}
|
||||
@onClose={{this.close}}
|
||||
@onSelect={{this.navigateBack}}
|
||||
@onBookmarkChange={{this.refreshMap}}
|
||||
@onUpdate={{this.handleUpdate}}
|
||||
/>
|
||||
{{#if this.mapUi.isSidebarVisible}}
|
||||
<PlacesSidebar
|
||||
@selectedPlace={{this.place}}
|
||||
@onClose={{this.close}}
|
||||
@onSelect={{this.navigateBack}}
|
||||
@onBookmarkChange={{this.refreshMap}}
|
||||
@onUpdate={{this.handleUpdate}}
|
||||
/>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
|
||||
+22
-20
@@ -56,28 +56,30 @@ export default class PlaceNewTemplate extends Component {
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h2><Icon @name="plus-circle" @size={{20}} @color="#ea4335" />
|
||||
New Place</h2>
|
||||
<button type="button" class="close-btn" {{on "click" this.close}}><Icon
|
||||
@name="x"
|
||||
@size={{20}}
|
||||
@color="#333"
|
||||
/></button>
|
||||
</div>
|
||||
{{#if this.mapUi.isSidebarVisible}}
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h2><Icon @name="plus-circle" @size={{20}} @color="#ea4335" />
|
||||
New Place</h2>
|
||||
<button
|
||||
type="button"
|
||||
class="close-btn"
|
||||
{{on "click" this.close}}
|
||||
><Icon @name="x" @size={{20}} @color="#333" /></button>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-content">
|
||||
<p class="helper-text">
|
||||
Drag the map to position the crosshair.
|
||||
</p>
|
||||
<div class="sidebar-content">
|
||||
<p class="helper-text">
|
||||
Drag the map to position the crosshair.
|
||||
</p>
|
||||
|
||||
<PlaceEditForm
|
||||
@place={{this.initialPlace}}
|
||||
@onSave={{this.savePlace}}
|
||||
@onCancel={{this.close}}
|
||||
/>
|
||||
<PlaceEditForm
|
||||
@place={{this.initialPlace}}
|
||||
@onSave={{this.savePlace}}
|
||||
@onCancel={{this.close}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -10,7 +10,13 @@ export default class SearchTemplate extends Component {
|
||||
@action
|
||||
selectPlace(place) {
|
||||
if (place) {
|
||||
const sidebarContent = document.querySelector('.sidebar-content');
|
||||
if (sidebarContent) {
|
||||
this.mapUi.saveScrollPosition('search', sidebarContent.scrollTop);
|
||||
}
|
||||
this.mapUi.returnToSearch = true;
|
||||
this.mapUi.showSidebar();
|
||||
this.mapUi.preventNextZoom = true;
|
||||
// We don't need to manually set currentSearch here because
|
||||
// it was already set in the route's setupController
|
||||
this.router.transitionTo('place', place);
|
||||
@@ -19,14 +25,17 @@ export default class SearchTemplate extends Component {
|
||||
|
||||
@action
|
||||
close() {
|
||||
this.router.transitionTo('index');
|
||||
this.mapUi.hideSidebar();
|
||||
}
|
||||
|
||||
<template>
|
||||
<PlacesSidebar
|
||||
@places={{@model}}
|
||||
@onSelect={{this.selectPlace}}
|
||||
@onClose={{this.close}}
|
||||
/>
|
||||
{{#if this.mapUi.isSidebarVisible}}
|
||||
<PlacesSidebar
|
||||
@places={{this.mapUi.searchResults}}
|
||||
@scrollTop={{this.mapUi.getScrollPosition "search"}}
|
||||
@onSelect={{this.selectPlace}}
|
||||
@onClose={{this.close}}
|
||||
/>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export function isMobile() {
|
||||
if (typeof navigator === 'undefined') return false;
|
||||
return /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
|
||||
}
|
||||
@@ -7,3 +7,8 @@ export function humanizeOsmTag(text) {
|
||||
w.replace(/^\w/, (c) => c.toUpperCase())
|
||||
);
|
||||
}
|
||||
|
||||
export function capitalize(text) {
|
||||
if (typeof text !== 'string' || !text) return '';
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export function getGeohashPrefixesInBbox(bbox) {
|
||||
|
||||
// Safety check to avoid infinite loops or massive arrays if bbox is weird
|
||||
if (Math.abs(maxLat - minLat) > 20 || Math.abs(maxLon - minLon) > 20) {
|
||||
console.warn(
|
||||
console.debug(
|
||||
'BBox too large for 4-char geohash scanning, aborting fine scan.'
|
||||
);
|
||||
return [];
|
||||
|
||||
+50
-1
@@ -1,10 +1,17 @@
|
||||
// AGENT: Keep imports sorted alphabetically, grouped by feather-icons → pinhead → custom/local
|
||||
/*
|
||||
* Feather icons
|
||||
*/
|
||||
import activity from 'feather-icons/dist/icons/activity.svg?raw';
|
||||
import arrowLeft from 'feather-icons/dist/icons/arrow-left.svg?raw';
|
||||
import bookmark from 'feather-icons/dist/icons/bookmark.svg?raw';
|
||||
import camera from 'feather-icons/dist/icons/camera.svg?raw';
|
||||
import featherCamera from 'feather-icons/dist/icons/camera.svg?raw';
|
||||
import checkSquare from 'feather-icons/dist/icons/check-square.svg?raw';
|
||||
import chevronLeft from 'feather-icons/dist/icons/chevron-left.svg?raw';
|
||||
import chevronRight from 'feather-icons/dist/icons/chevron-right.svg?raw';
|
||||
import alertTriangle from 'feather-icons/dist/icons/alert-triangle.svg?raw';
|
||||
import clock from 'feather-icons/dist/icons/clock.svg?raw';
|
||||
import database from 'feather-icons/dist/icons/database.svg?raw';
|
||||
import edit from 'feather-icons/dist/icons/edit.svg?raw';
|
||||
import facebook from 'feather-icons/dist/icons/facebook.svg?raw';
|
||||
import gift from 'feather-icons/dist/icons/gift.svg?raw';
|
||||
@@ -19,6 +26,8 @@ import mail from 'feather-icons/dist/icons/mail.svg?raw';
|
||||
import map from 'feather-icons/dist/icons/map.svg?raw';
|
||||
import mapPin from 'feather-icons/dist/icons/map-pin.svg?raw';
|
||||
import menu from 'feather-icons/dist/icons/menu.svg?raw';
|
||||
import moreHorizontal from 'feather-icons/dist/icons/more-horizontal.svg?raw';
|
||||
import moreVertical from 'feather-icons/dist/icons/more-vertical.svg?raw';
|
||||
import navigation from 'feather-icons/dist/icons/navigation.svg?raw';
|
||||
import phone from 'feather-icons/dist/icons/phone.svg?raw';
|
||||
import plus from 'feather-icons/dist/icons/plus.svg?raw';
|
||||
@@ -26,10 +35,17 @@ import search from 'feather-icons/dist/icons/search.svg?raw';
|
||||
import server from 'feather-icons/dist/icons/server.svg?raw';
|
||||
import settings from 'feather-icons/dist/icons/settings.svg?raw';
|
||||
import target from 'feather-icons/dist/icons/target.svg?raw';
|
||||
import trash2 from 'feather-icons/dist/icons/trash-2.svg?raw';
|
||||
import uploadCloud from 'feather-icons/dist/icons/upload-cloud.svg?raw';
|
||||
import user from 'feather-icons/dist/icons/user.svg?raw';
|
||||
import x from 'feather-icons/dist/icons/x.svg?raw';
|
||||
import check from 'feather-icons/dist/icons/check.svg?raw';
|
||||
import alertCircle from 'feather-icons/dist/icons/alert-circle.svg?raw';
|
||||
import zap from 'feather-icons/dist/icons/zap.svg?raw';
|
||||
|
||||
/*
|
||||
* Pinhead icons
|
||||
*/
|
||||
import angelfish from '@waysidemapping/pinhead/dist/icons/angelfish.svg?raw';
|
||||
import barbell from '@waysidemapping/pinhead/dist/icons/barbell.svg?raw';
|
||||
import climbingWall from '@waysidemapping/pinhead/dist/icons/climbing_wall.svg?raw';
|
||||
@@ -38,11 +54,17 @@ import badgeShieldWithFire from '@waysidemapping/pinhead/dist/icons/badge_shield
|
||||
import beachUmbrellaInGround from '@waysidemapping/pinhead/dist/icons/beach_umbrella_in_ground.svg?raw';
|
||||
import beerMugWithFoam from '@waysidemapping/pinhead/dist/icons/beer_mug_with_foam.svg?raw';
|
||||
import burgerAndDrinkCupWithStraw from '@waysidemapping/pinhead/dist/icons/burger_and_drink_cup_with_straw.svg?raw';
|
||||
import bridge from '@waysidemapping/pinhead/dist/icons/bridge.svg?raw';
|
||||
import bus from '@waysidemapping/pinhead/dist/icons/bus.svg?raw';
|
||||
import camera from '@waysidemapping/pinhead/dist/icons/camera.svg?raw';
|
||||
import boxingGloveUp from '@waysidemapping/pinhead/dist/icons/boxing_glove_up.svg?raw';
|
||||
import car from '@waysidemapping/pinhead/dist/icons/car.svg?raw';
|
||||
import carAndWrench from '@waysidemapping/pinhead/dist/icons/car_and_wrench.svg?raw';
|
||||
import castleKeep from '@waysidemapping/pinhead/dist/icons/castle_keep.svg?raw';
|
||||
import cigaretteWithSmokeCurl from '@waysidemapping/pinhead/dist/icons/cigarette_with_smoke_curl.svg?raw';
|
||||
import cityGate from '@waysidemapping/pinhead/dist/icons/city_gate.svg?raw';
|
||||
import classicalBuilding from '@waysidemapping/pinhead/dist/icons/classical_building.svg?raw';
|
||||
import classicalBuildingWithClock from '@waysidemapping/pinhead/dist/icons/classical_building_with_clock.svg?raw';
|
||||
import classicalBuildingWithDomeAndFlag from '@waysidemapping/pinhead/dist/icons/classical_building_with_dome_and_flag.svg?raw';
|
||||
import classicalBuildingWithFlag from '@waysidemapping/pinhead/dist/icons/classical_building_with_flag.svg?raw';
|
||||
import commercialBuilding from '@waysidemapping/pinhead/dist/icons/commercial_building.svg?raw';
|
||||
@@ -69,6 +91,8 @@ import gravestone from '@waysidemapping/pinhead/dist/icons/gravestone.svg?raw';
|
||||
import grecianVase from '@waysidemapping/pinhead/dist/icons/grecian_vase.svg?raw';
|
||||
import greekCross from '@waysidemapping/pinhead/dist/icons/greek_cross.svg?raw';
|
||||
import iceCreamOnCone from '@waysidemapping/pinhead/dist/icons/ice_cream_on_cone.svg?raw';
|
||||
import industrialBuilding from '@waysidemapping/pinhead/dist/icons/industrial_building.svg?raw';
|
||||
import infoI from '@waysidemapping/pinhead/dist/icons/info_i.svg?raw';
|
||||
import jewel from '@waysidemapping/pinhead/dist/icons/jewel.svg?raw';
|
||||
import lowriseBuilding from '@waysidemapping/pinhead/dist/icons/lowrise_building.svg?raw';
|
||||
import marketStall from '@waysidemapping/pinhead/dist/icons/market_stall.svg?raw';
|
||||
@@ -96,6 +120,7 @@ import roundStructureWithFlag from '@waysidemapping/pinhead/dist/icons/round_str
|
||||
import sailingShipInWater from '@waysidemapping/pinhead/dist/icons/sailing_ship_in_water.svg?raw';
|
||||
import scissorsOpen from '@waysidemapping/pinhead/dist/icons/scissors_open.svg?raw';
|
||||
import shipwreckInWater from '@waysidemapping/pinhead/dist/icons/shipwreck_in_water.svg?raw';
|
||||
import steamTrainOnRailwayTrack from '@waysidemapping/pinhead/dist/icons/steam_train_on_railway_track.svg?raw';
|
||||
import shoppingBag from '@waysidemapping/pinhead/dist/icons/shopping_bag.svg?raw';
|
||||
import shoppingBasket from '@waysidemapping/pinhead/dist/icons/shopping_basket.svg?raw';
|
||||
import shoppingCart from '@waysidemapping/pinhead/dist/icons/shopping_cart.svg?raw';
|
||||
@@ -105,8 +130,12 @@ import toolbox from '@waysidemapping/pinhead/dist/icons/toolbox.svg?raw';
|
||||
import treeAndBenchWithBackrest from '@waysidemapping/pinhead/dist/icons/tree_and_bench_with_backrest.svg?raw';
|
||||
import villageBuildings from '@waysidemapping/pinhead/dist/icons/village_buildings.svg?raw';
|
||||
import wallHangingWithMountainsAndSun from '@waysidemapping/pinhead/dist/icons/wall_hanging_with_mountains_and_sun.svg?raw';
|
||||
import windingWayWide from '@waysidemapping/pinhead/dist/icons/winding_way_wide.svg?raw';
|
||||
import womensAndMensRestroomSymbol from '@waysidemapping/pinhead/dist/icons/womens_and_mens_restroom_symbol.svg?raw';
|
||||
|
||||
/*
|
||||
* Custom/local icons
|
||||
*/
|
||||
import loadingRing from '../icons/270-ring.svg?raw';
|
||||
import nostrich from '../icons/nostrich-2.svg?raw';
|
||||
import remotestorage from '../icons/remotestorage.svg?raw';
|
||||
@@ -125,12 +154,21 @@ const ICONS = {
|
||||
bookmark,
|
||||
'boxing-glove-up': boxingGloveUp,
|
||||
'burger-and-drink-cup-with-straw': burgerAndDrinkCupWithStraw,
|
||||
bridge,
|
||||
bus,
|
||||
camera,
|
||||
'feather-camera': featherCamera,
|
||||
'check-square': checkSquare,
|
||||
'chevron-left': chevronLeft,
|
||||
'chevron-right': chevronRight,
|
||||
'cigarette-with-smoke-curl': cigaretteWithSmokeCurl,
|
||||
'city-gate': cityGate,
|
||||
climbing_wall: climbingWall,
|
||||
check,
|
||||
'alert-circle': alertCircle,
|
||||
'alert-triangle': alertTriangle,
|
||||
'classical-building': classicalBuilding,
|
||||
'classical-building-with-clock': classicalBuildingWithClock,
|
||||
'classical-building-with-dome-and-flag': classicalBuildingWithDomeAndFlag,
|
||||
'classical-building-with-flag': classicalBuildingWithFlag,
|
||||
'commercial-building': commercialBuilding,
|
||||
@@ -143,6 +181,7 @@ const ICONS = {
|
||||
'comedy-mask-and-tragedy-mask': comedyMaskAndTragedyMask,
|
||||
croissant,
|
||||
'cup-and-saucer': cupAndSaucer,
|
||||
database,
|
||||
donut,
|
||||
edit,
|
||||
eyeglasses,
|
||||
@@ -164,7 +203,9 @@ const ICONS = {
|
||||
heart,
|
||||
home,
|
||||
'ice-cream-on-cone': iceCreamOnCone,
|
||||
'industrial-building': industrialBuilding,
|
||||
info,
|
||||
'info-i': infoI,
|
||||
instagram,
|
||||
jewel,
|
||||
'log-in': logIn,
|
||||
@@ -178,6 +219,8 @@ const ICONS = {
|
||||
menu,
|
||||
'mobile-phone-with-keypad-and-antenna': mobilePhoneWithKeypadAndAntenna,
|
||||
'molar-tooth': molarTooth,
|
||||
'more-horizontal': moreHorizontal,
|
||||
'more-vertical': moreVertical,
|
||||
navigation,
|
||||
'needle-and-spool-of-thread': needleAndSpoolOfThread,
|
||||
nostrich,
|
||||
@@ -204,6 +247,7 @@ const ICONS = {
|
||||
'sailing-ship-in-water': sailingShipInWater,
|
||||
'scissors-open': scissorsOpen,
|
||||
'shipwreck-in-water': shipwreckInWater,
|
||||
'steam-train-on-railway-track': steamTrainOnRailwayTrack,
|
||||
'shopping-bag': shoppingBag,
|
||||
search,
|
||||
server,
|
||||
@@ -214,6 +258,8 @@ const ICONS = {
|
||||
'tattoo-machine': tattooMachine,
|
||||
toolbox,
|
||||
target,
|
||||
'trash-2': trash2,
|
||||
'upload-cloud': uploadCloud,
|
||||
'tree-and-bench-with-backrest': treeAndBenchWithBackrest,
|
||||
user,
|
||||
'village-buildings': villageBuildings,
|
||||
@@ -221,8 +267,11 @@ const ICONS = {
|
||||
'womens-and-mens-restroom-symbol': womensAndMensRestroomSymbol,
|
||||
whatsapp,
|
||||
wikipedia,
|
||||
winding_way_wide: windingWayWide,
|
||||
parking_p: parkingP,
|
||||
car,
|
||||
'car-and-wrench': carAndWrench,
|
||||
'castle-keep': castleKeep,
|
||||
x,
|
||||
zap,
|
||||
'loading-ring': loadingRing,
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
export function normalizeRelayUrl(url) {
|
||||
if (!url) return '';
|
||||
let normalized = url.trim().toLowerCase();
|
||||
if (!normalized) return '';
|
||||
|
||||
if (!normalized.startsWith('ws://') && !normalized.startsWith('wss://')) {
|
||||
normalized = 'wss://' + normalized;
|
||||
}
|
||||
|
||||
while (normalized.endsWith('/')) {
|
||||
normalized = normalized.slice(0, -1);
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function uniqNormalizedRelays(relays = []) {
|
||||
return Array.from(new Set(relays.map(normalizeRelayUrl).filter(Boolean)));
|
||||
}
|
||||
|
||||
export function mergeRequiredRelays(requiredRelays = [], customRelays = []) {
|
||||
const requiredSet = new Set(requiredRelays.filter(Boolean));
|
||||
const merged = [...requiredRelays.filter(Boolean)];
|
||||
|
||||
for (const relay of uniqNormalizedRelays(customRelays)) {
|
||||
if (!requiredSet.has(relay)) {
|
||||
merged.push(relay);
|
||||
}
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
export function excludeRequiredRelays(customRelays = [], requiredRelays = []) {
|
||||
const requiredSet = new Set(requiredRelays.filter(Boolean));
|
||||
return uniqNormalizedRelays(customRelays).filter((relay) => {
|
||||
return !requiredSet.has(relay);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts and normalizes photo data from NIP-360 (Place Photos) events.
|
||||
* Sorts chronologically and guarantees the first landscape photo (or first portrait) is at index 0.
|
||||
*
|
||||
* @param {Array} events NIP-360 events
|
||||
* @returns {Array} Array of photo objects
|
||||
*/
|
||||
export function parsePlacePhotos(events) {
|
||||
if (!events || events.length === 0) return [];
|
||||
|
||||
// Sort by created_at ascending (oldest first)
|
||||
const sortedEvents = [...events].sort((a, b) => a.created_at - b.created_at);
|
||||
|
||||
const allPhotos = [];
|
||||
|
||||
for (const event of sortedEvents) {
|
||||
const eventTagValues = event.tags
|
||||
.filter((t) => t[0] === 't')
|
||||
.map((t) => t[1])
|
||||
.filter(Boolean);
|
||||
|
||||
// Find all imeta tags
|
||||
const imetas = event.tags.filter((t) => t[0] === 'imeta');
|
||||
for (const imeta of imetas) {
|
||||
let url = null;
|
||||
let thumbUrl = null;
|
||||
let blurhash = null;
|
||||
let isLandscape = false;
|
||||
let aspectRatio = 16 / 9; // default
|
||||
let placeIdentifier = event.tags.find((t) => t[0] === 'i')?.[1];
|
||||
|
||||
for (const tag of imeta.slice(1)) {
|
||||
if (tag.startsWith('url ')) {
|
||||
url = tag.substring(4);
|
||||
} else if (tag.startsWith('thumb ')) {
|
||||
thumbUrl = tag.substring(6);
|
||||
} else if (tag.startsWith('blurhash ')) {
|
||||
blurhash = tag.substring(9);
|
||||
} else if (tag.startsWith('dim ')) {
|
||||
const dimStr = tag.substring(4);
|
||||
const [width, height] = dimStr.split('x').map(Number);
|
||||
if (width && height) {
|
||||
aspectRatio = width / height;
|
||||
if (width > height) {
|
||||
isLandscape = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (url) {
|
||||
allPhotos.push({
|
||||
eventId: event.id,
|
||||
pubkey: event.pubkey,
|
||||
createdAt: event.created_at,
|
||||
url,
|
||||
thumbUrl,
|
||||
blurhash,
|
||||
isLandscape,
|
||||
aspectRatio,
|
||||
placeIdentifier,
|
||||
tags: eventTagValues,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allPhotos.length === 0) return [];
|
||||
|
||||
// Find the first landscape photo
|
||||
const firstLandscapeIndex = allPhotos.findIndex((p) => p.isLandscape);
|
||||
|
||||
if (firstLandscapeIndex > 0) {
|
||||
// Move the first landscape photo to the front
|
||||
const [firstLandscape] = allPhotos.splice(firstLandscapeIndex, 1);
|
||||
allPhotos.unshift(firstLandscape);
|
||||
}
|
||||
|
||||
return allPhotos;
|
||||
}
|
||||
@@ -27,6 +27,8 @@ export const POI_ICON_RULES = [
|
||||
|
||||
{ tags: { amenity: 'bank' }, icon: 'banknote' },
|
||||
{ tags: { amenity: 'place_of_worship' }, icon: 'place-of-worship-building' },
|
||||
{ tags: { amenity: 'townhall' }, icon: 'classical-building-with-clock' },
|
||||
{ tags: { building: 'townhall' }, icon: 'classical-building-with-clock' },
|
||||
{ tags: { amenity: 'fire_station' }, icon: 'badge-shield-with-fire' },
|
||||
{ tags: { amenity: 'police' }, icon: 'police-officer-with-stop-arm' },
|
||||
{ tags: { amenity: 'toilets' }, icon: 'womens-and-mens-restroom-symbol' },
|
||||
@@ -72,6 +74,7 @@ export const POI_ICON_RULES = [
|
||||
tags: { shop: 'beauty' },
|
||||
icon: 'fancy-mirror-with-reflection-and-stars',
|
||||
},
|
||||
{ tags: { shop: 'car_repair' }, icon: 'car-and-wrench' },
|
||||
{ tags: { craft: 'tailor' }, icon: 'needle-and-spool-of-thread' },
|
||||
{ tags: { office: 'estate_agent' }, icon: 'village-buildings' },
|
||||
{ tags: { office: true }, icon: 'commercial-building' },
|
||||
@@ -103,14 +106,20 @@ export const POI_ICON_RULES = [
|
||||
{ tags: { tourism: 'viewpoint' }, icon: 'camera' },
|
||||
{ tags: { tourism: 'zoo' }, icon: 'camera' },
|
||||
{ tags: { tourism: 'artwork' }, icon: 'camera' },
|
||||
{ tags: { tourism: 'information' }, icon: 'info-i' },
|
||||
{ tags: { amenity: 'cinema' }, icon: 'film' },
|
||||
{ tags: { amenity: 'theatre' }, icon: 'camera' },
|
||||
{ tags: { amenity: 'arts_centre' }, icon: 'comedy-mask-and-tragedy-mask' },
|
||||
{ tags: { amenity: 'arts_center' }, icon: 'comedy-mask-and-tragedy-mask' },
|
||||
|
||||
// Historic
|
||||
{ tags: { historic: 'canal' }, icon: 'winding_way_wide' },
|
||||
{ tags: { historic: 'bridge' }, icon: 'bridge' },
|
||||
{ tags: { historic: 'bridge_site' }, icon: 'bridge' },
|
||||
{ tags: { historic: 'fort' }, icon: 'fort' },
|
||||
{ tags: { historic: 'city_gate' }, icon: 'city-gate' },
|
||||
{ tags: { historic: 'castle' }, icon: 'palace' },
|
||||
{ tags: { building: 'tower', historic: 'yes' }, icon: 'castle-keep' },
|
||||
{ tags: { historic: 'building' }, icon: 'classical-building-with-flag' },
|
||||
{ tags: { historic: 'archaeological_site' }, icon: 'grecian-vase' },
|
||||
{ tags: { historic: 'memorial' }, icon: 'memorial-stone-with-inscription' },
|
||||
@@ -119,6 +128,12 @@ export const POI_ICON_RULES = [
|
||||
tags: { historic: 'monument' },
|
||||
icon: 'classical-building-with-dome-and-flag',
|
||||
},
|
||||
{ tags: { historic: 'folly' }, icon: 'classical-building' },
|
||||
{ tags: { historic: 'industrial' }, icon: 'industrial-building' },
|
||||
{
|
||||
tags: { historic: 'railway_station' },
|
||||
icon: 'steam-train-on-railway-track',
|
||||
},
|
||||
{ tags: { historic: 'ship' }, icon: 'sailing-ship-in-water' },
|
||||
{ tags: { historic: 'wreck' }, icon: 'shipwreck-in-water' },
|
||||
{ tags: { historic: 'ruins' }, icon: 'camera' },
|
||||
|
||||
+10
-1
@@ -56,15 +56,24 @@ const PLACE_TYPE_KEYS = [
|
||||
export function getPlaceType(tags) {
|
||||
if (!tags) return null;
|
||||
|
||||
let fallbackKey = null;
|
||||
|
||||
for (const key of PLACE_TYPE_KEYS) {
|
||||
const value = tags[key];
|
||||
if (value) {
|
||||
if (value === 'yes') {
|
||||
return humanizeOsmTag(key);
|
||||
if (!fallbackKey) {
|
||||
fallbackKey = key;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return humanizeOsmTag(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (fallbackKey) {
|
||||
return humanizeOsmTag(fallbackKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { POI_CATEGORIES } from './poi-categories';
|
||||
import { getMatchingPoiCategoryIds } from './poi-category-matcher';
|
||||
|
||||
export const CATEGORY_TAGS = {
|
||||
restaurants: ['food', 'menu', 'vibe', 'front'],
|
||||
coffee: ['food', 'menu', 'vibe', 'front'],
|
||||
groceries: ['front', 'food'],
|
||||
'things-to-do': ['architecture', 'amenities', 'vibe', 'front'],
|
||||
accommodation: ['rooms', 'amenities', 'food', 'vibe', 'front'],
|
||||
};
|
||||
|
||||
export function getSuggestedPhotoTags(place) {
|
||||
const osmTags = place?.osmTags || place?.tags || {};
|
||||
const categoryIds = getMatchingPoiCategoryIds(osmTags, POI_CATEGORIES);
|
||||
|
||||
const suggested = [];
|
||||
for (const categoryId of categoryIds) {
|
||||
const tags = CATEGORY_TAGS[categoryId];
|
||||
if (!Array.isArray(tags)) continue;
|
||||
for (const tag of tags) {
|
||||
if (!suggested.includes(tag)) {
|
||||
suggested.push(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (suggested.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return suggested;
|
||||
}
|
||||
@@ -41,9 +41,9 @@ export const POI_CATEGORIES = [
|
||||
{
|
||||
id: 'things-to-do',
|
||||
label: 'Things to do',
|
||||
icon: 'camera',
|
||||
icon: 'feather-camera',
|
||||
filter: [
|
||||
'["tourism"~"^(museum|gallery|attraction|viewpoint|zoo|theme_park|aquarium|artwork)$"]',
|
||||
'["tourism"~"^(museum|gallery|attraction|viewpoint|zoo|theme_park|aquarium|artwork|information)$"]',
|
||||
'["amenity"~"^(cinema|theatre|arts_centre|planetarium)$"]',
|
||||
'["leisure"~"^(sports_centre|stadium|water_park)$"]',
|
||||
'["historic"]',
|
||||
@@ -55,7 +55,7 @@ export const POI_CATEGORIES = [
|
||||
id: 'accommodation',
|
||||
label: 'Hotels',
|
||||
icon: 'person-sleeping-in-bed',
|
||||
filter: ['["tourism"~"^(hotel|hostel|motel)$"]'],
|
||||
filter: ['["tourism"~"^(hotel|hostel|motel|chalet|guest_house)$"]'],
|
||||
types: ['node', 'way', 'relation'],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
export function getMatchingPoiCategories(osmTags, categories) {
|
||||
if (!Array.isArray(categories) || !osmTags) return [];
|
||||
|
||||
return categories.filter((category) => {
|
||||
if (!Array.isArray(category.filter)) return false;
|
||||
return category.filter.some((filterStr) =>
|
||||
matchesFilter(osmTags, filterStr)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function getMatchingPoiCategoryIds(osmTags, categories) {
|
||||
return getMatchingPoiCategories(osmTags, categories).map((c) => c.id);
|
||||
}
|
||||
|
||||
function matchesFilter(osmTags, filterStr) {
|
||||
const clauses = parseOverpassClauses(filterStr);
|
||||
if (clauses.length === 0) return false;
|
||||
return clauses.every((clause) => matchesClause(osmTags, clause));
|
||||
}
|
||||
|
||||
function parseOverpassClauses(filterStr) {
|
||||
if (!filterStr) return [];
|
||||
const matches = filterStr.match(/\[[^\]]+\]/g);
|
||||
if (!matches) return [];
|
||||
|
||||
return matches
|
||||
.map((raw) => parseClause(raw.slice(1, -1).trim()))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function parseClause(content) {
|
||||
const presenceMatch = content.match(/^"([^"]+)"$/);
|
||||
if (presenceMatch) {
|
||||
return { type: 'presence', key: presenceMatch[1] };
|
||||
}
|
||||
|
||||
const equalsMatch = content.match(/^"([^"]+)"\s*=\s*"([^"]*)"$/);
|
||||
if (equalsMatch) {
|
||||
return { type: 'equals', key: equalsMatch[1], value: equalsMatch[2] };
|
||||
}
|
||||
|
||||
const regexMatch = content.match(/^"([^"]+)"\s*~\s*"([^"]*)"$/);
|
||||
if (regexMatch) {
|
||||
return {
|
||||
type: 'regex',
|
||||
key: regexMatch[1],
|
||||
pattern: regexMatch[2],
|
||||
regex: new RegExp(regexMatch[2]),
|
||||
};
|
||||
}
|
||||
|
||||
const notRegexMatch = content.match(/^"([^"]+)"\s*!~\s*"([^"]*)"$/);
|
||||
if (notRegexMatch) {
|
||||
return {
|
||||
type: 'not-regex',
|
||||
key: notRegexMatch[1],
|
||||
pattern: notRegexMatch[2],
|
||||
regex: new RegExp(notRegexMatch[2]),
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function matchesClause(osmTags, clause) {
|
||||
const tagValues = getTagValues(osmTags, clause.key);
|
||||
|
||||
switch (clause.type) {
|
||||
case 'presence':
|
||||
return tagValues.length > 0;
|
||||
case 'equals':
|
||||
return tagValues.some((value) => value === clause.value);
|
||||
case 'regex':
|
||||
return tagValues.some((value) => clause.regex.test(value));
|
||||
case 'not-regex':
|
||||
return (
|
||||
tagValues.length === 0 ||
|
||||
!tagValues.some((value) => clause.regex.test(value))
|
||||
);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getTagValues(osmTags, key) {
|
||||
if (!osmTags || !key) return [];
|
||||
const rawValue = osmTags[key];
|
||||
if (rawValue === undefined || rawValue === null) return [];
|
||||
|
||||
return String(rawValue)
|
||||
.split(';')
|
||||
.map((value) => value.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import { encode } from 'blurhash';
|
||||
|
||||
self.onmessage = async (e) => {
|
||||
// Ignore internal browser/Vite/extension pings that don't match our exact job signature
|
||||
if (e.data?.type !== 'PROCESS_IMAGE') return;
|
||||
|
||||
const { id, file, targetWidth, targetHeight, quality, computeBlurhash } =
|
||||
e.data;
|
||||
|
||||
try {
|
||||
let finalCanvas;
|
||||
let finalCtx;
|
||||
|
||||
// --- 1. Attempt Hardware Resizing (Happy Path) ---
|
||||
try {
|
||||
const resizedBitmap = await createImageBitmap(file, {
|
||||
resizeWidth: targetWidth,
|
||||
resizeHeight: targetHeight,
|
||||
resizeQuality: 'high',
|
||||
});
|
||||
|
||||
finalCanvas = new OffscreenCanvas(targetWidth, targetHeight);
|
||||
finalCtx = finalCanvas.getContext('2d');
|
||||
if (!finalCtx) {
|
||||
throw new Error('Failed to get 2d context from OffscreenCanvas');
|
||||
}
|
||||
finalCtx.drawImage(resizedBitmap, 0, 0, targetWidth, targetHeight);
|
||||
resizedBitmap.close();
|
||||
} catch (hwError) {
|
||||
console.warn(
|
||||
'Hardware resize failed, falling back to stepped software scaling:',
|
||||
hwError
|
||||
);
|
||||
|
||||
// --- 2. Fallback to Stepped Software Scaling (Robust Path) ---
|
||||
// Bypass Android File descriptor bug by reading into memory
|
||||
const buffer = await file.arrayBuffer();
|
||||
const blob = new Blob([buffer], { type: file.type });
|
||||
|
||||
const source = await createImageBitmap(blob);
|
||||
let srcWidth = source.width;
|
||||
let srcHeight = source.height;
|
||||
|
||||
let currentCanvas = new OffscreenCanvas(srcWidth, srcHeight);
|
||||
let ctx = currentCanvas.getContext('2d');
|
||||
|
||||
ctx.imageSmoothingEnabled = true;
|
||||
ctx.imageSmoothingQuality = 'high';
|
||||
ctx.drawImage(source, 0, 0);
|
||||
|
||||
// Step down by halves until near target
|
||||
while (
|
||||
currentCanvas.width * 0.5 > targetWidth &&
|
||||
currentCanvas.height * 0.5 > targetHeight
|
||||
) {
|
||||
const nextCanvas = new OffscreenCanvas(
|
||||
Math.floor(currentCanvas.width * 0.5),
|
||||
Math.floor(currentCanvas.height * 0.5)
|
||||
);
|
||||
const nextCtx = nextCanvas.getContext('2d');
|
||||
|
||||
nextCtx.imageSmoothingEnabled = true;
|
||||
nextCtx.imageSmoothingQuality = 'high';
|
||||
|
||||
nextCtx.drawImage(
|
||||
currentCanvas,
|
||||
0,
|
||||
0,
|
||||
nextCanvas.width,
|
||||
nextCanvas.height
|
||||
);
|
||||
|
||||
currentCanvas = nextCanvas;
|
||||
}
|
||||
|
||||
// Final resize to exact target
|
||||
finalCanvas = new OffscreenCanvas(targetWidth, targetHeight);
|
||||
finalCtx = finalCanvas.getContext('2d');
|
||||
|
||||
finalCtx.imageSmoothingEnabled = true;
|
||||
finalCtx.imageSmoothingQuality = 'high';
|
||||
|
||||
finalCtx.drawImage(currentCanvas, 0, 0, targetWidth, targetHeight);
|
||||
|
||||
source.close();
|
||||
}
|
||||
|
||||
// --- 3. Generate Blurhash (if requested) ---
|
||||
let blurhash = null;
|
||||
if (computeBlurhash) {
|
||||
try {
|
||||
const imageData = finalCtx.getImageData(
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight
|
||||
);
|
||||
blurhash = encode(imageData.data, targetWidth, targetHeight, 4, 3);
|
||||
} catch (blurhashError) {
|
||||
console.warn(
|
||||
'Could not generate blurhash (possible canvas fingerprinting protection):',
|
||||
blurhashError
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --- 4. Compress to JPEG Blob ---
|
||||
const finalBlob = await finalCanvas.convertToBlob({
|
||||
type: 'image/jpeg',
|
||||
quality: quality,
|
||||
});
|
||||
|
||||
const dim = `${targetWidth}x${targetHeight}`;
|
||||
|
||||
// --- 5. Send results back to main thread ---
|
||||
self.postMessage({
|
||||
id,
|
||||
success: true,
|
||||
blob: finalBlob,
|
||||
dim,
|
||||
blurhash,
|
||||
});
|
||||
} catch (error) {
|
||||
self.postMessage({
|
||||
id,
|
||||
success: false,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -14,7 +14,7 @@ While NIP-68 (Picture-first feeds) caters to general visual feeds, this NIP spec
|
||||
|
||||
## Content
|
||||
|
||||
The `.content` of the event SHOULD generally be empty. If a user wishes to provide a detailed description, summary, or caption for a place, clients SHOULD encourage them to create a Place Review event (`kind: 30360`) instead.
|
||||
The `.content` of the event SHOULD generally be empty. If a user wishes to provide a detailed description for a place, clients SHOULD encourage them to create a Place Review event (`kind: 30360`) instead.
|
||||
|
||||
## Tags
|
||||
|
||||
@@ -45,17 +45,19 @@ Used for spatial indexing and discovery. Events MUST include at least one high-p
|
||||
|
||||
#### 3. `imeta` — Inline Media Metadata
|
||||
|
||||
Media files MUST be attached using the `imeta` tag as defined in NIP-92. Each `imeta` tag represents one media item. The primary `url` SHOULD also be appended to the event's `.content` for backwards compatibility with clients that do not parse `imeta` tags.
|
||||
An event MUST contain exactly one `imeta` tag representing a single media item. The primary `url` MAY also be appended to the event's `.content` for backwards compatibility with clients that do not parse `imeta` tags.
|
||||
|
||||
Clients SHOULD include `alt` (accessibility descriptions), `dim` (dimensions), `m` (MIME type), and `blurhash` where possible.
|
||||
Clients SHOULD include `alt` (accessibility descriptions), `dim` (dimensions), `m` (MIME type), `thumb` (URL to a smaller thumbnail image), and `blurhash` where possible. Clients MAY also include `fallback` URLs if the media is hosted on multiple servers.
|
||||
|
||||
```json
|
||||
[
|
||||
"imeta",
|
||||
"url https://example.com/photo.jpg",
|
||||
"url https://blossom.example.com/8e2e28a503fa37482de5b0959ee38b2bb4de4e0a752db24c568981c2ab410260.jpg",
|
||||
"m image/jpeg",
|
||||
"dim 3024x4032",
|
||||
"dim 1440x1920",
|
||||
"alt A steaming bowl of ramen on a wooden table at the restaurant.",
|
||||
"fallback https://mirror.example.com/8e2e28a503fa37482de5b0959ee38b2bb4de4e0a752db24c568981c2ab410260.jpg",
|
||||
"thumb https://example.com/7a1f592f6ea8e932b1de9568285b01851e4cf708466b0a03010b91e92c6c8135.jpg",
|
||||
"blurhash eVF$^OI:${M{o#*0-nNFxakD-?xVM}WEWB%iNKxvR-oetmo#R-aen$"
|
||||
]
|
||||
```
|
||||
@@ -83,10 +85,12 @@ Clients SHOULD include `alt` (accessibility descriptions), `dim` (dimensions), `
|
||||
|
||||
[
|
||||
"imeta",
|
||||
"url https://example.com/ramen.jpg",
|
||||
"url https://blossom.example.com/a9c84e183789a74288b8e05d04cc61230e74f386925a953e6b29f957e8cc3a61.jpg",
|
||||
"m image/jpeg",
|
||||
"dim 1080x1080",
|
||||
"dim 1920x1920",
|
||||
"alt A close-up of spicy miso ramen with chashu pork, soft boiled egg, and scallions.",
|
||||
"fallback https://mirror.example.com/a9c84e183789a74288b8e05d04cc61230e74f386925a953e6b29f957e8cc3a61.jpg",
|
||||
"thumb https://example.com/c5a528e20235e16cc1c18090b8f04179de76288ea4e410b0fcb8d1487e416a2d.jpg",
|
||||
"blurhash UHI=0o~q4T-o~q%MozM{x]t7RjRPt7oKkCWB"
|
||||
],
|
||||
|
||||
@@ -98,6 +102,10 @@ Clients SHOULD include `alt` (accessibility descriptions), `dim` (dimensions), `
|
||||
|
||||
## Rationale
|
||||
|
||||
### Kind 360
|
||||
|
||||
Easy to remember as a 360-degree view of places.
|
||||
|
||||
### Why not use NIP-68 (Picture-first feeds)?
|
||||
|
||||
NIP-68 is designed for general-purpose social feeds (like Instagram). Place photos require strict guarantees about what entity is being depicted to be useful for map clients, directories, and review aggregators. By mandating the `i` tag for POI linking and the `g` tag for spatial querying, this kind ensures interoperability for geo-spatial applications without cluttering general picture feeds with mundane POI images (like photos of storefronts or menus).
|
||||
@@ -105,3 +113,7 @@ NIP-68 is designed for general-purpose social feeds (like Instagram). Place phot
|
||||
### Separation from Place Reviews
|
||||
|
||||
Reviews (kind 30360) and media have different lifecycles and data models. A user might upload 10 photos of a park without writing a review, or write a detailed review without attaching photos. Keeping them as separate events allows clients to query `imeta` attachments for a specific `i` tag to quickly build a photo gallery for a place, regardless of whether a review was attached.
|
||||
|
||||
### Single Photo per Event
|
||||
|
||||
Restricting events to a single `imeta` attachment (one photo per event) is an intentional design choice. Batching photos into a single event forces all engagement (likes, zaps) to apply to the entire batch, rendering granular tagging and sorting impossible. Single-photo events enable per-photo engagement, fine-grained categorization (e.g., tagging one photo as "food" and another as "menu"), and richer sorting algorithms based on individual photo popularity.
|
||||
|
||||
@@ -276,6 +276,10 @@ Content payloads SHOULD NOT include place identifiers.
|
||||
|
||||
## Rationale
|
||||
|
||||
### Kind 30360
|
||||
|
||||
Pairs with kind 360 (Place Photos). Easy to remember as a 360-degree review of all aspects of a place.
|
||||
|
||||
### No Place Field in Content
|
||||
|
||||
Avoids duplication and inconsistency with tags.
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<link rel="stylesheet" href="/app/styles/app.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="modal-portal"></div>
|
||||
<script type="module">
|
||||
import Application from './app/app';
|
||||
import environment from './app/config/environment';
|
||||
|
||||
+6
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "marco",
|
||||
"version": "1.19.1",
|
||||
"version": "1.25.0",
|
||||
"private": true,
|
||||
"description": "Unhosted maps app",
|
||||
"repository": {
|
||||
@@ -52,7 +52,7 @@
|
||||
"@embroider/vite": "^1.5.0",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@glimmer/component": "^2.0.0",
|
||||
"@remotestorage/module-places": "~1.2.1",
|
||||
"@remotestorage/module-places": "~1.3.0",
|
||||
"@rollup/plugin-babel": "^6.1.0",
|
||||
"@warp-drive/core": "~5.8.0",
|
||||
"@warp-drive/ember": "~5.8.0",
|
||||
@@ -88,7 +88,7 @@
|
||||
"qunit": "^2.25.0",
|
||||
"qunit-dom": "^3.5.0",
|
||||
"remotestorage-widget": "^1.8.1",
|
||||
"remotestoragejs": "2.0.0-beta.8",
|
||||
"remotestoragejs": "2.0.0-beta.9",
|
||||
"sinon": "^21.0.1",
|
||||
"stylelint": "^16.26.1",
|
||||
"stylelint-config-standard": "^38.0.0",
|
||||
@@ -102,13 +102,16 @@
|
||||
"edition": "octane"
|
||||
},
|
||||
"dependencies": {
|
||||
"@noble/hashes": "^2.2.0",
|
||||
"@waysidemapping/pinhead": "^15.20.0",
|
||||
"applesauce-core": "^5.2.0",
|
||||
"applesauce-factory": "^4.0.0",
|
||||
"applesauce-relay": "^5.2.0",
|
||||
"applesauce-signers": "^5.2.0",
|
||||
"blurhash": "^2.0.5",
|
||||
"ember-concurrency": "^5.2.0",
|
||||
"ember-lifeline": "^7.0.0",
|
||||
"nostr-idb": "^5.0.0",
|
||||
"oauth2-pkce": "^2.1.3",
|
||||
"qrcode": "^1.5.4",
|
||||
"rxjs": "^7.8.2"
|
||||
|
||||
Generated
+45
-35
@@ -8,6 +8,9 @@ importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
'@noble/hashes':
|
||||
specifier: ^2.2.0
|
||||
version: 2.2.0
|
||||
'@waysidemapping/pinhead':
|
||||
specifier: ^15.20.0
|
||||
version: 15.20.0
|
||||
@@ -23,12 +26,18 @@ importers:
|
||||
applesauce-signers:
|
||||
specifier: ^5.2.0
|
||||
version: 5.2.0(@capacitor/core@7.6.2)(typescript@5.9.3)
|
||||
blurhash:
|
||||
specifier: ^2.0.5
|
||||
version: 2.0.5
|
||||
ember-concurrency:
|
||||
specifier: ^5.2.0
|
||||
version: 5.2.0(@babel/core@7.28.6)
|
||||
ember-lifeline:
|
||||
specifier: ^7.0.0
|
||||
version: 7.0.0(@ember/test-helpers@5.4.1(@babel/core@7.28.6))
|
||||
nostr-idb:
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.0
|
||||
oauth2-pkce:
|
||||
specifier: ^2.1.3
|
||||
version: 2.1.3
|
||||
@@ -79,8 +88,8 @@ importers:
|
||||
specifier: ^2.0.0
|
||||
version: 2.0.0
|
||||
'@remotestorage/module-places':
|
||||
specifier: ~1.2.1
|
||||
version: 1.2.1
|
||||
specifier: ~1.3.0
|
||||
version: 1.3.0
|
||||
'@rollup/plugin-babel':
|
||||
specifier: ^6.1.0
|
||||
version: 6.1.0(@babel/core@7.28.6)(rollup@4.55.1)
|
||||
@@ -187,8 +196,8 @@ importers:
|
||||
specifier: ^1.8.1
|
||||
version: 1.8.1
|
||||
remotestoragejs:
|
||||
specifier: 2.0.0-beta.8
|
||||
version: 2.0.0-beta.8
|
||||
specifier: 2.0.0-beta.9
|
||||
version: 2.0.0-beta.9
|
||||
sinon:
|
||||
specifier: ^21.0.1
|
||||
version: 21.0.1
|
||||
@@ -1459,8 +1468,8 @@ packages:
|
||||
resolution: {integrity: sha512-4rdu8GPY9TeQwsYp5D2My74dC3dSVS3tghAvisG80ybK4lqa0gvlrglaSTBxogJbxqHRw/NjI/liEtb3+SD+Bw==}
|
||||
engines: {node: '>=18.12'}
|
||||
|
||||
'@remotestorage/module-places@1.2.1':
|
||||
resolution: {integrity: sha512-hNRuhGoG8RS+cieVvDVzXWBEuNPfyeFirhgNH3z1WoKw9ngHdPY6V0sT0vKbsxB8xaODReZfo2ZKHLTmdFunlw==}
|
||||
'@remotestorage/module-places@1.3.0':
|
||||
resolution: {integrity: sha512-VM0CqkIP6IBEpjqJ2DyTrGDOQXc73aXoAFDLIoME5Lo033uTitgn+qKgTGPK/lD4H92mk1+D3W88ECtf9v3mWw==}
|
||||
|
||||
'@rollup/plugin-babel@6.1.0':
|
||||
resolution: {integrity: sha512-dFZNuFD2YRcoomP4oYf+DvQNSUA9ih+A3vUqopQx5EdtPGo3WBnQcI/S8pwpz91UsGfL0HsMSOlaMld8HrbubA==}
|
||||
@@ -1711,9 +1720,6 @@ packages:
|
||||
'@types/ms@2.1.0':
|
||||
resolution: {integrity: sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==}
|
||||
|
||||
'@types/node@20.14.0':
|
||||
resolution: {integrity: sha512-5cHBxFGJx6L4s56Bubp4fglrEpmyJypsqI6RgzMfBHWUJQGWAAi8cWcgetEbZXHYXo9C2Fa4EEds/uSyS4cxmA==}
|
||||
|
||||
'@types/node@25.0.7':
|
||||
resolution: {integrity: sha512-C/er7DlIZgRJO7WtTdYovjIFzGsz0I95UlMyR9anTb4aCpBSRWe5Jc1/RvLKUfzmOxHPGjSE5+63HgLtndxU4w==}
|
||||
|
||||
@@ -1726,9 +1732,6 @@ packages:
|
||||
'@types/symlink-or-copy@1.2.2':
|
||||
resolution: {integrity: sha512-MQ1AnmTLOncwEf9IVU+B2e4Hchrku5N67NkgcAHW0p3sdzPe0FNMANxEm6OJUzPniEQGkeT3OROLlCwZJLWFZA==}
|
||||
|
||||
'@types/tv4@1.2.33':
|
||||
resolution: {integrity: sha512-7phCVTXC6Bj50IV1iKOwqGkR4JONJyMbRZnKTSuujv1S/tO9rG5OdCt7BMSjytO+zJmYdn1/I4fd3SH0gtO99g==}
|
||||
|
||||
'@types/unist@3.0.3':
|
||||
resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==}
|
||||
|
||||
@@ -2044,6 +2047,9 @@ packages:
|
||||
bluebird@3.7.2:
|
||||
resolution: {integrity: sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==}
|
||||
|
||||
blurhash@2.0.5:
|
||||
resolution: {integrity: sha512-cRygWd7kGBQO3VEhPiTgq4Wc43ctsM+o46urrmPOiuAe+07fzlSB9OJVdpgDL0jPqXUVQ9ht7aq7kxOeJHRK+w==}
|
||||
|
||||
body-parser@1.20.4:
|
||||
resolution: {integrity: sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==}
|
||||
engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16}
|
||||
@@ -3700,6 +3706,9 @@ packages:
|
||||
resolution: {integrity: sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
idb@8.0.3:
|
||||
resolution: {integrity: sha512-LtwtVyVYO5BqRvcsKuB2iUMnHwPVByPCXFXOpuU96IZPPoPN6xjOGxZQ74pgSVVLQWtUOYgyeL4GE98BY5D3wg==}
|
||||
|
||||
ignore@5.3.2:
|
||||
resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==}
|
||||
engines: {node: '>= 4'}
|
||||
@@ -4396,6 +4405,9 @@ packages:
|
||||
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
nostr-idb@5.0.0:
|
||||
resolution: {integrity: sha512-w5y4AnHefZIwCCL11NryfM2xp3U0Ka4qVNQEYAjnQbPwyoV+bZTdwuPXHCdRDWvhOFP2bZr1WBegcsAmkBjrxQ==}
|
||||
|
||||
nostr-signer-capacitor-plugin@0.0.5:
|
||||
resolution: {integrity: sha512-/EvqWz71HZ5cWmzvfXWTm48AWZtbeZDbOg3vLwXyXPjnIp1DR7Wurww/Mo41ORNu1DNPlqH20l7kIXKO6vR5og==}
|
||||
peerDependencies:
|
||||
@@ -4888,8 +4900,8 @@ packages:
|
||||
remotestorage-widget@1.8.1:
|
||||
resolution: {integrity: sha512-HxNu2VvIRW3wzkf5fLEzs56ySQ7+YQbRqyp3CKvmw/G+zKhRsmj06HtFoAcm3B14/nJh2SOAv3LyfKuXfUsKPw==}
|
||||
|
||||
remotestoragejs@2.0.0-beta.8:
|
||||
resolution: {integrity: sha512-rtyHTG2VbtiKTRmbwjponRf5VTPJMcHv/ijNid1zX48C0Z0F8ZCBBfkKD2QCxTQyQvCupkWNy3wuIu4HE+AEng==}
|
||||
remotestoragejs@2.0.0-beta.9:
|
||||
resolution: {integrity: sha512-d09ByL7ecbZLMuzl4mQ3SXMFlsCwvvINm6l1CfdR8ylvX9E1nsq44t8gmRxzW6GUS5cwonyYA4FRXYKEhARjTA==}
|
||||
|
||||
remove-types@1.0.0:
|
||||
resolution: {integrity: sha512-G7Hk1Q+UJ5DvlNAoJZObxANkBZGiGdp589rVcTW/tYqJWJ5rwfraSnKSQaETN8Epaytw8J40nS/zC7bcHGv36w==}
|
||||
@@ -5560,9 +5572,6 @@ packages:
|
||||
underscore@1.13.7:
|
||||
resolution: {integrity: sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==}
|
||||
|
||||
undici-types@5.26.5:
|
||||
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
|
||||
|
||||
undici-types@7.16.0:
|
||||
resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==}
|
||||
|
||||
@@ -5729,8 +5738,8 @@ packages:
|
||||
web-worker@1.5.0:
|
||||
resolution: {integrity: sha512-RiMReJrTAiA+mBjGONMnjVDP2u3p9R1vkcGz6gDIrOMT3oGuYwX2WRMYI9ipkphSuE5XKEhydbhNEJh4NY9mlw==}
|
||||
|
||||
webfinger.js@2.8.2:
|
||||
resolution: {integrity: sha512-Zqn9KXkGrD1tVEm029bVUIfmzef2KXs3G7OZrdqehDHtgv9YSxX1oy4RoPoMk2PHWIifwWCA0xwKZOAZqXMpfg==}
|
||||
webfinger.js@3.0.4:
|
||||
resolution: {integrity: sha512-5c15N1n4qCm/jGJjUt32mBdPVlSugLbAztIDNBpuDfukGz2E9NhmXPfLikayn2p3kcgEZsI/UOdOwVpxOr8qJA==}
|
||||
|
||||
webidl-conversions@7.0.0:
|
||||
resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==}
|
||||
@@ -7430,7 +7439,7 @@ snapshots:
|
||||
'@pnpm/error': 1000.0.5
|
||||
find-up: 5.0.0
|
||||
|
||||
'@remotestorage/module-places@1.2.1':
|
||||
'@remotestorage/module-places@1.3.0':
|
||||
dependencies:
|
||||
latlon-geohash: 2.0.0
|
||||
ulid: 3.0.2
|
||||
@@ -7537,7 +7546,7 @@ snapshots:
|
||||
'@scure/bip32@1.3.1':
|
||||
dependencies:
|
||||
'@noble/curves': 1.1.0
|
||||
'@noble/hashes': 1.3.1
|
||||
'@noble/hashes': 1.3.2
|
||||
'@scure/base': 1.1.1
|
||||
|
||||
'@scure/bip32@1.7.0':
|
||||
@@ -7554,7 +7563,7 @@ snapshots:
|
||||
|
||||
'@scure/bip39@1.2.1':
|
||||
dependencies:
|
||||
'@noble/hashes': 1.3.1
|
||||
'@noble/hashes': 1.3.2
|
||||
'@scure/base': 1.1.1
|
||||
|
||||
'@scure/bip39@2.0.1':
|
||||
@@ -7630,10 +7639,6 @@ snapshots:
|
||||
|
||||
'@types/ms@2.1.0': {}
|
||||
|
||||
'@types/node@20.14.0':
|
||||
dependencies:
|
||||
undici-types: 5.26.5
|
||||
|
||||
'@types/node@25.0.7':
|
||||
dependencies:
|
||||
undici-types: 7.16.0
|
||||
@@ -7647,8 +7652,6 @@ snapshots:
|
||||
|
||||
'@types/symlink-or-copy@1.2.2': {}
|
||||
|
||||
'@types/tv4@1.2.33': {}
|
||||
|
||||
'@types/unist@3.0.3': {}
|
||||
|
||||
'@typescript-eslint/tsconfig-utils@8.53.0(typescript@5.9.3)':
|
||||
@@ -8053,6 +8056,8 @@ snapshots:
|
||||
|
||||
bluebird@3.7.2: {}
|
||||
|
||||
blurhash@2.0.5: {}
|
||||
|
||||
body-parser@1.20.4:
|
||||
dependencies:
|
||||
bytes: 3.1.2
|
||||
@@ -10275,6 +10280,8 @@ snapshots:
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
|
||||
idb@8.0.3: {}
|
||||
|
||||
ignore@5.3.2: {}
|
||||
|
||||
ignore@7.0.5: {}
|
||||
@@ -11010,6 +11017,13 @@ snapshots:
|
||||
|
||||
normalize-path@3.0.0: {}
|
||||
|
||||
nostr-idb@5.0.0:
|
||||
dependencies:
|
||||
debug: 4.4.3
|
||||
idb: 8.0.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
nostr-signer-capacitor-plugin@0.0.5(@capacitor/core@7.6.2):
|
||||
dependencies:
|
||||
'@capacitor/core': 7.6.2
|
||||
@@ -11501,13 +11515,11 @@ snapshots:
|
||||
|
||||
remotestorage-widget@1.8.1: {}
|
||||
|
||||
remotestoragejs@2.0.0-beta.8:
|
||||
remotestoragejs@2.0.0-beta.9:
|
||||
dependencies:
|
||||
'@types/node': 20.14.0
|
||||
'@types/tv4': 1.2.33
|
||||
esm: 3.2.25
|
||||
tv4: 1.3.0
|
||||
webfinger.js: 2.8.2
|
||||
webfinger.js: 3.0.4
|
||||
xhr2: 0.2.1
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.3
|
||||
@@ -12387,8 +12399,6 @@ snapshots:
|
||||
|
||||
underscore@1.13.7: {}
|
||||
|
||||
undici-types@5.26.5: {}
|
||||
|
||||
undici-types@7.16.0: {}
|
||||
|
||||
unicode-canonical-property-names-ecmascript@2.0.1: {}
|
||||
@@ -12540,7 +12550,7 @@ snapshots:
|
||||
|
||||
web-worker@1.5.0: {}
|
||||
|
||||
webfinger.js@2.8.2: {}
|
||||
webfinger.js@3.0.4: {}
|
||||
|
||||
webidl-conversions@7.0.0: {}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
!function(){"use strict";var t=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],e=(e,a)=>{var o="";for(let r=1;r<=a;r++){let h=Math.floor(e)/Math.pow(83,a-r)%83;o+=t[Math.floor(h)]}return o},a=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},o=t=>{let e=Math.max(0,Math.min(1,t));return e<=.0031308?Math.trunc(12.92*e*255+.5):Math.trunc(255*(1.055*Math.pow(e,.4166666666666667)-.055)+.5)},r=(t,e)=>(t=>t<0?-1:1)(t)*Math.pow(Math.abs(t),e),h=class extends Error{constructor(t){super(t),this.name="ValidationError",this.message=t}},i=(t,e,o,r)=>{let h=0,i=0,n=0,s=4*e;for(let g=0;g<e;g++){let e=4*g;for(let l=0;l<o;l++){let o=e+l*s,c=r(g,l);h+=c*a(t[o]),i+=c*a(t[o+1]),n+=c*a(t[o+2])}}let l=1/(e*o);return[h*l,i*l,n*l]};self.onmessage=async t=>{if("PROCESS_IMAGE"!==t.data?.type)return;const{id:a,file:n,targetWidth:s,targetHeight:l,quality:g,computeBlurhash:c}=t.data;try{let t,M;try{const e=await createImageBitmap(n,{resizeWidth:s,resizeHeight:l,resizeQuality:"high"});if(t=new OffscreenCanvas(s,l),M=t.getContext("2d"),!M)throw new Error("Failed to get 2d context from OffscreenCanvas");M.drawImage(e,0,0,s,l),e.close()}catch(f){console.warn("Hardware resize failed, falling back to stepped software scaling:",f);const e=await n.arrayBuffer(),a=new Blob([e],{type:n.type}),o=await createImageBitmap(a);let r=o.width,h=o.height,i=new OffscreenCanvas(r,h),g=i.getContext("2d");for(g.imageSmoothingEnabled=!0,g.imageSmoothingQuality="high",g.drawImage(o,0,0);.5*i.width>s&&.5*i.height>l;){const t=new OffscreenCanvas(Math.floor(.5*i.width),Math.floor(.5*i.height)),e=t.getContext("2d");e.imageSmoothingEnabled=!0,e.imageSmoothingQuality="high",e.drawImage(i,0,0,t.width,t.height),i=t}t=new OffscreenCanvas(s,l),M=t.getContext("2d"),M.imageSmoothingEnabled=!0,M.imageSmoothingQuality="high",M.drawImage(i,0,0,s,l),o.close()}let d=null;if(c)try{d=((t,a,n)=>{if(a*n*4!==t.length)throw new h("Width and height must match the pixels array");let s=[];for(let e=0;e<3;e++)for(let o=0;o<4;o++){let r=0==o&&0==e?1:2,h=i(t,a,n,(t,h)=>r*Math.cos(Math.PI*o*t/a)*Math.cos(Math.PI*e*h/n));s.push(h)}let l,g=s[0],c=s.slice(1),f="";if(f+=e(21,1),c.length>0){let t=Math.max(...c.map(t=>Math.max(...t))),a=Math.floor(Math.max(0,Math.min(82,Math.floor(166*t-.5))));l=(a+1)/166,f+=e(a,1)}else l=1,f+=e(0,1);return f+=e((t=>(o(t[0])<<16)+(o(t[1])<<8)+o(t[2]))(g),4),c.forEach(t=>{f+=e(((t,e)=>19*Math.floor(Math.max(0,Math.min(18,Math.floor(9*r(t[0]/e,.5)+9.5))))*19+19*Math.floor(Math.max(0,Math.min(18,Math.floor(9*r(t[1]/e,.5)+9.5))))+Math.floor(Math.max(0,Math.min(18,Math.floor(9*r(t[2]/e,.5)+9.5)))))(t,l),2)}),f})(M.getImageData(0,0,s,l).data,s,l)}catch(m){console.warn("Could not generate blurhash (possible canvas fingerprinting protection):",m)}const u=await t.convertToBlob({type:"image/jpeg",quality:g}),w=`${s}x${l}`;self.postMessage({id:a,success:!0,blob:u,dim:w,blurhash:d})}catch(M){self.postMessage({id:a,success:!1,error:M.message})}}}();
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3
-2
@@ -39,9 +39,10 @@
|
||||
<meta name="msapplication-TileColor" content="#F6E9A6">
|
||||
<meta name="msapplication-TileImage" content="/icons/icon-144.png">
|
||||
|
||||
<script type="module" crossorigin src="/assets/main-BVEi_-zb.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/main-BF2Ls-fG.css">
|
||||
<script type="module" crossorigin src="/assets/main-BVNM87jL.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/main-BGF-Udec.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="modal-portal"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click, waitFor } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'marco/tests/helpers';
|
||||
import Service from '@ember/service';
|
||||
|
||||
class MockOsmService extends Service {
|
||||
async fetchOsmObject() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class MockStorageService extends Service {
|
||||
initialSyncDone = true;
|
||||
savedPlaces = [
|
||||
{
|
||||
id: 'place-123',
|
||||
title: 'Mountain Trail',
|
||||
geohash: 'u33dc0',
|
||||
osmTags: { name: 'Mountain Trail' },
|
||||
},
|
||||
];
|
||||
lists = [
|
||||
{
|
||||
id: 'to-go',
|
||||
title: 'Want to go',
|
||||
color: '#2e9e4f',
|
||||
placeRefs: [{ id: 'place-123', geohash: 'u33dc0' }],
|
||||
},
|
||||
{ id: 'to-do', title: 'To do', color: '#2a7fff', placeRefs: [] },
|
||||
];
|
||||
|
||||
findPlaceById(id) {
|
||||
if (id === 'place-123') {
|
||||
return this.savedPlaces[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
isPlaceSaved() {
|
||||
return true;
|
||||
}
|
||||
|
||||
loadPlacesInBounds() {
|
||||
return [];
|
||||
}
|
||||
|
||||
getPlacesInList(listId) {
|
||||
if (listId === 'to-go') {
|
||||
return Promise.resolve([this.savedPlaces[0]]);
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
rs = {
|
||||
on: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
module('Acceptance | collections navigation', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.owner.register('service:osm', MockOsmService);
|
||||
this.owner.register('service:storage', MockStorageService);
|
||||
});
|
||||
|
||||
test('navigating through the collections menu hierarchy, viewing list places, and going back', async function (assert) {
|
||||
// 1. Visit Home Map
|
||||
await visit('/');
|
||||
assert.strictEqual(currentURL(), '/');
|
||||
|
||||
// 2. Open the App Menu overlay
|
||||
await click('.menu-btn-integrated');
|
||||
assert.dom('.sidebar.app-menu-pane').exists('App menu sidebar is open');
|
||||
assert
|
||||
.dom('.app-menu')
|
||||
.includesText('Collections', 'Menu contains Collections link');
|
||||
|
||||
// 3. Transition to Collections Index (List of lists)
|
||||
await click(document.querySelectorAll('.app-menu button')[0]); // Click "Collections"
|
||||
assert.strictEqual(currentURL(), '/lists', 'Transitions to /lists index');
|
||||
assert
|
||||
.dom('.sidebar-header-text-centered')
|
||||
.includesText('Collections', 'Header is centered and titled Collections');
|
||||
assert
|
||||
.dom('.lists-index-item')
|
||||
.exists({ count: 2 }, 'Renders our 2 mocked list items');
|
||||
|
||||
// 4. Transition to a specific list (Want to go)
|
||||
await click(document.querySelectorAll('.lists-index-item')[0]); // Click "Want to go"
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
'/lists/to-go',
|
||||
'Transitions instantly to /lists/to-go'
|
||||
);
|
||||
|
||||
// 5. Verify background loading spinner shows up, then results populate
|
||||
await waitFor('.places-list');
|
||||
assert
|
||||
.dom('.places-list .place-name')
|
||||
.hasText('Mountain Trail', 'Renders the saved place from the list');
|
||||
assert
|
||||
.dom('.places-list .place-type')
|
||||
.hasText('Saved place', 'Place type displays Saved place correctly');
|
||||
|
||||
// 6. Click back button in collection list header
|
||||
await click('.sidebar-header .back-btn');
|
||||
assert.strictEqual(currentURL(), '/lists', 'Goes back to /lists index');
|
||||
|
||||
// 7. Click back button in collections index header
|
||||
await click('.sidebar-header .back-btn');
|
||||
assert.strictEqual(currentURL(), '/menu', 'Goes back to main menu route');
|
||||
|
||||
// 8. Close sidebar
|
||||
await click('.sidebar-header .close-btn');
|
||||
assert.strictEqual(currentURL(), '/', 'Sidebar closed and returned home');
|
||||
});
|
||||
|
||||
test('clicking a place inside a collection sets returnToRoute and returns gracefully on back click', async function (assert) {
|
||||
await visit('/lists/to-go');
|
||||
await waitFor('.places-list');
|
||||
|
||||
// Click on the place item to view details
|
||||
await click('.place-item');
|
||||
assert.ok(
|
||||
currentURL().includes('/place/place-123'),
|
||||
'Transitions to place details route'
|
||||
);
|
||||
|
||||
// Click back from place details
|
||||
await click('.back-btn');
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
'/lists/to-go',
|
||||
'Returns gracefully back to lists/to-go list view'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,6 @@ import { module, test } from 'qunit';
|
||||
import { visit, currentURL, waitFor, triggerEvent } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'marco/tests/helpers';
|
||||
import Service from '@ember/service';
|
||||
import sinon from 'sinon';
|
||||
|
||||
module('Acceptance | map search reset', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -17,58 +16,10 @@ module('Acceptance | map search reset', function (hooks) {
|
||||
'marco:map-view',
|
||||
JSON.stringify(highZoomState)
|
||||
);
|
||||
|
||||
// Stub window.fetch using Sinon
|
||||
// We want to intercept map style requests and let everything else through
|
||||
this.fetchStub = sinon.stub(window, 'fetch');
|
||||
|
||||
this.fetchStub.callsFake(async (input, init) => {
|
||||
let url = input;
|
||||
if (typeof input === 'object' && input !== null && 'url' in input) {
|
||||
url = input.url;
|
||||
}
|
||||
|
||||
if (
|
||||
typeof url === 'string' &&
|
||||
url.includes('tiles.openfreemap.org/styles/liberty')
|
||||
) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
version: 8,
|
||||
name: 'Liberty',
|
||||
sources: {
|
||||
openmaptiles: {
|
||||
type: 'vector',
|
||||
url: 'https://tiles.openfreemap.org/planet',
|
||||
},
|
||||
},
|
||||
layers: [
|
||||
{
|
||||
id: 'background',
|
||||
type: 'background',
|
||||
paint: {
|
||||
'background-color': '#123456',
|
||||
},
|
||||
},
|
||||
],
|
||||
glyphs:
|
||||
'https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf',
|
||||
sprite: 'https://tiles.openfreemap.org/sprites/liberty',
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
// Pass through to the original implementation
|
||||
return this.fetchStub.wrappedMethod(input, init);
|
||||
});
|
||||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
window.localStorage.removeItem('marco:map-view');
|
||||
// Restore the original fetch
|
||||
this.fetchStub.restore();
|
||||
});
|
||||
|
||||
test('clicking the map clears the category search parameter', async function (assert) {
|
||||
@@ -140,15 +91,17 @@ module('Acceptance | map search reset', function (hooks) {
|
||||
bubbles: true,
|
||||
});
|
||||
|
||||
// Wait for transition to index
|
||||
// Wait for transition or UI update
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
'/',
|
||||
'Should have transitioned to index (closed sidebar)'
|
||||
|
||||
// Sidebar should be hidden, but we should stay on the search route
|
||||
assert.dom('.sidebar').doesNotExist('Sidebar should be closed');
|
||||
assert.ok(
|
||||
currentURL().includes('category=coffee'),
|
||||
'Should have stayed on the search route with markers intact'
|
||||
);
|
||||
|
||||
// Second Click (Start new search)
|
||||
// Second Click (Clear search and markers)
|
||||
// Click slightly differently to ensure fresh event
|
||||
await triggerEvent(canvas, 'pointerdown', {
|
||||
clientX: 250,
|
||||
@@ -172,11 +125,6 @@ module('Acceptance | map search reset', function (hooks) {
|
||||
// 3. Wait for transition
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
|
||||
const newUrl = currentURL();
|
||||
assert.notOk(
|
||||
newUrl.includes('category=coffee'),
|
||||
`New URL ${newUrl} should not contain category param`
|
||||
);
|
||||
assert.ok(newUrl.includes('/search'), 'Should be on search route');
|
||||
assert.strictEqual(currentURL(), '/', 'Should have transitioned to index');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,6 +38,7 @@ class MockOsmService extends Service {
|
||||
}
|
||||
|
||||
class MockStorageService extends Service {
|
||||
initialSyncDone = true;
|
||||
savedPlaces = [];
|
||||
findPlaceById() {
|
||||
return null;
|
||||
@@ -84,7 +85,7 @@ module('Acceptance | navigation', function (hooks) {
|
||||
);
|
||||
});
|
||||
|
||||
test('closing the sidebar resets the returnToSearch flag', async function (assert) {
|
||||
test('closing the sidebar transitions back to search route when opened from search results', async function (assert) {
|
||||
const mapUi = this.owner.lookup('service:map-ui');
|
||||
|
||||
await visit('/search?lat=1&lon=1');
|
||||
@@ -95,8 +96,23 @@ module('Acceptance | navigation', function (hooks) {
|
||||
// Click the Close (X) button
|
||||
await click('.close-btn');
|
||||
|
||||
assert.strictEqual(currentURL(), '/', 'Returned to index');
|
||||
assert.false(mapUi.returnToSearch, 'Flag is reset after closing sidebar');
|
||||
assert.dom('.sidebar').doesNotExist('Sidebar should be closed');
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
'/search?lat=1&lon=1',
|
||||
'Should transition back to search route'
|
||||
);
|
||||
});
|
||||
|
||||
test('closing the sidebar when visiting a place directly transitions to index', async function (assert) {
|
||||
await visit('/place/osm:node:123');
|
||||
assert.ok(currentURL().includes('/place/'), 'Visited place directly');
|
||||
|
||||
// Click the Close (X) button
|
||||
await click('.close-btn');
|
||||
|
||||
assert.dom('.sidebar').doesNotExist('Sidebar should be closed');
|
||||
assert.strictEqual(currentURL(), '/', 'Should transition back to index');
|
||||
});
|
||||
|
||||
test('navigating directly to place and back closes sidebar', async function (assert) {
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, click, fillIn, currentURL } from '@ember/test-helpers';
|
||||
import { visit, click, fillIn, currentURL, settled } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'marco/tests/helpers';
|
||||
import Service from '@ember/service';
|
||||
import { Promise } from 'rsvp';
|
||||
|
||||
let photonResolve;
|
||||
let osmResolve;
|
||||
|
||||
class MockPhotonService extends Service {
|
||||
cancelAll() {}
|
||||
|
||||
async search(query) {
|
||||
// Simulate network delay
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
if (query === 'slow') {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
// Return a promise that we can manually resolve in the test
|
||||
// to avoid race conditions with native setTimeout
|
||||
return new Promise((resolve) => {
|
||||
photonResolve = () => {
|
||||
resolve([
|
||||
{
|
||||
title: 'Test Place',
|
||||
lat: 1,
|
||||
lon: 1,
|
||||
osmId: '123',
|
||||
osmType: 'node',
|
||||
},
|
||||
]);
|
||||
};
|
||||
});
|
||||
}
|
||||
return [
|
||||
{
|
||||
@@ -29,9 +44,12 @@ class MockOsmService extends Service {
|
||||
cancelAll() {}
|
||||
|
||||
async getCategoryPois(bounds, category) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
if (category === 'slow_category') {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
return new Promise((resolve) => {
|
||||
osmResolve = () => {
|
||||
resolve([]);
|
||||
};
|
||||
});
|
||||
}
|
||||
return [];
|
||||
}
|
||||
@@ -44,6 +62,8 @@ module('Acceptance | search loading', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
photonResolve = null;
|
||||
osmResolve = null;
|
||||
this.owner.register('service:photon', MockPhotonService);
|
||||
this.owner.register('service:osm', MockOsmService);
|
||||
});
|
||||
@@ -66,7 +86,12 @@ module('Acceptance | search loading', function (hooks) {
|
||||
'Loading state is set for text search'
|
||||
);
|
||||
|
||||
// Resolve the manual promise so the task can finish deterministically
|
||||
photonResolve();
|
||||
|
||||
await searchPromise;
|
||||
await settled(); // Wait for ember-concurrency tasks to fully settle
|
||||
|
||||
assert.strictEqual(
|
||||
mapUi.loadingState,
|
||||
null,
|
||||
@@ -83,7 +108,12 @@ module('Acceptance | search loading', function (hooks) {
|
||||
'Loading state is set for category search'
|
||||
);
|
||||
|
||||
// Resolve the manual promise
|
||||
osmResolve();
|
||||
|
||||
await catPromise;
|
||||
await settled();
|
||||
|
||||
assert.strictEqual(
|
||||
mapUi.loadingState,
|
||||
null,
|
||||
@@ -122,6 +152,7 @@ module('Acceptance | search loading', function (hooks) {
|
||||
|
||||
// 4. Click the clear button (should be visible since input has value)
|
||||
await click('.search-clear-btn');
|
||||
// Wait for the click and transition to settle
|
||||
|
||||
// Verify loading state is cleared immediately
|
||||
assert.strictEqual(
|
||||
@@ -130,7 +161,85 @@ module('Acceptance | search loading', function (hooks) {
|
||||
'Loading state is cleared immediately after clicking clear'
|
||||
);
|
||||
|
||||
// Clean up the dangling promise
|
||||
if (photonResolve) {
|
||||
photonResolve();
|
||||
}
|
||||
|
||||
// Verify we are back on index (or at least query is gone)
|
||||
assert.strictEqual(currentURL(), '/', 'Navigated to index');
|
||||
});
|
||||
|
||||
test('quick search pills visibility during category search transition', async function (assert) {
|
||||
const mapUi = this.owner.lookup('service:map-ui');
|
||||
mapUi.currentZoom = 15;
|
||||
|
||||
// Seed localStorage with a high zoom level to ensure quick search buttons show
|
||||
const highZoomState = {
|
||||
center: [13.4, 52.5],
|
||||
zoom: 18,
|
||||
};
|
||||
window.localStorage.setItem(
|
||||
'marco:map-view',
|
||||
JSON.stringify(highZoomState)
|
||||
);
|
||||
|
||||
try {
|
||||
// Make sure quick search buttons setting is enabled
|
||||
const settings = this.owner.lookup('service:settings');
|
||||
settings.showQuickSearchButtons = true;
|
||||
|
||||
// 1. Visit slowly loading category search
|
||||
const catPromise = visit('/search?category=slow_category&lat=1&lon=1');
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
|
||||
// Verify loading state is set and pills are visible (i.e. header-center does NOT have .searching)
|
||||
assert.ok(mapUi.loadingState, 'Search is loading');
|
||||
assert
|
||||
.dom('.header-center')
|
||||
.doesNotHaveClass(
|
||||
'searching',
|
||||
'Pills remain visible while search is loading'
|
||||
);
|
||||
|
||||
// Resolve the promise with empty results
|
||||
osmResolve();
|
||||
await catPromise;
|
||||
await settled();
|
||||
|
||||
// Verify search completed and since results are empty, pills are still visible
|
||||
assert.strictEqual(mapUi.searchResults.length, 0, 'No results found');
|
||||
assert
|
||||
.dom('.header-center')
|
||||
.doesNotHaveClass(
|
||||
'searching',
|
||||
'Pills remain visible after search completes with no results'
|
||||
);
|
||||
|
||||
// 2. Now simulate a fast category search that returns results
|
||||
const osmService = this.owner.lookup('service:osm');
|
||||
osmService.getCategoryPois = async () => [
|
||||
{
|
||||
title: 'Latte Art Cafe',
|
||||
lat: 1,
|
||||
lon: 1,
|
||||
osmId: '101',
|
||||
osmType: 'N',
|
||||
},
|
||||
];
|
||||
|
||||
await visit('/search?category=coffee&lat=1&lon=1');
|
||||
|
||||
// Verify search completed with results, so pills are hidden
|
||||
assert.ok(mapUi.searchResults.length > 0, 'Results found');
|
||||
assert
|
||||
.dom('.header-center')
|
||||
.hasClass(
|
||||
'searching',
|
||||
'Pills are hidden after search completes with results'
|
||||
);
|
||||
} finally {
|
||||
window.localStorage.removeItem('marco:map-view');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -270,4 +270,76 @@ module('Acceptance | search', function (hooks) {
|
||||
.hasText('Search request failed. Please try again.');
|
||||
assert.dom('.places-sidebar').doesNotExist('Results panel should not open');
|
||||
});
|
||||
|
||||
test('search box query synchronized with active route query parameters', async function (assert) {
|
||||
// Mock Osm Service
|
||||
class MockOsmService extends Service {
|
||||
async getCategoryPois() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
this.owner.register('service:osm', MockOsmService);
|
||||
|
||||
// Mock Photon Service
|
||||
class MockPhotonService extends Service {
|
||||
async search() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
this.owner.register('service:photon', MockPhotonService);
|
||||
|
||||
// Mock Storage Service
|
||||
class MockStorageService extends Service {
|
||||
savedPlaces = [];
|
||||
findPlaceById() {
|
||||
return null;
|
||||
}
|
||||
isPlaceSaved() {
|
||||
return false;
|
||||
}
|
||||
rs = { on: () => {} };
|
||||
placesInView = [];
|
||||
loadPlacesInBounds() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
this.owner.register('service:storage', MockStorageService);
|
||||
|
||||
// Mock Map Service
|
||||
class MockMapService extends Service {
|
||||
getBounds() {
|
||||
return {
|
||||
minLat: 52.5,
|
||||
minLon: 13.4,
|
||||
maxLat: 52.6,
|
||||
maxLon: 13.5,
|
||||
};
|
||||
}
|
||||
}
|
||||
this.owner.register('service:map', MockMapService);
|
||||
|
||||
// 1. Visit a search URL directly
|
||||
await visit('/search?q=Berlin');
|
||||
assert
|
||||
.dom('.search-input')
|
||||
.hasValue(
|
||||
'Berlin',
|
||||
'Search input is populated with search term on direct load'
|
||||
);
|
||||
|
||||
// 2. Visit a category search URL
|
||||
await visit('/search?category=coffee&lat=52.52&lon=13.405');
|
||||
assert
|
||||
.dom('.search-input')
|
||||
.hasValue(
|
||||
'Coffee',
|
||||
'Search input is populated with mapped category label'
|
||||
);
|
||||
|
||||
// 3. Go back to index
|
||||
await visit('/');
|
||||
assert
|
||||
.dom('.search-input')
|
||||
.hasValue('', 'Search input is cleared on transitioning to index');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,93 @@ import {
|
||||
setupRenderingTest as upstreamSetupRenderingTest,
|
||||
setupTest as upstreamSetupTest,
|
||||
} from 'ember-qunit';
|
||||
import { setupNostrMocks } from './mock-nostr';
|
||||
import sinon from 'sinon';
|
||||
|
||||
function setupMapStyleMocks(hooks) {
|
||||
hooks.beforeEach(function () {
|
||||
// Stub window.fetch to capture map-style assets before they hit the network
|
||||
this.fetchStub = sinon.stub(window, 'fetch');
|
||||
|
||||
this.fetchStub.callsFake(async (input, init) => {
|
||||
let url = input;
|
||||
if (typeof input === 'object' && input !== null && 'url' in input) {
|
||||
url = input.url;
|
||||
}
|
||||
|
||||
if (typeof url === 'string' && url.includes('tiles.openfreemap.org')) {
|
||||
// A. Mock Style Sheet
|
||||
if (url.includes('/styles/liberty')) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({
|
||||
version: 8,
|
||||
name: 'Mock Style',
|
||||
sources: {
|
||||
openmaptiles: {
|
||||
type: 'vector',
|
||||
tiles: [], // Empty tiles list prevents any map tile fetching completely!
|
||||
},
|
||||
},
|
||||
sprite: 'https://tiles.openfreemap.org/sprites/liberty',
|
||||
glyphs:
|
||||
'https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf',
|
||||
layers: [
|
||||
{
|
||||
id: 'background',
|
||||
type: 'background',
|
||||
paint: { 'background-color': '#f8f9fa' },
|
||||
},
|
||||
],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
// B. Mock Sprite Atlas JSON
|
||||
if (url.endsWith('.json') && url.includes('/sprites/')) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({}), // Empty sprite dictionary
|
||||
};
|
||||
}
|
||||
|
||||
// C. Mock Sprite Atlas PNG (Returns a valid 1x1 transparent PNG)
|
||||
if (url.endsWith('.png') && url.includes('/sprites/')) {
|
||||
const bytes = new Uint8Array([
|
||||
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0,
|
||||
0, 1, 0, 0, 0, 1, 8, 6, 0, 0, 0, 31, 21, 196, 137, 0, 0, 0, 11, 73,
|
||||
68, 65, 84, 120, 156, 99, 96, 0, 0, 0, 2, 0, 1, 226, 33, 188, 51, 0,
|
||||
0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130,
|
||||
]);
|
||||
const blob = new Blob([bytes], { type: 'image/png' });
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
blob: async () => blob,
|
||||
};
|
||||
}
|
||||
|
||||
// Catch-all mock for other openfreemap endpoints
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({}),
|
||||
};
|
||||
}
|
||||
|
||||
// Pass through to original fetch (e.g. Photon results, local mock APIs)
|
||||
return this.fetchStub.wrappedMethod(input, init);
|
||||
});
|
||||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
if (this.fetchStub && typeof this.fetchStub.restore === 'function') {
|
||||
this.fetchStub.restore();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This file exists to provide wrappers around ember-qunit's
|
||||
// test setup functions. This way, you can easily extend the setup that is
|
||||
@@ -10,6 +97,8 @@ import {
|
||||
|
||||
function setupApplicationTest(hooks, options) {
|
||||
upstreamSetupApplicationTest(hooks, options);
|
||||
setupNostrMocks(hooks);
|
||||
setupMapStyleMocks(hooks);
|
||||
|
||||
// Additional setup for application tests can be done here.
|
||||
//
|
||||
@@ -29,12 +118,14 @@ function setupApplicationTest(hooks, options) {
|
||||
|
||||
function setupRenderingTest(hooks, options) {
|
||||
upstreamSetupRenderingTest(hooks, options);
|
||||
setupNostrMocks(hooks);
|
||||
|
||||
// Additional setup for rendering tests can be done here.
|
||||
}
|
||||
|
||||
function setupTest(hooks, options) {
|
||||
upstreamSetupTest(hooks, options);
|
||||
setupNostrMocks(hooks);
|
||||
|
||||
// Additional setup for unit tests can be done here.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import Service from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { Promise } from 'rsvp';
|
||||
|
||||
export class MockNostrAuthService extends Service {
|
||||
@tracked pubkey = null;
|
||||
@tracked signerType = null;
|
||||
@tracked connectStatus = null;
|
||||
@tracked connectUri = null;
|
||||
|
||||
get isConnected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
get isMobile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
get signer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
async connectWithExtension() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async connectWithApp() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
export class MockNostrDataService extends Service {
|
||||
@tracked profile = null;
|
||||
@tracked mailboxes = null;
|
||||
@tracked blossomServers = [];
|
||||
@tracked placePhotos = [];
|
||||
|
||||
store = {
|
||||
add: () => {},
|
||||
};
|
||||
|
||||
get activeReadRelays() {
|
||||
return [];
|
||||
}
|
||||
|
||||
get activeWriteRelays() {
|
||||
return [];
|
||||
}
|
||||
|
||||
get requiredReadRelays() {
|
||||
return [];
|
||||
}
|
||||
|
||||
get requiredWriteRelays() {
|
||||
return [];
|
||||
}
|
||||
|
||||
get mailboxReadRelays() {
|
||||
return [];
|
||||
}
|
||||
|
||||
get mailboxWriteRelays() {
|
||||
return [];
|
||||
}
|
||||
|
||||
get userDisplayName() {
|
||||
return 'Mock User';
|
||||
}
|
||||
|
||||
loadPlacesInBounds() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
loadPhotosForPlace() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
loadPlacePhotos() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
export class MockNostrRelayService extends Service {
|
||||
pool = {
|
||||
publish: () => Promise.resolve([{ ok: true }]),
|
||||
subscribe: () => {},
|
||||
unsubscribe: () => {},
|
||||
close: () => {},
|
||||
};
|
||||
|
||||
async publish() {
|
||||
return [{ ok: true }];
|
||||
}
|
||||
}
|
||||
|
||||
export function setupNostrMocks(hooks) {
|
||||
hooks.beforeEach(function () {
|
||||
this.owner.register('service:nostrAuth', MockNostrAuthService);
|
||||
this.owner.register('service:nostrData', MockNostrDataService);
|
||||
this.owner.register('service:nostrRelay', MockNostrRelayService);
|
||||
});
|
||||
}
|
||||
+6
-1
@@ -16,7 +16,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/testem.js" integrity="" data-embroider-ignore></script>
|
||||
<script
|
||||
src="/testem.js"
|
||||
integrity=""
|
||||
data-embroider-ignore
|
||||
vite-ignore
|
||||
></script>
|
||||
|
||||
<script type="module">import "ember-testing";</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
||||
import { click, fillIn, render } from '@ember/test-helpers';
|
||||
import Service, { service } from '@ember/service';
|
||||
import AppMenuSettingsNostr from 'marco/components/app-menu/settings/nostr';
|
||||
import {
|
||||
excludeRequiredRelays,
|
||||
mergeRequiredRelays,
|
||||
uniqNormalizedRelays,
|
||||
} from 'marco/utils/nostr';
|
||||
|
||||
class MockNostrDataService extends Service {
|
||||
@service settings;
|
||||
|
||||
requiredReadRelays = ['wss://nostr.kosmos.org'];
|
||||
requiredWriteRelays = [];
|
||||
|
||||
mailboxReadRelays = ['wss://mailbox.example.com'];
|
||||
mailboxWriteRelays = ['wss://mailbox-write.example.com'];
|
||||
|
||||
get configuredReadRelays() {
|
||||
const configured = uniqNormalizedRelays([
|
||||
...this.mailboxReadRelays,
|
||||
...(this.settings.nostrReadRelays || []),
|
||||
]);
|
||||
|
||||
return excludeRequiredRelays(
|
||||
configured,
|
||||
this.settings.nostrReadRelayExclusions || []
|
||||
);
|
||||
}
|
||||
|
||||
get configuredWriteRelays() {
|
||||
const configured = uniqNormalizedRelays([
|
||||
...this.mailboxWriteRelays,
|
||||
...(this.settings.nostrWriteRelays || []),
|
||||
]);
|
||||
|
||||
return excludeRequiredRelays(
|
||||
configured,
|
||||
this.settings.nostrWriteRelayExclusions || []
|
||||
);
|
||||
}
|
||||
|
||||
get activeReadRelays() {
|
||||
return mergeRequiredRelays(
|
||||
this.requiredReadRelays,
|
||||
this.configuredReadRelays
|
||||
);
|
||||
}
|
||||
|
||||
get activeWriteRelays() {
|
||||
return mergeRequiredRelays(
|
||||
this.requiredWriteRelays,
|
||||
this.configuredWriteRelays
|
||||
);
|
||||
}
|
||||
|
||||
async clearCache() {}
|
||||
}
|
||||
|
||||
function readRows(element) {
|
||||
const list = element.querySelectorAll('.relay-list')[0];
|
||||
return [...list.querySelectorAll('li')];
|
||||
}
|
||||
|
||||
function writeRows(element) {
|
||||
const list = element.querySelectorAll('.relay-list')[1];
|
||||
return [...list.querySelectorAll('li')];
|
||||
}
|
||||
|
||||
function rowByText(rows, text) {
|
||||
return rows.find((row) => row.textContent.includes(text));
|
||||
}
|
||||
|
||||
module('Integration | Component | app-menu/settings/nostr', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
localStorage.removeItem('marco:settings');
|
||||
|
||||
this.owner.register('service:nostrData', MockNostrDataService);
|
||||
this.settings = this.owner.lookup('service:settings');
|
||||
this.onChange = () => {};
|
||||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
localStorage.removeItem('marco:settings');
|
||||
});
|
||||
|
||||
async function renderAndOpenDetails(context) {
|
||||
await render(
|
||||
<template><AppMenuSettingsNostr @onChange={{this.onChange}} /></template>
|
||||
);
|
||||
await click('summary');
|
||||
return context.element;
|
||||
}
|
||||
|
||||
test('required read relay is first and non-removable', async function (assert) {
|
||||
const element = await renderAndOpenDetails(this);
|
||||
const rows = readRows(element);
|
||||
|
||||
assert.dom(rows[0]).includesText('nostr.kosmos.org');
|
||||
|
||||
const requiredRow = rowByText(rows, 'nostr.kosmos.org');
|
||||
const mailboxRow = rowByText(rows, 'mailbox.example.com');
|
||||
|
||||
assert.dom(requiredRow.querySelector('.btn-remove-relay')).doesNotExist();
|
||||
assert.dom(mailboxRow.querySelector('.btn-remove-relay')).exists();
|
||||
});
|
||||
|
||||
test('removing mailbox read relay stores exclusion override', async function (assert) {
|
||||
const element = await renderAndOpenDetails(this);
|
||||
const mailboxRow = rowByText(readRows(element), 'mailbox.example.com');
|
||||
|
||||
await click(mailboxRow.querySelector('.btn-remove-relay'));
|
||||
|
||||
assert.deepEqual(this.settings.nostrReadRelayExclusions, [
|
||||
'wss://mailbox.example.com',
|
||||
]);
|
||||
assert.strictEqual(this.settings.nostrReadRelays, null);
|
||||
});
|
||||
|
||||
test('removing custom read relay updates custom list without exclusions', async function (assert) {
|
||||
this.settings.update('nostrReadRelays', ['wss://custom.example.com']);
|
||||
|
||||
const element = await renderAndOpenDetails(this);
|
||||
const customRow = rowByText(readRows(element), 'custom.example.com');
|
||||
|
||||
await click(customRow.querySelector('.btn-remove-relay'));
|
||||
|
||||
assert.strictEqual(this.settings.nostrReadRelays, null);
|
||||
assert.strictEqual(this.settings.nostrReadRelayExclusions, null);
|
||||
});
|
||||
|
||||
test('adding read relay clears existing exclusion for same relay', async function (assert) {
|
||||
this.settings.update('nostrReadRelayExclusions', [
|
||||
'wss://mailbox.example.com',
|
||||
]);
|
||||
|
||||
const element = await renderAndOpenDetails(this);
|
||||
|
||||
await fillIn('#new-read-relay', 'Mailbox.EXAMPLE.com/');
|
||||
await click(element.querySelector('#new-read-relay').nextElementSibling);
|
||||
|
||||
assert.deepEqual(this.settings.nostrReadRelays, [
|
||||
'wss://mailbox.example.com',
|
||||
]);
|
||||
assert.strictEqual(this.settings.nostrReadRelayExclusions, null);
|
||||
});
|
||||
|
||||
test('reset read relays clears additions and exclusions', async function (assert) {
|
||||
this.settings.update('nostrReadRelays', ['wss://custom.example.com']);
|
||||
this.settings.update('nostrReadRelayExclusions', [
|
||||
'wss://mailbox.example.com',
|
||||
]);
|
||||
|
||||
const element = await renderAndOpenDetails(this);
|
||||
await click(element.querySelectorAll('.reset-relays')[0]);
|
||||
|
||||
assert.strictEqual(this.settings.nostrReadRelays, null);
|
||||
assert.strictEqual(this.settings.nostrReadRelayExclusions, null);
|
||||
|
||||
const requiredRow = rowByText(readRows(element), 'nostr.kosmos.org');
|
||||
assert.dom(requiredRow).exists();
|
||||
});
|
||||
|
||||
test('write relays are removable and mailbox delete stores exclusion', async function (assert) {
|
||||
this.settings.update('nostrWriteRelays', [
|
||||
'wss://custom-write.example.com',
|
||||
]);
|
||||
|
||||
const element = await renderAndOpenDetails(this);
|
||||
const rows = writeRows(element);
|
||||
|
||||
assert.true(
|
||||
rows.every((row) => row.querySelector('.btn-remove-relay')),
|
||||
'all write relays can be removed'
|
||||
);
|
||||
|
||||
const mailboxRow = rowByText(rows, 'mailbox-write.example.com');
|
||||
await click(mailboxRow.querySelector('.btn-remove-relay'));
|
||||
|
||||
assert.deepEqual(this.settings.nostrWriteRelayExclusions, [
|
||||
'wss://mailbox-write.example.com',
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import PhotoCarousel from 'marco/components/photo-carousel';
|
||||
|
||||
module('Integration | Component | photo-carousel', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders gracefully with no photos', async function (assert) {
|
||||
this.photos = [];
|
||||
|
||||
await render(
|
||||
<template><PhotoCarousel @photos={{this.photos}} /></template>
|
||||
);
|
||||
|
||||
assert
|
||||
.dom('.photo-carousel')
|
||||
.doesNotExist('it does not render the wrapper when there are no photos');
|
||||
});
|
||||
|
||||
test('it renders a single photo without navigation chevrons', async function (assert) {
|
||||
this.photos = [
|
||||
{
|
||||
url: 'photo1.jpg',
|
||||
thumbUrl: 'thumb1.jpg',
|
||||
blurhash: 'LKO2?U%2Tw=w]~RBVZRi};RPxuwH',
|
||||
ratio: 1.5,
|
||||
isLandscape: true,
|
||||
},
|
||||
];
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div class="test-container">
|
||||
<PhotoCarousel @photos={{this.photos}} />
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert.dom('.photo-carousel').exists('it renders the wrapper');
|
||||
assert
|
||||
.dom('.carousel-slide:not(.carousel-placeholder)')
|
||||
.exists({ count: 1 }, 'it renders one real photo slide');
|
||||
assert
|
||||
.dom('.carousel-placeholder')
|
||||
.exists({ count: 1 }, 'it renders one placeholder');
|
||||
assert
|
||||
.dom('img.place-header-photo')
|
||||
.hasAttribute('data-src', 'photo1.jpg', 'it sets the data-src correctly');
|
||||
|
||||
// There should be no chevrons when there's only 1 photo
|
||||
assert
|
||||
.dom('.carousel-nav-btn')
|
||||
.doesNotExist('it does not render chevrons for a single photo');
|
||||
});
|
||||
|
||||
test('it renders multiple photos and shows chevrons', async function (assert) {
|
||||
this.photos = [
|
||||
{
|
||||
url: 'photo1.jpg',
|
||||
thumbUrl: 'thumb1.jpg',
|
||||
blurhash: 'LKO2?U%2Tw=w]~RBVZRi};RPxuwH',
|
||||
ratio: 1.5,
|
||||
isLandscape: true,
|
||||
},
|
||||
{
|
||||
url: 'photo2.jpg',
|
||||
thumbUrl: 'thumb2.jpg',
|
||||
blurhash: 'LKO2?U%2Tw=w]~RBVZRi};RPxuwH',
|
||||
ratio: 1.0,
|
||||
isLandscape: false,
|
||||
},
|
||||
{
|
||||
url: 'photo3.jpg',
|
||||
thumbUrl: 'thumb3.jpg',
|
||||
blurhash: 'LKO2?U%2Tw=w]~RBVZRi};RPxuwH',
|
||||
ratio: 0.8,
|
||||
isLandscape: false,
|
||||
},
|
||||
];
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div class="test-container">
|
||||
<PhotoCarousel @photos={{this.photos}} />
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
assert.dom('.carousel-slide').exists({ count: 3 }, 'it renders all slides');
|
||||
assert
|
||||
.dom('.carousel-nav-btn')
|
||||
.exists({ count: 2 }, 'it renders both chevrons');
|
||||
|
||||
// Initially, it shouldn't be able to scroll left
|
||||
assert
|
||||
.dom('.carousel-nav-btn.prev')
|
||||
.hasClass('disabled', 'the prev button is disabled initially');
|
||||
assert
|
||||
.dom('.carousel-nav-btn.next')
|
||||
.doesNotHaveClass('disabled', 'the next button is enabled initially');
|
||||
|
||||
// We can't perfectly test native scroll behavior easily in JSDOM/QUnit without mocking the DOM elements' scroll properties,
|
||||
// but we can test that clicking the next button triggers the scrolling method.
|
||||
// However, since we mock scrollLeft in the component logic implicitly via template action, let's at least ensure clicking doesn't throw.
|
||||
await click('.carousel-nav-btn.next');
|
||||
|
||||
assert.ok(true, 'clicking next button does not throw');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,339 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
||||
import { render, click, triggerKeyEvent } from '@ember/test-helpers';
|
||||
import Service from '@ember/service';
|
||||
import PhotoGallery from 'marco/components/photo-gallery';
|
||||
import { setupNostrMocks } from 'marco/tests/helpers/mock-nostr';
|
||||
import sinon from 'sinon';
|
||||
|
||||
class MockBlossomService extends Service {
|
||||
async delete() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class MockToastService extends Service {
|
||||
show() {}
|
||||
}
|
||||
|
||||
module('Integration | Component | photo-gallery', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
setupNostrMocks(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.owner.register('service:blossom', MockBlossomService);
|
||||
this.owner.register('service:toast', MockToastService);
|
||||
|
||||
this.blossom = this.owner.lookup('service:blossom');
|
||||
this.nostrAuth = this.owner.lookup('service:nostrAuth');
|
||||
this.nostrData = this.owner.lookup('service:nostrData');
|
||||
this.nostrRelay = this.owner.lookup('service:nostrRelay');
|
||||
this.toast = this.owner.lookup('service:toast');
|
||||
this.settings = this.owner.lookup('service:settings');
|
||||
|
||||
this.photos = [
|
||||
{
|
||||
eventId: 'event1',
|
||||
pubkey: 'userA',
|
||||
placeIdentifier: 'osm:node:12345',
|
||||
url: 'https://example.com/a3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1.jpg',
|
||||
thumbUrl:
|
||||
'https://example.com/b3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1.jpg',
|
||||
},
|
||||
{
|
||||
eventId: 'event2',
|
||||
pubkey: 'userB',
|
||||
placeIdentifier: 'osm:node:12345',
|
||||
url: 'photo2.jpg',
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
hooks.afterEach(function () {
|
||||
sinon.restore();
|
||||
localStorage.removeItem('marco:settings');
|
||||
});
|
||||
|
||||
test('it does not show delete button if user is not creator', async function (assert) {
|
||||
this.nostrAuth.pubkey = 'userB'; // Different from photo1's pubkey
|
||||
this.selectedPhoto = this.photos[0];
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
// Open dropdown
|
||||
await click('.dropdown-trigger-btn');
|
||||
|
||||
assert.dom('.dropdown-popover').exists('Dropdown opened');
|
||||
assert
|
||||
.dom('.dropdown-item.text-danger')
|
||||
.doesNotExist('Delete button is hidden for non-creator');
|
||||
});
|
||||
|
||||
test('it shows delete button if user is creator and setting is enabled', async function (assert) {
|
||||
this.nostrAuth.pubkey = 'userA'; // Matches photo1's pubkey
|
||||
this.settings.update('experimentalEnablePhotoDeletion', true); // Enable the setting
|
||||
this.selectedPhoto = this.photos[0];
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
// Open dropdown
|
||||
await click('.dropdown-trigger-btn');
|
||||
|
||||
assert.dom('.dropdown-popover').exists('Dropdown opened');
|
||||
assert
|
||||
.dom('.dropdown-item.text-danger')
|
||||
.exists('Delete button is visible for creator when setting is enabled');
|
||||
});
|
||||
|
||||
test('it handles cancellation of deletion', async function (assert) {
|
||||
this.nostrAuth.pubkey = 'userA';
|
||||
this.settings.update('experimentalEnablePhotoDeletion', true);
|
||||
this.selectedPhoto = this.photos[0];
|
||||
|
||||
const confirmStub = sinon.stub(window, 'confirm').returns(false);
|
||||
const blossomSpy = sinon.spy(this.blossom, 'delete');
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
await click('.dropdown-trigger-btn');
|
||||
await click('.dropdown-item.text-danger');
|
||||
|
||||
assert.ok(confirmStub.calledOnce, 'confirmation dialog was shown');
|
||||
assert.ok(blossomSpy.notCalled, 'blossom.delete was NOT called');
|
||||
});
|
||||
|
||||
test('it performs full deletion flow when confirmed', async function (assert) {
|
||||
this.nostrAuth.pubkey = 'userA';
|
||||
this.settings.update('experimentalEnablePhotoDeletion', true);
|
||||
// Override the mock's getter just for this test
|
||||
Object.defineProperty(this.nostrAuth, 'signer', {
|
||||
configurable: true,
|
||||
get: () => ({
|
||||
signEvent: async (e) => ({
|
||||
...e,
|
||||
id: 'signed-id',
|
||||
sig: 'sig',
|
||||
pubkey: 'userA',
|
||||
}),
|
||||
getPublicKey: async () => 'userA',
|
||||
}),
|
||||
});
|
||||
this.selectedPhoto = this.photos[0];
|
||||
|
||||
let closed = false;
|
||||
this.handleClose = () => {
|
||||
closed = true;
|
||||
};
|
||||
|
||||
const confirmStub = sinon.stub(window, 'confirm').returns(true);
|
||||
const blossomStub = sinon.stub(this.blossom, 'delete').resolves();
|
||||
const publishStub = sinon.stub(this.nostrRelay, 'publish').resolves();
|
||||
const storeStub = sinon.stub(this.nostrData.store, 'add');
|
||||
const toastSpy = sinon.spy(this.toast, 'show');
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
@onClose={{this.handleClose}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
await click('.dropdown-trigger-btn');
|
||||
await click('.dropdown-item.text-danger');
|
||||
|
||||
assert.ok(confirmStub.calledOnce, 'confirmation dialog was shown');
|
||||
|
||||
// Check blossom deletions
|
||||
assert.ok(
|
||||
blossomStub.calledTwice,
|
||||
'blossom.delete was called twice (main + thumb)'
|
||||
);
|
||||
assert.strictEqual(
|
||||
blossomStub.firstCall.args[0],
|
||||
'a3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1',
|
||||
'extracted correct hash for main image'
|
||||
);
|
||||
assert.strictEqual(
|
||||
blossomStub.secondCall.args[0],
|
||||
'b3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1',
|
||||
'extracted correct hash for thumb image'
|
||||
);
|
||||
|
||||
// Check Nostr kind 5
|
||||
assert.ok(publishStub.calledOnce, 'nostrRelay.publish was called');
|
||||
const publishedEvent = publishStub.firstCall.args[1];
|
||||
assert.strictEqual(publishedEvent.kind, 5, 'published event is kind 5');
|
||||
assert.deepEqual(
|
||||
publishedEvent.tags[0],
|
||||
['e', 'event1'],
|
||||
'event tags reference the deleted photo'
|
||||
);
|
||||
assert.deepEqual(
|
||||
publishedEvent.tags[1],
|
||||
['i', 'osm:node:12345'],
|
||||
'event tags include the place identifier'
|
||||
);
|
||||
|
||||
// Check store update
|
||||
assert.ok(storeStub.calledOnce, 'nostrData.store.add was called');
|
||||
assert.strictEqual(
|
||||
storeStub.firstCall.args[0].kind,
|
||||
5,
|
||||
'added kind 5 event to local store'
|
||||
);
|
||||
|
||||
// Check UX
|
||||
assert.ok(
|
||||
toastSpy.calledWith('Photo deleted successfully'),
|
||||
'success toast was shown'
|
||||
);
|
||||
assert.ok(closed, 'gallery was closed after deletion');
|
||||
});
|
||||
|
||||
test('it copies event id to clipboard', async function (assert) {
|
||||
this.nostrAuth.pubkey = 'userA';
|
||||
this.selectedPhoto = this.photos[0];
|
||||
|
||||
const clipboardStub = sinon
|
||||
.stub(navigator.clipboard, 'writeText')
|
||||
.resolves();
|
||||
const toastSpy = sinon.spy(this.toast, 'show');
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
await click('.dropdown-trigger-btn');
|
||||
|
||||
// Find the copy button (it should be the first one)
|
||||
const items = document.querySelectorAll('.dropdown-item');
|
||||
let copyBtn;
|
||||
items.forEach((item) => {
|
||||
if (item.textContent.includes('Copy Photo Event ID')) {
|
||||
copyBtn = item;
|
||||
}
|
||||
});
|
||||
|
||||
await click(copyBtn);
|
||||
|
||||
assert.ok(clipboardStub.calledWith('event1'), 'copied correct event id');
|
||||
assert.ok(
|
||||
toastSpy.calledWith('Event ID copied to clipboard'),
|
||||
'success toast was shown'
|
||||
);
|
||||
});
|
||||
|
||||
test('keyboard navigation changes photos', async function (assert) {
|
||||
this.photos = [
|
||||
{ eventId: 'event1', url: 'photo1.jpg' },
|
||||
{ eventId: 'event2', url: 'photo2.jpg' },
|
||||
{ eventId: 'event3', url: 'photo3.jpg' },
|
||||
];
|
||||
this.selectedPhoto = this.photos[0];
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute('data-current-event-id', 'event1');
|
||||
|
||||
// Right Arrow
|
||||
await triggerKeyEvent(document, 'keydown', 'ArrowRight');
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute('data-current-event-id', 'event2');
|
||||
|
||||
// Right Arrow again
|
||||
await triggerKeyEvent(document, 'keydown', 'ArrowRight');
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute('data-current-event-id', 'event3');
|
||||
|
||||
// Left Arrow
|
||||
await triggerKeyEvent(document, 'keydown', 'ArrowLeft');
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute('data-current-event-id', 'event2');
|
||||
});
|
||||
|
||||
test('escape key closes gallery', async function (assert) {
|
||||
this.selectedPhoto = this.photos[0];
|
||||
let closed = false;
|
||||
this.handleClose = () => {
|
||||
closed = true;
|
||||
};
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
@onClose={{this.handleClose}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
await triggerKeyEvent(document, 'keydown', 'Escape');
|
||||
assert.ok(closed, 'gallery was closed on escape key');
|
||||
});
|
||||
});
|
||||
@@ -334,4 +334,54 @@ module('Integration | Component | place-details', function (hooks) {
|
||||
assert.dom(links[0]).hasText('+44 987 654 321');
|
||||
assert.dom(links[1]).hasText('+1 234-567 8900');
|
||||
});
|
||||
|
||||
test('it renders correct OpenStreetMap link for an OSM place', async function (assert) {
|
||||
const place = {
|
||||
title: 'OSM Place',
|
||||
osmId: '12345',
|
||||
osmType: 'node',
|
||||
lat: 52.520008,
|
||||
lon: 13.404954,
|
||||
};
|
||||
|
||||
await render(<template><PlaceDetails @place={{place}} /></template>);
|
||||
|
||||
const osmLink = this.element.querySelector(
|
||||
'.meta-info a[href^="https://www.openstreetmap.org/node/12345"]'
|
||||
);
|
||||
assert.ok(osmLink, 'OpenStreetMap link is rendered');
|
||||
assert.strictEqual(
|
||||
osmLink.getAttribute('href'),
|
||||
'https://www.openstreetmap.org/node/12345'
|
||||
);
|
||||
|
||||
assert.dom('button.btn-link').hasText('Add a photo');
|
||||
});
|
||||
|
||||
test('it renders correct search-based OpenStreetMap link for a custom saved place', async function (assert) {
|
||||
class MockMapUi extends Service {
|
||||
currentCenter = { lat: 52.5, lon: 13.4 };
|
||||
currentZoom = 15.6;
|
||||
}
|
||||
this.owner.register('service:map-ui', MockMapUi);
|
||||
|
||||
const place = {
|
||||
title: 'Custom Place',
|
||||
lat: 52.520008,
|
||||
lon: 13.404954,
|
||||
};
|
||||
|
||||
await render(<template><PlaceDetails @place={{place}} /></template>);
|
||||
|
||||
const osmLink = this.element.querySelector(
|
||||
'.meta-info a[href^="https://www.openstreetmap.org/search"]'
|
||||
);
|
||||
assert.ok(osmLink, 'OpenStreetMap search link is rendered');
|
||||
assert.strictEqual(
|
||||
osmLink.getAttribute('href'),
|
||||
'https://www.openstreetmap.org/search?lat=52.520008&lon=13.404954&zoom=16#map=16/52.50000/13.40000'
|
||||
);
|
||||
|
||||
assert.dom('button.btn-link').doesNotExist();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
||||
import { render, click, triggerEvent } from '@ember/test-helpers';
|
||||
import Service from '@ember/service';
|
||||
import PlacePhotoUpload from 'marco/components/place-photo-upload';
|
||||
|
||||
module('Integration | Component | place-photo-upload', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
class MockNostrAuthService extends Service {
|
||||
get isConnected() {
|
||||
return true;
|
||||
}
|
||||
|
||||
get signer() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.owner.register('service:nostrAuth', MockNostrAuthService);
|
||||
});
|
||||
|
||||
async function selectFile(element, file) {
|
||||
const input = element.querySelector('#photo-upload-input');
|
||||
Object.defineProperty(input, 'files', {
|
||||
value: [file],
|
||||
configurable: true,
|
||||
});
|
||||
await triggerEvent(input, 'change');
|
||||
}
|
||||
|
||||
test('it shows tag suggestions when they exist after upload selection', async function (assert) {
|
||||
this.place = {
|
||||
title: 'Cafe Alpha',
|
||||
osmId: '123',
|
||||
osmType: 'node',
|
||||
osmTags: { amenity: 'cafe' },
|
||||
};
|
||||
|
||||
await render(
|
||||
<template><PlacePhotoUpload @place={{this.place}} /></template>
|
||||
);
|
||||
|
||||
assert.dom('.photo-tag-suggestions').doesNotExist();
|
||||
|
||||
const file = new File(['test'], 'photo.jpg', { type: 'image/jpeg' });
|
||||
await selectFile(this.element, file);
|
||||
|
||||
assert.dom('.photo-tag-suggestions').exists();
|
||||
assert.dom('.photo-tag-chip').exists();
|
||||
assert.dom('.photo-tag-chip').includesText('Food');
|
||||
});
|
||||
|
||||
test('it only allows one selected tag at a time', async function (assert) {
|
||||
this.place = {
|
||||
title: 'Cafe Alpha',
|
||||
osmId: '123',
|
||||
osmType: 'node',
|
||||
osmTags: { amenity: 'cafe' },
|
||||
};
|
||||
|
||||
await render(
|
||||
<template><PlacePhotoUpload @place={{this.place}} /></template>
|
||||
);
|
||||
|
||||
const file = new File(['test'], 'photo.jpg', { type: 'image/jpeg' });
|
||||
await selectFile(this.element, file);
|
||||
|
||||
const chips = this.element.querySelectorAll('.photo-tag-chip');
|
||||
assert.ok(chips.length > 1, 'multiple tag chips are rendered');
|
||||
|
||||
await click(chips[0]);
|
||||
assert.dom('.photo-tag-chip.is-selected').exists({ count: 1 });
|
||||
assert.dom(chips[0]).hasClass('is-selected');
|
||||
|
||||
await click(chips[1]);
|
||||
assert.dom('.photo-tag-chip.is-selected').exists({ count: 1 });
|
||||
assert.dom(chips[1]).hasClass('is-selected');
|
||||
assert.dom(chips[0]).doesNotHaveClass('is-selected');
|
||||
});
|
||||
|
||||
test('it hides tag suggestions when no tags are suggested', async function (assert) {
|
||||
this.place = {
|
||||
title: 'Office Beta',
|
||||
osmId: '456',
|
||||
osmType: 'node',
|
||||
osmTags: { office: 'lawyer' },
|
||||
};
|
||||
|
||||
await render(
|
||||
<template><PlacePhotoUpload @place={{this.place}} /></template>
|
||||
);
|
||||
|
||||
const file = new File(['test'], 'photo.jpg', { type: 'image/jpeg' });
|
||||
await selectFile(this.element, file);
|
||||
|
||||
assert.dom('.photo-tag-suggestions').doesNotExist();
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
||||
import { render, fillIn, click, waitFor } from '@ember/test-helpers';
|
||||
import { render, fillIn, click, waitFor, focus } from '@ember/test-helpers';
|
||||
import SearchBox from 'marco/components/search-box';
|
||||
import Service from '@ember/service';
|
||||
|
||||
@@ -208,22 +208,301 @@ module('Integration | Component | search-box', function (hooks) {
|
||||
);
|
||||
|
||||
// Type "Resta" to trigger "Restaurants" category match
|
||||
await focus('.search-input');
|
||||
await fillIn('.search-input', 'Resta');
|
||||
|
||||
// Wait for debounce (300ms) + execution
|
||||
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
await delay(400);
|
||||
await waitFor('.search-result-item');
|
||||
|
||||
// The first result should be the category match
|
||||
assert.dom('.search-result-item').exists({ count: 1 });
|
||||
assert.dom('.result-title').hasText('Restaurants');
|
||||
const resultItems = Array.from(
|
||||
this.element.querySelectorAll('.search-result-item')
|
||||
);
|
||||
const categoryResult = resultItems.find((item) =>
|
||||
item.textContent.includes('Restaurants')
|
||||
);
|
||||
|
||||
assert.ok(categoryResult, 'Restaurants category result is shown');
|
||||
|
||||
// Click the result
|
||||
await click('.search-result-item');
|
||||
await click(categoryResult);
|
||||
|
||||
// Assert transition with lat/lon from map center
|
||||
assert.verifySteps([
|
||||
'transitionTo: search {"queryParams":{"q":"Restaurants","category":"restaurants","selected":null,"lat":"51.5074","lon":"-0.1278"}}',
|
||||
]);
|
||||
});
|
||||
|
||||
test('it includes, deduplicates, and prioritizes saved places in search results', async function (assert) {
|
||||
// Mock MapUi Service
|
||||
class MockMapUiService extends Service {
|
||||
currentCenter = { lat: 52.52, lon: 13.405 };
|
||||
setSearchBoxFocus() {}
|
||||
}
|
||||
this.owner.register('service:map-ui', MockMapUiService);
|
||||
|
||||
// Mock Router Service
|
||||
class MockRouterService extends Service {
|
||||
transitionTo(routeName, id) {
|
||||
assert.step(`transitionTo: ${routeName} ["${id}"]`);
|
||||
}
|
||||
}
|
||||
this.owner.register('service:router', MockRouterService);
|
||||
|
||||
// Mock Storage Service
|
||||
class MockStorageService extends Service {
|
||||
lists = [{ id: 'favs', title: 'Favorites' }];
|
||||
savedPlaces = [
|
||||
{
|
||||
title: 'Awesome Coffee',
|
||||
lat: 52.5,
|
||||
lon: 13.4,
|
||||
osmId: '999',
|
||||
osmType: 'node',
|
||||
_listIds: ['favs'],
|
||||
},
|
||||
];
|
||||
}
|
||||
this.owner.register('service:storage', MockStorageService);
|
||||
|
||||
// Mock Photon Service
|
||||
class MockPhotonService extends Service {
|
||||
async search(query) {
|
||||
if (query === 'coffee') {
|
||||
return [
|
||||
{
|
||||
title: 'Awesome Coffee',
|
||||
osmId: '999',
|
||||
osmType: 'node',
|
||||
description: 'Duplicate to be removed',
|
||||
},
|
||||
{
|
||||
title: 'Other Coffee',
|
||||
osmId: '888',
|
||||
osmType: 'node',
|
||||
description: 'A different coffee shop',
|
||||
},
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
this.owner.register('service:photon', MockPhotonService);
|
||||
|
||||
this.noop = () => {};
|
||||
await render(
|
||||
<template><SearchBox @onToggleMenu={{this.noop}} /></template>
|
||||
);
|
||||
|
||||
// Type "coffee" to trigger matches in Category, Saved, and Photon
|
||||
await fillIn('.search-input', 'coffee');
|
||||
await waitFor('.search-results-popover', { timeout: 2000 });
|
||||
|
||||
const resultItems = Array.from(
|
||||
this.element.querySelectorAll('.search-result-item')
|
||||
);
|
||||
|
||||
// Should be exactly 3 items:
|
||||
// 1. Category (Coffee)
|
||||
// 2. Saved (Awesome Coffee)
|
||||
// 3. Photon (Other Coffee)
|
||||
// (The Photon duplicate of "Awesome Coffee" is removed)
|
||||
assert.strictEqual(resultItems.length, 3, 'Renders exactly 3 items');
|
||||
|
||||
// 1. Category
|
||||
assert.ok(
|
||||
resultItems[0].textContent.includes('Coffee'),
|
||||
'First item is the category match'
|
||||
);
|
||||
assert
|
||||
.dom(resultItems[0].querySelector('.result-icon svg'))
|
||||
.hasClass('feather-search', 'Category uses search icon');
|
||||
|
||||
// 2. Saved Place
|
||||
assert.ok(
|
||||
resultItems[1].textContent.includes('Awesome Coffee'),
|
||||
'Second item is the saved place match'
|
||||
);
|
||||
assert.ok(
|
||||
resultItems[1].textContent.includes('Saved place'),
|
||||
'Saved place has correct description text'
|
||||
);
|
||||
assert
|
||||
.dom(resultItems[1].querySelector('.result-icon svg'))
|
||||
.hasClass('feather-bookmark', 'Saved place uses bookmark icon');
|
||||
|
||||
// 3. Photon Match
|
||||
assert.ok(
|
||||
resultItems[2].textContent.includes('Other Coffee'),
|
||||
'Third item is the unique photon result'
|
||||
);
|
||||
|
||||
// Click the Saved Place
|
||||
await click(resultItems[1]);
|
||||
|
||||
assert.verifySteps(['transitionTo: place ["osm:node:999"]']);
|
||||
});
|
||||
|
||||
test('it requires 3 or more characters to match saved places', async function (assert) {
|
||||
// Mock MapUi Service
|
||||
class MockMapUiService extends Service {
|
||||
currentCenter = { lat: 52.52, lon: 13.405 };
|
||||
setSearchBoxFocus() {}
|
||||
}
|
||||
this.owner.register('service:map-ui', MockMapUiService);
|
||||
|
||||
// Mock Router Service
|
||||
class MockRouterService extends Service {
|
||||
transitionTo() {}
|
||||
}
|
||||
this.owner.register('service:router', MockRouterService);
|
||||
|
||||
// Mock Storage Service
|
||||
class MockStorageService extends Service {
|
||||
lists = [{ id: 'favs', title: 'Favorites' }];
|
||||
savedPlaces = [
|
||||
{
|
||||
title: 'Awesome Coffee',
|
||||
lat: 52.5,
|
||||
lon: 13.4,
|
||||
osmId: '999',
|
||||
osmType: 'node',
|
||||
_listIds: ['favs'],
|
||||
},
|
||||
];
|
||||
}
|
||||
this.owner.register('service:storage', MockStorageService);
|
||||
|
||||
// Mock Photon Service
|
||||
class MockPhotonService extends Service {
|
||||
async search(query) {
|
||||
if (query === 'aw' || query === 'awe') {
|
||||
return [
|
||||
{
|
||||
title: 'Aww Some Place',
|
||||
osmId: '111',
|
||||
osmType: 'node',
|
||||
},
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
this.owner.register('service:photon', MockPhotonService);
|
||||
|
||||
this.noop = () => {};
|
||||
await render(
|
||||
<template><SearchBox @onToggleMenu={{this.noop}} /></template>
|
||||
);
|
||||
|
||||
// Type "aw" (2 characters)
|
||||
await fillIn('.search-input', 'aw');
|
||||
await waitFor('.search-results-popover', { timeout: 2000 });
|
||||
|
||||
let resultItems = Array.from(
|
||||
this.element.querySelectorAll('.search-result-item')
|
||||
);
|
||||
|
||||
// Should only show Photon match since 'aw' is < 3 characters
|
||||
assert.strictEqual(
|
||||
resultItems.length,
|
||||
1,
|
||||
'Renders exactly 1 item for 2 chars'
|
||||
);
|
||||
assert.ok(
|
||||
resultItems[0].textContent.includes('Aww Some Place'),
|
||||
'Shows photon match'
|
||||
);
|
||||
assert.notOk(
|
||||
resultItems.some((item) => item.textContent.includes('Awesome Coffee')),
|
||||
'Saved place is NOT shown for 2 char query'
|
||||
);
|
||||
|
||||
// Type "awe" (3 characters)
|
||||
await fillIn('.search-input', 'awe');
|
||||
await waitFor('.search-results-popover', { timeout: 2000 });
|
||||
|
||||
resultItems = Array.from(
|
||||
this.element.querySelectorAll('.search-result-item')
|
||||
);
|
||||
|
||||
// Should now show Saved Place and Photon match
|
||||
assert.strictEqual(
|
||||
resultItems.length,
|
||||
2,
|
||||
'Renders exactly 2 items for 3 chars'
|
||||
);
|
||||
assert.ok(
|
||||
resultItems.some((item) => item.textContent.includes('Awesome Coffee')),
|
||||
'Saved place is now shown'
|
||||
);
|
||||
assert.ok(
|
||||
resultItems.some((item) =>
|
||||
item.textContent.includes('Saved place (Favorites)')
|
||||
),
|
||||
'List names are appended to the description'
|
||||
);
|
||||
});
|
||||
|
||||
test('it navigates to internal ID for custom saved places without an OSM ID', async function (assert) {
|
||||
// Mock MapUi Service
|
||||
class MockMapUiService extends Service {
|
||||
currentCenter = { lat: 52.52, lon: 13.405 };
|
||||
setSearchBoxFocus() {}
|
||||
}
|
||||
this.owner.register('service:map-ui', MockMapUiService);
|
||||
|
||||
// Mock Router Service
|
||||
class MockRouterService extends Service {
|
||||
transitionTo(routeName, id) {
|
||||
assert.step(`transitionTo: ${routeName} ["${id}"]`);
|
||||
}
|
||||
}
|
||||
this.owner.register('service:router', MockRouterService);
|
||||
|
||||
// Mock Storage Service (Custom Place)
|
||||
class MockStorageService extends Service {
|
||||
savedPlaces = [
|
||||
{
|
||||
id: 'custom-1234',
|
||||
title: 'My Custom Home',
|
||||
lat: 52.5,
|
||||
lon: 13.4,
|
||||
// Notice NO osmId or osmType
|
||||
},
|
||||
];
|
||||
}
|
||||
this.owner.register('service:storage', MockStorageService);
|
||||
|
||||
// Mock Photon Service
|
||||
class MockPhotonService extends Service {
|
||||
async search() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
this.owner.register('service:photon', MockPhotonService);
|
||||
|
||||
this.noop = () => {};
|
||||
await render(
|
||||
<template><SearchBox @onToggleMenu={{this.noop}} /></template>
|
||||
);
|
||||
|
||||
// Type 3 chars to trigger saved place match
|
||||
await fillIn('.search-input', 'cus');
|
||||
await waitFor('.search-results-popover', { timeout: 2000 });
|
||||
|
||||
const resultItems = Array.from(
|
||||
this.element.querySelectorAll('.search-result-item')
|
||||
);
|
||||
|
||||
// Ensure our custom place is rendered
|
||||
const customResult = resultItems.find((item) =>
|
||||
item.textContent.includes('My Custom Home')
|
||||
);
|
||||
assert.ok(customResult, 'Custom place is rendered');
|
||||
|
||||
// Click it
|
||||
await click(customResult);
|
||||
|
||||
// Verify it navigated using the internal ID, NOT a search query
|
||||
assert.verifySteps(['transitionTo: place ["custom-1234"]']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,6 +36,8 @@ module('Unit | Route | place', function (hooks) {
|
||||
selectPlaceCalled = true;
|
||||
}
|
||||
stopSearch() {}
|
||||
showSidebar() {}
|
||||
hideSidebar() {}
|
||||
}
|
||||
|
||||
this.owner.register('service:osm', OsmStub);
|
||||
@@ -76,6 +78,8 @@ module('Unit | Route | place', function (hooks) {
|
||||
class MapUiStub extends Service {
|
||||
selectPlace() {}
|
||||
stopSearch() {}
|
||||
showSidebar() {}
|
||||
hideSidebar() {}
|
||||
}
|
||||
|
||||
this.owner.register('service:osm', OsmStub);
|
||||
@@ -110,6 +114,8 @@ module('Unit | Route | place', function (hooks) {
|
||||
class MapUiStub extends Service {
|
||||
selectPlace() {}
|
||||
stopSearch() {}
|
||||
showSidebar() {}
|
||||
hideSidebar() {}
|
||||
}
|
||||
|
||||
this.owner.register('service:osm', OsmStub);
|
||||
@@ -155,6 +161,8 @@ module('Unit | Route | place', function (hooks) {
|
||||
assert.ok(options.preventZoom, 'Prevented zoom on update');
|
||||
}
|
||||
stopSearch() {}
|
||||
showSidebar() {}
|
||||
hideSidebar() {}
|
||||
}
|
||||
|
||||
this.owner.register('service:storage', StorageStub);
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
import { module, test } from 'qunit';
|
||||
import {
|
||||
excludeRequiredRelays,
|
||||
mergeRequiredRelays,
|
||||
normalizeRelayUrl,
|
||||
parsePlacePhotos,
|
||||
uniqNormalizedRelays,
|
||||
} from 'marco/utils/nostr';
|
||||
|
||||
module('Unit | Utility | nostr', function () {
|
||||
test('normalizeRelayUrl normalizes protocol, case, and slashes', function (assert) {
|
||||
assert.strictEqual(normalizeRelayUrl(null), '');
|
||||
assert.strictEqual(normalizeRelayUrl(''), '');
|
||||
assert.strictEqual(normalizeRelayUrl(' '), '');
|
||||
|
||||
assert.strictEqual(
|
||||
normalizeRelayUrl('Relay.example.com'),
|
||||
'wss://relay.example.com'
|
||||
);
|
||||
assert.strictEqual(
|
||||
normalizeRelayUrl('ws://Relay.example.com/'),
|
||||
'ws://relay.example.com'
|
||||
);
|
||||
assert.strictEqual(
|
||||
normalizeRelayUrl('wss://relay.example.com///'),
|
||||
'wss://relay.example.com'
|
||||
);
|
||||
});
|
||||
|
||||
test('parsePlacePhotos includes event t tags on photo objects', function (assert) {
|
||||
const events = [
|
||||
{
|
||||
id: 'event-1',
|
||||
pubkey: 'pubkey-1',
|
||||
created_at: 123,
|
||||
tags: [
|
||||
['i', 'osm:node:123'],
|
||||
['t', 'food'],
|
||||
['t', 'vibe'],
|
||||
['imeta', 'url https://example.com/photo.jpg', 'dim 800x600'],
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const photos = parsePlacePhotos(events);
|
||||
|
||||
assert.strictEqual(photos.length, 1);
|
||||
assert.deepEqual(photos[0].tags, ['food', 'vibe']);
|
||||
});
|
||||
|
||||
test('parsePlacePhotos sorts by created_at', function (assert) {
|
||||
const events = [
|
||||
{
|
||||
id: 'event-2',
|
||||
pubkey: 'pubkey-2',
|
||||
created_at: 200,
|
||||
tags: [
|
||||
['i', 'osm:node:456'],
|
||||
['imeta', 'url https://example.com/late.jpg', 'dim 600x900'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'event-1',
|
||||
pubkey: 'pubkey-1',
|
||||
created_at: 100,
|
||||
tags: [
|
||||
['i', 'osm:node:123'],
|
||||
['imeta', 'url https://example.com/early.jpg', 'dim 600x900'],
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const photos = parsePlacePhotos(events);
|
||||
|
||||
assert.strictEqual(photos.length, 2);
|
||||
assert.strictEqual(photos[0].url, 'https://example.com/early.jpg');
|
||||
assert.strictEqual(photos[1].url, 'https://example.com/late.jpg');
|
||||
});
|
||||
|
||||
test('parsePlacePhotos promotes first landscape photo to index 0', function (assert) {
|
||||
const events = [
|
||||
{
|
||||
id: 'event-1',
|
||||
pubkey: 'pubkey-1',
|
||||
created_at: 100,
|
||||
tags: [
|
||||
['imeta', 'url https://example.com/portrait.jpg', 'dim 600x900'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'event-2',
|
||||
pubkey: 'pubkey-2',
|
||||
created_at: 200,
|
||||
tags: [
|
||||
['imeta', 'url https://example.com/landscape.jpg', 'dim 1200x600'],
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const photos = parsePlacePhotos(events);
|
||||
|
||||
assert.strictEqual(photos.length, 2);
|
||||
assert.strictEqual(photos[0].url, 'https://example.com/landscape.jpg');
|
||||
assert.strictEqual(photos[1].url, 'https://example.com/portrait.jpg');
|
||||
});
|
||||
|
||||
test('parsePlacePhotos skips imeta entries without urls', function (assert) {
|
||||
const events = [
|
||||
{
|
||||
id: 'event-1',
|
||||
pubkey: 'pubkey-1',
|
||||
created_at: 100,
|
||||
tags: [['imeta', 'dim 800x600']],
|
||||
},
|
||||
];
|
||||
|
||||
const photos = parsePlacePhotos(events);
|
||||
|
||||
assert.deepEqual(photos, []);
|
||||
});
|
||||
|
||||
test('parsePlacePhotos returns one photo per event imeta tag', function (assert) {
|
||||
const events = [
|
||||
{
|
||||
id: 'event-1',
|
||||
pubkey: 'pubkey-1',
|
||||
created_at: 100,
|
||||
tags: [
|
||||
['i', 'osm:node:123'],
|
||||
['imeta', 'url https://example.com/photo-1.jpg', 'dim 800x600'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'event-2',
|
||||
pubkey: 'pubkey-2',
|
||||
created_at: 200,
|
||||
tags: [
|
||||
['i', 'osm:node:456'],
|
||||
['imeta', 'url https://example.com/photo-2.jpg', 'dim 600x800'],
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const photos = parsePlacePhotos(events);
|
||||
|
||||
assert.strictEqual(photos.length, 2);
|
||||
assert.strictEqual(photos[0].placeIdentifier, 'osm:node:123');
|
||||
assert.strictEqual(photos[1].placeIdentifier, 'osm:node:456');
|
||||
});
|
||||
|
||||
test('uniqNormalizedRelays returns normalized unique relays', function (assert) {
|
||||
const relays = uniqNormalizedRelays([
|
||||
'Relay.example.com',
|
||||
'wss://relay.example.com/',
|
||||
'wss://other.example.com',
|
||||
]);
|
||||
|
||||
assert.deepEqual(relays, [
|
||||
'wss://relay.example.com',
|
||||
'wss://other.example.com',
|
||||
]);
|
||||
});
|
||||
|
||||
test('mergeRequiredRelays keeps required relays as-is and merges normalized custom relays', function (assert) {
|
||||
const relays = mergeRequiredRelays(
|
||||
['wss://required.example.com', 'required-2.example.com'],
|
||||
['required-2.example.com/', 'wss://custom.example.com']
|
||||
);
|
||||
|
||||
assert.deepEqual(relays, [
|
||||
'wss://required.example.com',
|
||||
'required-2.example.com',
|
||||
'wss://required-2.example.com',
|
||||
'wss://custom.example.com',
|
||||
]);
|
||||
});
|
||||
|
||||
test('excludeRequiredRelays removes required relays from normalized custom list', function (assert) {
|
||||
const relays = excludeRequiredRelays(
|
||||
[
|
||||
'wss://required.example.com',
|
||||
'custom.example.com',
|
||||
'ws://custom2.example.com',
|
||||
],
|
||||
['wss://required.example.com']
|
||||
);
|
||||
|
||||
assert.deepEqual(relays, [
|
||||
'wss://custom.example.com',
|
||||
'ws://custom2.example.com',
|
||||
]);
|
||||
});
|
||||
|
||||
test('excludeRequiredRelays trusts required list without normalizing it', function (assert) {
|
||||
const relays = excludeRequiredRelays(
|
||||
['Required.example.com', 'custom.example.com'],
|
||||
['required.example.com']
|
||||
);
|
||||
|
||||
assert.deepEqual(relays, [
|
||||
'wss://required.example.com',
|
||||
'wss://custom.example.com',
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getIconNameForTags } from 'marco/utils/osm-icons';
|
||||
import { getIconNameForTags, POI_ICON_RULES } from 'marco/utils/osm-icons';
|
||||
import { getIcon } from 'marco/utils/icons';
|
||||
import { module, test } from 'qunit';
|
||||
|
||||
module('Unit | Utility | osm-icons', function () {
|
||||
@@ -36,4 +37,14 @@ module('Unit | Utility | osm-icons', function () {
|
||||
let result = getIconNameForTags({ foo: 'bar' });
|
||||
assert.strictEqual(result, null);
|
||||
});
|
||||
|
||||
test('all icons used in POI_ICON_RULES exist in the icons utility', function (assert) {
|
||||
for (let rule of POI_ICON_RULES) {
|
||||
let icon = getIcon(rule.icon);
|
||||
assert.ok(
|
||||
icon,
|
||||
`Icon "${rule.icon}" specified in POI_ICON_RULES should be imported and available in getIcon`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,6 +89,12 @@ module('Unit | Utility | osm', function (hooks) {
|
||||
assert.strictEqual(result, 'Building');
|
||||
});
|
||||
|
||||
test('getPlaceType ignores generic "yes" values if a more specific tag is present', function (assert) {
|
||||
const tags = { historic: 'yes', building: 'tower' };
|
||||
const result = getPlaceType(tags);
|
||||
assert.strictEqual(result, 'Tower');
|
||||
});
|
||||
|
||||
test('getPlaceType prioritizes order (amenity > shop > building)', function (assert) {
|
||||
// If something is both a shop and a building, it should be a shop
|
||||
const tags = { building: 'yes', shop: 'supermarket' };
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { POI_CATEGORIES } from 'marco/utils/poi-categories';
|
||||
import { getMatchingPoiCategoryIds } from 'marco/utils/poi-category-matcher';
|
||||
import {
|
||||
getSuggestedPhotoTags,
|
||||
CATEGORY_TAGS,
|
||||
} from 'marco/utils/photo-tag-suggestions';
|
||||
|
||||
module('Unit | Utility | photo-tag-suggestions', function () {
|
||||
test('returns tags for all matching categories with de-duplication', function (assert) {
|
||||
const place = { osmTags: { amenity: 'cafe' } };
|
||||
const categoryIds = getMatchingPoiCategoryIds(
|
||||
place.osmTags,
|
||||
POI_CATEGORIES
|
||||
);
|
||||
|
||||
assert.ok(categoryIds.includes('restaurants'));
|
||||
assert.ok(categoryIds.includes('coffee'));
|
||||
|
||||
const result = getSuggestedPhotoTags(place);
|
||||
assert.deepEqual(result, CATEGORY_TAGS.restaurants);
|
||||
});
|
||||
|
||||
test('returns no tags when no category matches', function (assert) {
|
||||
const place = { osmTags: { office: 'lawyer' } };
|
||||
const result = getSuggestedPhotoTags(place);
|
||||
|
||||
assert.deepEqual(result, []);
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user