Optionally add tag to place photo
This commit is contained in:
@@ -8,6 +8,10 @@ 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 {
|
||||
@@ -22,6 +26,7 @@ export default class PlacePhotoUpload extends Component {
|
||||
@tracked error = '';
|
||||
@tracked isPublishing = false;
|
||||
@tracked isDragging = false;
|
||||
@tracked selectedTags = [];
|
||||
|
||||
get place() {
|
||||
return this.args.place || {};
|
||||
@@ -37,6 +42,10 @@ export default class PlacePhotoUpload extends Component {
|
||||
);
|
||||
}
|
||||
|
||||
get suggestedTags() {
|
||||
return getSuggestedPhotoTags(this.place);
|
||||
}
|
||||
|
||||
@action
|
||||
handleFileSelect(event) {
|
||||
this.addFile(event.target.files[0]);
|
||||
@@ -93,11 +102,22 @@ export default class PlacePhotoUpload extends Component {
|
||||
}
|
||||
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) {
|
||||
@@ -139,6 +159,10 @@ export default class PlacePhotoUpload extends Component {
|
||||
|
||||
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)]);
|
||||
@@ -227,6 +251,26 @@ export default class PlacePhotoUpload extends Component {
|
||||
/>
|
||||
</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"
|
||||
|
||||
Reference in New Issue
Block a user