Skip to content

Commit

Permalink
Refresh search results when sidebar is refreshed, and allow subclasse…
Browse files Browse the repository at this point in the history
…s of BaseSidebarView to choose how much of the UI is refreshed, based on whether the panel changed
  • Loading branch information
rogup committed May 2, 2024
1 parent 3b33ff4 commit a96781c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 56 deletions.
23 changes: 19 additions & 4 deletions src/map-app/app/presenter/sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Dictionary } from '../../common-types';
import { EventBus } from '../../eventbus';
import { MapUI } from '../map-ui';
import { Initiative } from '../model/initiative';
import { SidebarView } from '../view/sidebar';
import { BasePresenter } from './base';
import { AboutSidebarPresenter } from './sidebar/about';
Expand Down Expand Up @@ -63,7 +64,7 @@ export class SidebarPresenter extends BasePresenter {
if (name !== undefined) {
// If name is set, change the current sidebar and then refresh
this.sidebarName = name;
this.children[this.sidebarName]?.refreshView();
this.children[this.sidebarName]?.refreshView(true);
}
else {
// Just refresh the currently showing sidebar.
Expand All @@ -76,11 +77,13 @@ export class SidebarPresenter extends BasePresenter {
return; // No sidebars? Can't do anything.
}

this.children[this.sidebarName]?.refreshView();
this.children[this.sidebarName]?.refreshView(false);
}
}

showSidebar() {
// Refresh the view before showing
this.children[this.sidebarName ?? 'undefined']?.refreshView(true);
this.view.showSidebar();
}

Expand All @@ -97,6 +100,14 @@ export class SidebarPresenter extends BasePresenter {
this.view.hideInitiativeSidebar();
}

populateInitiativeSidebar(initiative: Initiative, initiativeContent: string) {
this.view.populateInitiativeSidebar(initiative, initiativeContent);
}

showInitiativeList() {
this.view.showInitiativeList();
}

hideInitiativeList() {
this.view.hideInitiativeList();
}
Expand All @@ -112,7 +123,7 @@ export class SidebarPresenter extends BasePresenter {
});
EventBus.Sidebar.showDirectory.sub(() => {
this.changeSidebar("directory");
this.view.showInitiativeList();
this.showSidebar();
});
EventBus.Sidebar.showDatasets.sub(() => {
this.changeSidebar("datasets");
Expand All @@ -121,8 +132,12 @@ export class SidebarPresenter extends BasePresenter {
EventBus.Sidebar.showSidebar.sub(() => this.showSidebar());
EventBus.Sidebar.hideSidebar.sub(() => this.hideSidebar());
EventBus.Sidebar.hideInitiativeSidebar.sub(() => this.hideInitiativeSidebar());
EventBus.Sidebar.showInitiativeList.sub(() => this.showInitiativeList());
EventBus.Sidebar.hideInitiativeList.sub(() => this.hideInitiativeList());
EventBus.Initiatives.reset.sub(() => this.changeSidebar());
EventBus.Initiatives.reset.sub(() => {
this.changeSidebar();
this.hideInitiativeList();
});
EventBus.Initiatives.loadComplete.sub(() => this.changeSidebar());
}

Expand Down
17 changes: 14 additions & 3 deletions src/map-app/app/presenter/sidebar/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export abstract class BaseSidebarPresenter extends BasePresenter {
super();
}

// If the sidebar wants to do something more than to get its view to refresh when the history buttons have been used, then
// it should override this definition with its own:
/**
* If the sidebar wants to do something more than to get its view to refresh when the history
* buttons have been used, then it should override this definition with its own.
*/
historyButtonsUsed(): void {
this.view.refresh();
this.view.refresh(false);
}

deselectInitiatives(): void {
Expand Down Expand Up @@ -49,6 +51,15 @@ export abstract class BaseSidebarPresenter extends BasePresenter {
this.historyButtonsUsed();
}

/**
* Refreshes the sidebar view
*
* @param changed true if we changed to this sidebar, false if it was already showing and we're
* just refreshing it.
*/
refreshView(changed: boolean) {
this.view.refresh(changed);
}

onInitiativeClicked(initiative: Initiative): void {
EventBus.Map.initiativeClicked.pub(initiative);
Expand Down
40 changes: 2 additions & 38 deletions src/map-app/app/presenter/sidebar/initiatives.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { EventBus } from '../../../eventbus';
import { InitiativesSidebarView } from '../../view/sidebar/initiatives';
import { BaseSidebarPresenter } from './base';
import { SearchResults } from '../../../search-results';
import { Initiative } from '../../model/initiative';
import { compactArray, toString as _toString } from '../../../utils';
import { toString as _toString } from '../../../utils';
import { SidebarPresenter } from '../sidebar';

export class InitiativesSidebarPresenter extends BaseSidebarPresenter {
readonly view: InitiativesSidebarView;

_eventbusRegister(): void {
EventBus.Marker.selectionToggled.sub(initiative => this.onMarkerSelectionToggled(initiative));
EventBus.Initiative.searchedInitiativeClicked.sub(initiative => this.searchedInitiativeClicked(_toString(initiative.uri, undefined)));
}

constructor(readonly parent: SidebarPresenter) {
Expand All @@ -27,44 +25,10 @@ export class InitiativesSidebarPresenter extends BaseSidebarPresenter {
changeFilters(propName: string, value?: string) {
this.parent.mapui.changeFilters(propName, value);
}

notifyShowInitiativeTooltip(initiative: Initiative) {
EventBus.Map.needToShowInitiativeTooltip.pub(initiative);
}

notifyHideInitiativeTooltip(initiative: Initiative) {
EventBus.Map.needToHideInitiativeTooltip.pub(initiative);
}

historyButtonsUsed() {
//console.log("sidebar/initiatives historyButtonsUsed");
//console.log(lastContent);
//this.notifyMarkersNeedToShowNewSelection(lastContent);
this.view.refresh();
}

initClicked(initiative: Initiative) {
EventBus.Directory.initiativeClicked.pub(initiative);
if (window.outerWidth <= 800) {
EventBus.Directory.initiativeClickedHideSidebar.pub(initiative);
}
}

onInitiativeMouseoverInSidebar(initiative: Initiative) {
this.notifyShowInitiativeTooltip(initiative);
}

onInitiativeMouseoutInSidebar(initiative: Initiative) {
this.notifyHideInitiativeTooltip(initiative);
}

onMarkerSelectionToggled(initiative: Initiative) {
this.parent.mapui.toggleSelectInitiative(initiative);
this.view.refresh();
}

searchedInitiativeClicked(uri?: string) {
if (uri) this.view.onInitiativeClicked(uri);
this.view.refresh(false);
}

performSearch(text: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/map-app/app/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class AppState {
static applyTextSearch(initiatives: Set<Initiative>, textSearch?: TextSearch): Set<Initiative> {
if (!textSearch)
return initiatives;
if (textSearch.willMatch())
if (textSearch.isEmpty())
return initiatives;
return filterSet(initiatives, textSearch.predicate);
}
Expand Down Expand Up @@ -120,7 +120,7 @@ export class AppState {
}

get hasTextSearch(): boolean {
return this.textSearch.willMatch();
return !this.textSearch.isEmpty();
}

addTextSearch(textSearch: TextSearch): AppStateChange|undefined {
Expand Down Expand Up @@ -233,7 +233,7 @@ export class TextSearch {
.trim(); // trim whitespace from front and back
}

willMatch() {
isEmpty() {
return this.normSearchText === '';
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/map-app/app/view/map/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,13 @@ export class MapMarkerView extends BaseView {
this.presenter.notifySelectionToggled(this.presenter.initiative);
} else {
console.log(this.presenter.initiative);
// this.presenter.notifySelectionSet(this.initiative);
EventBus.Directory.initiativeClicked.pub(this.presenter.initiative);
EventBus.Map.initiativeClicked.pub(this.presenter.initiative);
}
}

setUnselected(initiative: Initiative) {
//close pop-up
this.presenter.mapUI.map?.closePopup();
//close information on the left hand side (for smaller screens)
EventBus.Sidebar.hideInitiative.pub();
//reset the map vars and stop the zoom event from triggering selectInitiative ({target}) method

//change the color of an initiative with a location
Expand Down Expand Up @@ -210,7 +207,7 @@ export class MapMarkerView extends BaseView {
let deselectInitiative = (e: leaflet.LeafletEvent) => {
if (factory.geoClusterGroup.getVisibleParent(marker) !== marker) {
this.setUnselected(initiative);
EventBus.Directory.initiativeClicked.pub(undefined); // deselects
EventBus.Map.initiativeClicked.pub(undefined); // deselects
factory.geoClusterGroup.off("animationend", deselectInitiative);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/map-app/app/view/sidebar/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export abstract class BaseSidebarView extends BaseView {
static readonly accordionClasses =
"w3-bar-item w3-tiny w3-light-grey w3-padding-small" + BaseSidebarView.hoverColour;
static readonly sectionClasses = "w3-bar-item w3-small w3-white w3-padding-small";



abstract readonly presenter: BaseSidebarPresenter;

Expand Down Expand Up @@ -85,10 +83,17 @@ export abstract class BaseSidebarView extends BaseView {
}
}

refresh() {
/**
* Refreshes the sidebar view
*
* @param changed true if we changed to this sidebar, false if it was already showing and we're
* just refreshing it.
*/
refresh(changed: boolean) {
this.loadFixedSection();
this.loadHistoryNavigation(); // back and forward buttons
this.loadScrollableSection();
this.refreshSearchResults();
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/map-app/app/view/sidebar/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ export class DirectorySidebarView extends BaseSidebarView {
this.title = presenter.parent.mapui.labels.directory;
}

refresh(changed: boolean) {
this.loadHistoryNavigation();
if (changed) {
// only need to load these if we changed to the directory sidebar
this.loadFixedSection();
this.loadScrollableSection();
}
this.refreshSearchResults();
}


populateFixedSelection(selection: d3Selection): void {
const that = this;
Expand Down

0 comments on commit a96781c

Please sign in to comment.