Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/ActionDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export class ActionDispatcher {
}
}

public dispatch(type: string, data?: unknown): void {
public dispatch(timeStamp: number, type: string, data?: unknown): void {
if (this.actions[type]) {
this.actions[type].forEach((fn) => fn(data));
this.actions[type].forEach((fn) => fn(data, timeStamp));
}
}
}
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const initializeDigmaMessageListener = (
window.addEventListener("message", (e) => {
if (isDigmaMessageEvent(e)) {
console.debug("Digma message received: ", e);
dispatcher.dispatch(e.data.action, e.data.payload);
dispatcher.dispatch(e.timeStamp, e.data.action, e.data.payload);
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ActionListener = (data: unknown) => void;
export type ActionListener = (data: unknown, timeStamp: number) => void;

export interface DigmaIncomingMessageData {
type: "digma";
Expand Down
26 changes: 15 additions & 11 deletions src/components/Assets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const Assets = (props: AssetsProps) => {
null
);
const [data, setData] = useState<GroupedAssetEntries>();
const [lastSetDataTimeStamp, setLastSetDataTimeStamp] = useState<number>();
const theme = useTheme();
const noDataIconColor = getNoDataIconColor(theme);

Expand All @@ -85,28 +86,31 @@ export const Assets = (props: AssetsProps) => {
action: actions.GET_DATA
});

let getDataTimeout: number;

const handleAssetsData = (data: unknown) => {
const handleAssetsData = (data: unknown, timeStamp: number) => {
const entries = (data as AssetsData | null)?.serviceAssetsEntries;
setData(entries ? groupEntries(entries) : undefined);

getDataTimeout = window.setTimeout(() => {
window.sendMessageToDigma({
action: actions.GET_DATA
});
}, REFRESH_INTERVAL);
setLastSetDataTimeStamp(timeStamp);
};

dispatcher.addActionListener(actions.SET_DATA, handleAssetsData);

return () => {
clearTimeout(getDataTimeout);

dispatcher.removeActionListener(actions.SET_DATA, handleAssetsData);
};
}, []);

useEffect(() => {
const timerId = window.setTimeout(() => {
window.sendMessageToDigma({
action: actions.GET_DATA
});
}, REFRESH_INTERVAL);

return () => {
window.clearTimeout(timerId);
};
}, [lastSetDataTimeStamp]);

useEffect(() => {
if (!props.data) {
return;
Expand Down
12 changes: 0 additions & 12 deletions src/components/common/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ export const App = (props: AppProps) => {
const [mainFont, setMainFont] = useState(defaultMainFont);
const [codeFont, setCodeFont] = useState(defaultCodeFont);

useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
console.debug(e);
};

window.addEventListener("keydown", handleKeyDown);

return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, []);

useEffect(() => {
if (!props.theme) {
return;
Expand Down
6 changes: 3 additions & 3 deletions src/components/common/CursorFollower/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const CursorFollower = (props: { children: JSX.Element }) => {
const [degree, setDegree] = useState(0);
const ref = useRef<HTMLDivElement | null>(null);

const handleMove = (event: MouseEvent) => {
const handleMouseMove = (event: MouseEvent) => {
if (ref.current) {
const elPosition = ref.current.getBoundingClientRect();
const diffX = event.pageX - elPosition.left - elPosition.width / 2;
Expand All @@ -29,10 +29,10 @@ export const CursorFollower = (props: { children: JSX.Element }) => {
};

useEffect(() => {
document.addEventListener("mousemove", handleMove);
window.addEventListener("mousemove", handleMouseMove);

return () => {
document.removeEventListener("mousemove", handleMove);
window.removeEventListener("mousemove", handleMouseMove);
};
});

Expand Down