From a585120d51cd02a22d2a42d0f7154e516fb11b52 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 12 Jan 2016 19:44:18 +0000 Subject: [PATCH] Refactor some of the breadcrumb code --- static/src/js/components/breadcrumbs.js | 27 +++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/static/src/js/components/breadcrumbs.js b/static/src/js/components/breadcrumbs.js index 1224430..294feb5 100644 --- a/static/src/js/components/breadcrumbs.js +++ b/static/src/js/components/breadcrumbs.js @@ -1,33 +1,26 @@ import React from 'react'; -let { - Breadcrumb, - BreadcrumbItem -} = require('react-bootstrap'); - export default class Breadcrumbs extends React.Component { + constructor() { + super(); + this.urlParts = Object.freeze(location.pathname.split('/').slice(1, -1)); + } + render() { - const parts = location.pathname.split('/').slice(1, -1); var elements = []; - for (var i = 0; i < parts.length; i++) { + for (var i = 0; i < this.urlParts.length; i++) { var dirs = []; for (var j = 0; j <= i; j++) { - dirs.push(parts[j]); + dirs.push(this.urlParts[j]); } - if (i === (parts.length - 1)) { + if (i === (this.urlParts.length - 1)) { elements.push( -
  • - {parts[i]} -
  • +
  • {this.urlParts[i]}
  • ); } else { var url = '/' + dirs.join('/') + '/'; elements.push( -
  • - - {parts[i]} - -
  • +
  • {this.urlParts[i]}
  • ); } }