hummingbird-me/kitsu-web

View on GitHub
app/routes/explore/category/more.js

Summary

Maintainability
A
1 hr
Test Coverage
F
0%
import Route from '@ember/routing/route';
import { get, set, setProperties } from '@ember/object';
import { inject as service } from '@ember/service';
import { capitalize } from '@ember/string';

export default Route.extend({
  intl: service(),

  /**
   * Since the page is built using data-driven components, we don't know if this section exists
   * or not. So we don't render a page that is half-broken we redirect if we don't have a
   * translations setup.
   */
  beforeModel() {
    const title = this.titleToken();
    if (title && title.toString().includes('Missing translation')) {
      this.transitionTo('explore.category');
    }
  },

  setupController(controller) {
    this._super(...arguments);
    const { type } = this.paramsFor('explore.category.more');
    const { media_type: mediaType } = this.paramsFor('explore');
    const category = this.modelFor('explore.category');
    setProperties(controller, { type, mediaType, category });
  },

  titleToken() {
    const { type } = this.paramsFor('explore.category.more');
    const { media_type: mediaType } = this.paramsFor('explore');
    const category = this.modelFor('explore.category');
    const title = get(this, 'intl').t(`titles.explore.category.more.${type}`, {
      type: capitalize(mediaType),
      category: get(category, 'title')
    });
    set(this, 'breadcrumb', title);
    return title;
  }
});