All files / src/BaseBar BaseSideBar.vue.js

70.58% Statements 12/17
30% Branches 3/10
70% Functions 7/10
75% Lines 12/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68              1x                           2x         2x         2x   2x   1x 1x                           2x 2x 2x 2x         2x                  
// @ts-check
 
import Vue from "vue";
import { filter, get, isFunction } from "lodash";
import MatchMedia from "../BaseMatchMedia";
import { BaseStoreMixin } from "../store/utils";
 
const component = /** @type {V.Constructor<any, any> } */ (Vue).extend({
  name: "BaseSideBar",
  mixins: [ BaseStoreMixin ],
  props: {
    showRoutes: { type: Boolean, default: true },
    showAbout: { type: Boolean, default: false }
  },
  /**
   * @returns {{
   *   media?: ?MatchMedia,
   *   hidden: boolean,
   *   absolute: boolean
   *  }}
   */
  data() { return { absolute: true, hidden: false }; },
  computed: {
    /**
     * @return {boolean}
     */
    darkMode() { return this.getBaseState([ "ui", "darkMode" ]); },
    /** @return {boolean} */
    isAdmin() { return get(this.$route, [ "meta", "isAdmin" ], false); },
    /** @return {any[]} */
    navRoutes() {
      Iif (!this.showRoutes) { return []; }
      else {
        return filter(get(this.$router, [ "options", "routes" ]),
          (r) => {
            const nav = get(r, "meta.navbar", true);
            return (isFunction(nav)) ? nav(this) : nav;
          });
      }
    }
  },
  watch: {
    "$route.name": function() {
      /* hide nav if toggler is visible and displayed */
      if (this.absolute && !this.hidden) {
        this.hidden = true;
      }
    }
  },
  mounted() {
    this.media = new MatchMedia(MatchMedia.LG, (/** @type {boolean} */ value) => {
      this.absolute = !value;
      Eif (this.absolute) {
        this.hidden = true;
      }
    });
  },
  beforeDestroy() {
    /** @type {MatchMedia} */ (this.media).close();
  },
  methods: {
    toggle() {
      this.hidden = !this.hidden;
    }
  }
});
export default component;