Ghost/ghost/admin/app/components/gh-tenor.js
Kevin Ansfield 6853b964f8 First iteration of gifs image selector + card
refs https://github.com/TryGhost/Team/issues/1217

- adds `tenor` service that acts as a coordinator for the Tenor API similar to the `unsplash` service
- adds `<GhTenor>` component that renders an image search and select modal using the `tenor` service
- swapped the gifs card over to use the `tenor` image selector so it opens the tenor modal instead of the unsplash modal
2021-11-12 16:10:26 +00:00

64 lines
1.4 KiB
JavaScript

import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {tracked} from '@glimmer/tracking';
export default class GhTenorComponent extends Component {
@service tenor;
@tracked zoomedGif;
@action
search(event) {
const term = event.target.value;
this.tenor.updateSearch(term);
this.closeZoom();
}
@action
setInitialSearch() {
if (this.args.searchTerm !== this.tenor.searchTerm) {
this.tenor.updateSearch(this.args.searchTerm);
}
}
@action
zoom(gif, event) {
event?.preventDefault();
this.zoomedGif = gif;
}
@action
closeZoom(event) {
event?.preventDefault();
this.zoomedGif = null;
}
@action
select(gif, event) {
event?.preventDefault();
event?.stopPropagation();
const media = gif.media[0].gif;
const selectParams = {
src: media.url,
width: media.dims[0],
height: media.dims[1],
caption: '(Via <a href="https://tenor.com">Tenor</a>)'
};
this.args.select(selectParams);
this.args.close();
}
@action
handleEscape() {
if (this.zoomedGif) {
this.zoomedGif = null;
} else {
this.args.close();
}
}
}