Skip to content

Commit

Permalink
fix: error loading non-visible mode
Browse files Browse the repository at this point in the history
Fixes #426
  • Loading branch information
arildm committed Jan 27, 2025
1 parent e4fa180 commit cc282a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- Result tab progress bars grow smoothly and are shown even when only one corpus is selected
- Removed old test code

### Fixed

- Error when loading a non-`visible_modes` mode [#426](https://github.com/spraakbanken/korp-frontend/issues/426)

## [9.8.1] - 2025-01-23

### Fixed
Expand Down
19 changes: 10 additions & 9 deletions app/scripts/components/app-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ angular.module("korpApp").component("appHeader", {
<div class="flex items-center justify-between px-3 py-2" id="top_bar">
<ul id="mode_switch">
<li class="visible" ng-repeat="mode in $ctrl.visible" ng-class="{selected: mode.selected}">
<a ng-href="{{$ctrl.getUrl(mode.mode)}}"> {{mode.label | locObj:lang}}</a>
<a ng-href="{{$ctrl.getUrl(mode.mode)}}"> {{mode.label | locObj:$oot.lang}}</a>
</li>
<li class="menu_more visible" ng-if="$ctrl.menu.length" uib-dropdown>
<a uib-dropdown-toggle>
Expand All @@ -50,7 +50,7 @@ angular.module("korpApp").component("appHeader", {
<ul uib-dropdown-menu>
<li ng-repeat="mode in $ctrl.menu" ng-class="{selected: mode.selected}">
<a ng-href="{{$ctrl.getUrl(mode.mode)}}"> {{mode.label | locObj:lang}}</a>
<a ng-href="{{$ctrl.getUrl(mode.mode)}}"> {{mode.label | locObj:$root.lang}}</a>
</li>
</ul>
</li>
Expand Down Expand Up @@ -235,17 +235,18 @@ angular.module("korpApp").component("appHeader", {
$ctrl.modes = _.filter(settings["modes"], (item) => !item.labOnly)
}

// Split modes into visible and menu
$ctrl.visible = $ctrl.modes.slice(0, N_VISIBLE)
$ctrl.menu = $ctrl.modes.slice(N_VISIBLE)

// If current mode is in menu, promote it to visible
const modesInMenu = _.remove($ctrl.menu, (item) => item.mode == currentMode)
$ctrl.visible.push(...modesInMenu)

$rootScope.$watch("lang", () => {
$scope.lang = $rootScope.lang
$ctrl.menu = collatorSort($ctrl.modes.slice(N_VISIBLE), "label", $rootScope.lang)

const i = _.map($ctrl.menu, "mode").indexOf(currentMode)
if (i !== -1) {
$ctrl.visible.push($ctrl.menu[i])
$ctrl.menu.splice(i, 1)
}
// Re-sort menu but not visible options
$ctrl.menu = collatorSort($ctrl.menu, "label", $rootScope.lang)
})

$ctrl.getUrl = function (modeId) {
Expand Down

0 comments on commit cc282a3

Please sign in to comment.