Commit c10818b0 authored by Sandro Lutz's avatar Sandro Lutz Committed by Sandro Lutz
Browse files

Fix wrong menu rendering (Resolves #43)

parent 46f13d9c
...@@ -8,7 +8,15 @@ import { currentLanguage } from './language'; ...@@ -8,7 +8,15 @@ import { currentLanguage } from './language';
*/ */
export default class Navigation { export default class Navigation {
constructor(items) { constructor(items) {
this._items = items; this._items = items.map(item => {
const newItem = Object.assign({}, item);
if (newItem.addLanguagePrefix) {
newItem.getLink = addLanguagePrefix => Navigation._getLink(newItem.path, addLanguagePrefix);
} else {
newItem.getLink = () => newItem.path;
}
return newItem;
});
} }
get items() { get items() {
...@@ -36,10 +44,17 @@ export default class Navigation { ...@@ -36,10 +44,17 @@ export default class Navigation {
this._selectedIndex = this._checkMenuItemSelection(); this._selectedIndex = this._checkMenuItemSelection();
} }
static _getLink(path, addLanguagePrefix = true) {
if (addLanguagePrefix) {
return `/${currentLanguage()}${path}`;
}
return path;
}
_checkMenuItemSelection() { _checkMenuItemSelection() {
let selectedIndex; let selectedIndex;
this._items.forEach((item, index) => { this._items.forEach((item, index) => {
const link = item.getLink(); const link = item.getLink(false);
if ( if (
(link.length <= 4 && m.route.get() === link) || (link.length <= 4 && m.route.get() === link) ||
(link.length > 4 && m.route.get().includes(link)) || (link.length > 4 && m.route.get().includes(link)) ||
...@@ -56,59 +71,70 @@ export default class Navigation { ...@@ -56,59 +71,70 @@ export default class Navigation {
export const mainNavigation = new Navigation([ export const mainNavigation = new Navigation([
{ {
label: 'AMIV', label: 'AMIV',
getLink: () => `/${currentLanguage()}/about`, path: '/about',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
submenu: new Navigation([ submenu: new Navigation([
{ {
label: 'About AMIV', label: 'About AMIV',
getLink: () => `/${currentLanguage()}/about`, path: '/about',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
{ {
label: 'Board', label: 'Board',
getLink: () => `/${currentLanguage()}/board`, path: '/board',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
{ {
label: 'Commissions', label: 'Commissions',
getLink: () => `/${currentLanguage()}/commissions`, path: '/commissions',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
{ {
label: 'Statutes', label: 'Statutes',
getLink: () => `/${currentLanguage()}/statutes`, path: '/statutes',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
{ {
label: 'Minutes', label: 'Minutes',
getLink: () => `/${currentLanguage()}/minutes`, path: '/minutes',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
]), ]),
}, },
{ {
label: 'Events', label: 'Events',
getLink: () => `/${currentLanguage()}/events`, path: '/events',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
{ {
label: 'Studydocuments', label: 'Studydocuments',
getLink: () => `/${currentLanguage()}/studydocuments`, path: '/studydocuments',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
{ {
label: 'Jobs', label: 'Jobs',
getLink: () => `/${currentLanguage()}/jobs`, path: '/jobs',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
submenu: new Navigation([ submenu: new Navigation([
{ {
label: 'Jobs', label: 'Jobs',
getLink: () => `/${currentLanguage()}/jobs`, path: '/jobs',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
{ {
label: 'Companies', label: 'Companies',
getLink: () => `/${currentLanguage()}/companies`, path: '/companies',
addLanguagePrefix: true,
onupdate: m.route.link, onupdate: m.route.link,
}, },
]), ]),
......
...@@ -230,12 +230,6 @@ header { ...@@ -230,12 +230,6 @@ header {
} }
} }
} }
// @media @mobile {
// display: grid;
// grid-template-columns: .5fr .5fr;
// text-align: center;
// }
} }
.language-switcher { .language-switcher {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment