From 2e8e872edcef86928f26673964584d80051a436a Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Thu, 20 Aug 2020 16:27:20 +0200 Subject: [PATCH] Reorder the exploration aspect module (#106) --- frontend/src/aspects/exploration.ts | 59 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/frontend/src/aspects/exploration.ts b/frontend/src/aspects/exploration.ts index 2b651159..1d493215 100644 --- a/frontend/src/aspects/exploration.ts +++ b/frontend/src/aspects/exploration.ts @@ -10,6 +10,34 @@ import { ensureSources } from '../global/sources'; import sourceListPanel from '../global/source-list-view'; const browserHistory = window.history; +const resetSourceList = () => explorer.reset(sourceListPanel); + +/** + * Common patterns for the explorer routes. + */ +function deepRoute(obtainAction, resetAction) { + return ([serial]) => explorer.scrollOrAction( + browserHistory.state, + () => resetAction(controller, obtainAction(serial)) + ); +} +const sourceRoute = partial(deepRoute, act.getSource); +const itemRoute = partial(deepRoute, act.getItem); + +mainRouter.on('route:explore', () => { + ensureSources(); + explorer.scrollOrAction(sourceListPanel.cid, resetSourceList); +}); + +router.on('route:source:bare', sourceRoute(act.sourceWithoutAnnotations)); +router.on('route:source:annotated', sourceRoute(act.sourceWithAnnotations)); +router.on('route:item', itemRoute(act.item)); +router.on('route:item:edit', itemRoute(act.itemInEditMode)); +router.on('route:item:related', itemRoute(act.itemWithRelations)); +router.on('route:item:related:edit', itemRoute(act.itemWithEditRelations)); +router.on('route:item:external', itemRoute(act.itemWithExternal)); +router.on('route:item:external:edit', itemRoute(act.itemWithEditExternal)); +router.on('route:item:annotations', itemRoute(act.itemWithOccurrences)); channel.on({ 'sourceview:showAnnotations': controller.reopenSourceAnnotations, @@ -39,34 +67,3 @@ channel.on('currentRoute', (route, panel) => { // panel. browserHistory.replaceState(panel.cid, document.title); }); - -mainRouter.on('route:explore', () => { - ensureSources(); - explorer.scrollOrAction( - sourceListPanel.cid, - () => explorer.reset(sourceListPanel) - ); -}); - -/** - * Common patterns for the explorer routes. - */ -function deepRoute(obtainAction, resetAction) { - return ([serial]) => explorer.scrollOrAction( - browserHistory.state, - () => resetAction(controller, obtainAction(serial)) - ); -} - -const sourceRoute = partial(deepRoute, act.getSource); -const itemRoute = partial(deepRoute, act.getItem); - -router.on('route:source:bare', sourceRoute(act.sourceWithoutAnnotations)); -router.on('route:source:annotated', sourceRoute(act.sourceWithAnnotations)); -router.on('route:item', itemRoute(act.item)); -router.on('route:item:edit', itemRoute(act.itemInEditMode)); -router.on('route:item:related', itemRoute(act.itemWithRelations)); -router.on('route:item:related:edit', itemRoute(act.itemWithEditRelations)); -router.on('route:item:external', itemRoute(act.itemWithExternal)); -router.on('route:item:external:edit', itemRoute(act.itemWithEditExternal)); -router.on('route:item:annotations', itemRoute(act.itemWithOccurrences));