Skip to content

Commit 19525f2

Browse files
Merge pull request #2 from SanjayLavingia/hoverFrontendCom
Hover frontend com
2 parents b3e689f + c68d549 commit 19525f2

File tree

12 files changed

+40
-17
lines changed

12 files changed

+40
-17
lines changed

src/app/actions/actions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,9 @@ export const deleteTab = tab => ({
7777
export const resetSlider = () => ({
7878
type: types.SLIDER_ZERO,
7979
});
80+
81+
export const onHover = () => ({
82+
type: types.ON_HOVER,
83+
//the payload should be something to relate the component we're hovering and highlight that component on the DOM
84+
payload: 'PAYLOAD FROM onHover inside of action.ts'
85+
})

src/app/components/ComponentMap.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import React, { useEffect, useCallback } from 'react';
88
import * as d3 from 'd3';
9+
import { useStoreContext } from '../store'
10+
import { onHover } from '../actions/actions'
911

1012
interface componentMapProps {
1113
x: number;
@@ -22,7 +24,6 @@ const ComponentMap = (props: componentMapProps) => {
2224
let lastSnap: number | null = null;
2325
if (viewIndex < 0) lastSnap = snapshots.length - 1;
2426
else lastSnap = viewIndex;
25-
2627
//external constants
2728
const width: any = '100vw';
2829
const height: any = '100vh';
@@ -34,6 +35,7 @@ const ComponentMap = (props: componentMapProps) => {
3435
return makeChart(data);
3536
}, [data]);
3637

38+
const [{ tabs, currentTab }, dispatch] = useStoreContext();
3739
const makeChart = useCallback(
3840
(data) => {
3941
// Establish Constants
@@ -145,10 +147,12 @@ const ComponentMap = (props: componentMapProps) => {
145147

146148
//TODO -> Alter incoming snapshots so there is useful data to show on hover.
147149
nodeEnter.on('mouseover', function (d: any, i: number): any {
148-
150+
//onHover is an action in progress
151+
dispatch(onHover());
149152
d3.select(this)
150153
.append('text')
151154
.text(() => {
155+
//i want to return to the node in d3 the values listed in a more readable way. Right now it's just a horizontal line of text
152156
return JSON.stringify(d.data.state);
153157
})
154158
.attr('x', -25)
@@ -158,6 +162,8 @@ const ComponentMap = (props: componentMapProps) => {
158162
.attr('stroke', 'white')
159163
.attr('stroke-width', .5)
160164
.attr('id', `popup${i}`);
165+
166+
161167

162168
});
163169
nodeEnter.on('mouseout', function (d: any, i: number): any {

src/app/components/StateRoute.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Tree from './Tree';
1515
import ComponentMap from './ComponentMap';
1616
import PerfView from './PerfView';
1717
import AtomsRelationship from './AtomsRelationship.jsx';
18+
import { Console } from 'console';
1819

1920
const History = require('./History').default;
2021

src/app/constants/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export const NEW_SNAPSHOTS = 'NEW_SNAPSHOTS';
1313
export const SET_TAB = 'SET_TAB';
1414
export const DELETE_TAB = 'DELETE_TAB';
1515
export const SLIDER_ZERO = 'SLIDER_ZERO';
16+
export const ON_HOVER = 'ON_HOVER';

src/app/containers/MainContainer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const mixpanel = require("mixpanel").init("12fa2800ccbf44a5c36c37bc9776e4c0", {
2323
function MainContainer(): any {
2424
const [store, dispatch] = useStoreContext();
2525
const { tabs, currentTab, port: currentPort } = store;
26-
2726
// add event listeners to background script
2827
useEffect(() => {
2928
// only open port once
@@ -127,7 +126,6 @@ function MainContainer(): any {
127126
snapshots,
128127
hierarchy,
129128
} = tabs[currentTab];
130-
131129
// if viewIndex is -1, then use the sliderIndex instead
132130
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
133131
// cleaning hierarchy and snapshotView from stateless data

src/app/reducers/mainReducer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable prefer-const */
33
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
44
/* eslint-disable no-param-reassign */
5-
import produce from 'immer';
5+
import {produce, original} from 'immer';
66
import * as types from '../constants/actionTypes.ts';
77

88
export default (state, action) => produce(state, draft => {
@@ -39,19 +39,28 @@ export default (state, action) => produce(state, draft => {
3939
};
4040

4141
switch (action.type) {
42+
case types.ON_HOVER: {
43+
port.postMessage({
44+
action: 'onHover',
45+
payload: 'payload from Reducer ON_HOVER',
46+
tabId: currentTab,
47+
})
48+
break;
49+
}
50+
4251
case types.MOVE_BACKWARD: {
4352
if (snapshots.length > 0 && sliderIndex > 0) {
4453
const newIndex = sliderIndex - 1;
4554
// eslint-disable-next-line max-len
4655
// finds the name by the newIndex parsing through the hierarchy to send to background.js the current name in the jump action
4756
const nameFromIndex = findName(newIndex, hierarchy);
48-
4957
port.postMessage({
5058
action: 'jumpToSnap',
5159
payload: snapshots[newIndex],
5260
index: newIndex,
5361
name: nameFromIndex,
5462
tabId: currentTab,
63+
newProp: 'newPropFromReducer'
5564
});
5665
clearInterval(intervalId);
5766

src/backend/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
4949
timeJump(payload, true); // * This sets state with given payload
5050
// Get the pathname from payload and add new entry to browser history
5151
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
52-
5352
// try to modify workInProgress tree from here
5453
// window.history.pushState('', '', getRouteURL(payload));
5554
break;
@@ -59,6 +58,9 @@ window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
5958
case 'setPause':
6059
mode.paused = payload;
6160
break;
61+
case 'onHover':
62+
// console.log('WE MADE IT ALL THE WAY FROM THE FRONTEND! HERE\'S THE PAYLOAD:', payload);
63+
break;
6264
default:
6365
break;
6466
}

src/backend/linkFiber.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ function getRecoilState(): any {
6363
function sendSnapshot(snap: Snapshot, mode: Mode): void {
6464
// Don't send messages while jumping or while paused
6565
if (mode.jumping || mode.paused) return;
66-
6766
if (!snap.tree) {
6867
snap.tree = new Tree('root', 'root');
6968
}
70-
7169
const payload = snap.tree.cleanTreeCopy();
7270
if (isRecoil) {
7371
getRecoilState();
@@ -170,6 +168,7 @@ function createTree(
170168
fromSibling = false
171169
) {
172170
// Base case: child or sibling pointed to null
171+
173172
if (!currentFiber) return null;
174173
if (!tree) return tree;
175174

@@ -226,14 +225,13 @@ function createTree(
226225
stateNode.state,
227226
stateNode
228227
);
228+
229229
newState = stateNode.state;
230230
componentFound = true;
231231
}
232232

233233
let hooksIndex;
234234

235-
236-
237235
const atomArray = [];
238236
atomArray.push(memoizedProps);
239237

@@ -335,7 +333,6 @@ function createTree(
335333
} else {
336334
newNode = tree;
337335
}
338-
339336
// Recurse on children
340337
if (child && !circularComponentTable.has(child)) {
341338
// If this node had state we appended to the children array,
@@ -369,7 +366,6 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
369366
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
370367
const reactInstance = devTools ? devTools.renderers.get(1) : null;
371368
fiberRoot = devTools.getFiberRoots(1).values().next().value;
372-
373369
const throttledUpdateSnapshot = throttle(() => updateSnapShotTree(snap, mode), 70);
374370
document.addEventListener('visibilitychange', onVisibilityChange);
375371
if (reactInstance && reactInstance.version) {

src/backend/timeJump.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Console } from 'console';
12
/* eslint-disable @typescript-eslint/no-unused-vars */
23
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
34
/* eslint-disable max-len */

src/extension/background.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
324324
default:
325325
break;
326326
}
327+
console.log('inside background.js, tabsObj:', tabsObj);
327328
return true; // attempt to fix close port error
328329
});
329330

0 commit comments

Comments
 (0)