Skip to content

Commit

Permalink
adds optional TabBase.onActivate
Browse files Browse the repository at this point in the history
  • Loading branch information
Clay-Ferguson committed Dec 6, 2024
1 parent 0030e8f commit 645377d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/resources/public/src/AppContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function */
let dispatcher: (o: { type: string, func: (s: AppState) => any }) => void = null;

export let state = new AppState();
export const AppContext = createContext(state);
export const AppContext: React.Context<AppState> = createContext(state);
export type StateModFunc = (s: AppState) => any;

interface DispatchData {
Expand All @@ -31,7 +31,7 @@ function reducer(s: AppState, action: DispatchData) {
// ============================
// WARNING!!!! Normally dispatch methods return NOTHING, and so returning exactly 'false' is
// the only case we need to detect here. Do not change this to handle any "falsy" type
// because that will break the entier app.
// because that will break the entire app.
// ============================
if (action.func(newState) === false) {
// if func itself requested rollback, then rollback
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/public/src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class Constants {

static readonly PUBSUB_mainWindowScroll = "PUBSUB_mainWindowScroll";
static readonly PUBSUB_postMainWindowScroll = "PUBSUB_postMainWindowScroll";
static readonly PUBSUB_tabChanging = "PUBSUB_tabChanging";
static readonly PUBSUB_closeNavPanel = "PUBSUB_closeNavPanel";
static readonly PUBSUB_friendsChanged = "PUBSUB_friendsChanged";

Expand Down
9 changes: 4 additions & 5 deletions src/main/resources/public/src/TabUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AppState } from "./AppState";
import { AppTab } from "./comp/AppTab";
import { Constants as C } from "./Constants";
import { TabBase } from "./intf/TabBase";
import { PubSub } from "./PubSub";
import { S } from "./Singletons";
import { AdminTab } from "./tabs/data/AdminTab";
import { DocumentTab } from "./tabs/data/DocumentTab";
Expand Down Expand Up @@ -138,14 +137,14 @@ export class TabUtil {
return data?.props?.results?.length > 0;
}

/* This function manages persisting the scroll position when switching from one tab to another,
to automatically restore the scroll position that was last scroll position on any given tab */
tabChanging(prevTab: string, newTab: string) {

/* Don't run any code here if we aren't actually changing tabs */
if (prevTab && newTab && prevTab === newTab) {
return;
}
PubSub.pub(C.PUBSUB_tabChanging, newTab);
const data = getAs().tabData.find(d => d.id === newTab);
if (data) {
data.onActivate();
}
}
}
8 changes: 4 additions & 4 deletions src/main/resources/public/src/comp/FullScreenGraphViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class FullScreenGraphViewer extends Main {
}
}

// This technique of overriding the _domUpdateEvent() method is used to ensure that the Graphg
// This technique of overriding the _domUpdateEvent() method is used to ensure that the Graph
// DOM element which is not managed by react, is always maintained across renders, so that it
// doesn't loose state
// doesn't lose state
override _domUpdateEvent = () => {
const elm: HTMLElement = this.getRef();
if (!elm || !elm.isConnected) return;
Expand Down Expand Up @@ -90,7 +90,7 @@ export class FullScreenGraphViewer extends Main {
}
});
}

FullScreenGraphViewer.sim = d3.forceSimulation(nodes)
.force("link", d3.forceLink(ast.attractionLinksInGraph ? [...links, ...nodeLinks] : links) //
.id((d: any) => d.id).distance(5)
Expand Down Expand Up @@ -207,7 +207,7 @@ export class FullScreenGraphViewer extends Main {
})

.on("click", (event: any, d: any) => {
d3.select(event.currentTarget)
d3.select(event.currentTarget)
.attr("fill", "green");

if (d.data.id) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/public/src/intf/TabBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class TabBase<PT = any> {
props: PT = {} as PT;
openGraphComps: OpenGraphPanel[] = [];

onActivate(): void { }

constructView(_data: TabBase<PT>): Comp { return null; }

// controls whether to show tab button or not.
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/public/src/tabs/data/GraphTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FullScreenType } from "../../Interfaces";
import { TabBase } from "../../intf/TabBase";

export class GraphTab extends TabBase<any> {
name = "Node Graph";
name = "Graph";
tooltip = "View Node Graph";
id = C.TAB_GRAPH;
props = {};
Expand All @@ -20,13 +20,15 @@ export class GraphTab extends TabBase<any> {
return FullScreenGraphViewer.div;
}

// todo-0: It's kind of ugly that constructView uses a side effect rather than constructing a view. Fix this and also
// check to see if here are other cases of this.
constructView(_data: TabBase<any>): any {
onActivate() {
dispatch("RestoreGraph", s => {
s.savedActiveTab = s.activeTab;
s.fullScreenConfig = { type: FullScreenType.GRAPH };
});
}

// Note: We have a slight architectural inconsistency here because we build the actual view elsewhere
constructView(_data: TabBase<any>): any {
return null;
}
}

0 comments on commit 645377d

Please sign in to comment.