1 import type { RefObject } from 'react';
2 import { useEffect } from 'react';
3 import { useState } from 'react';
5 import { TelemetryCollapsibleLeftSidebarEvents, TelemetryMeasurementGroups } from '@proton/shared/lib/api/telemetry';
6 import { sendTelemetryReport } from '@proton/shared/lib/helpers/metrics';
8 import type { APP_NAMES } from '../constants';
9 import type { Api } from '../interfaces';
11 export const enum COLLAPSE_EVENTS {
12 COLLAPSE = 'COLLAPSE',
15 export const enum SOURCE_EVENT {
16 BUTTON_SIDEBAR = 'BUTTON_SIDEBAR',
17 BUTTON_FOLDERS = 'BUTTON_FOLDERS',
18 BUTTON_LABELS = 'BUTTON_LABELS',
21 export const sendRequestCollapsibleSidebarReport = ({
28 action: COLLAPSE_EVENTS;
29 application: APP_NAMES;
30 sourceEvent: SOURCE_EVENT;
32 void sendTelemetryReport({
34 measurementGroup: TelemetryMeasurementGroups.collapsibleLeftSidebar,
35 event: TelemetryCollapsibleLeftSidebarEvents.toggleLeftSidebar,
45 navigationRef: RefObject<HTMLElement>;
48 const checkIsScrollPresent = ({ navigationRef }: Props) => {
49 if (!navigationRef?.current) {
53 const navigationScrollHeight = navigationRef.current.scrollHeight;
54 const navigationClientHeight = navigationRef.current.clientHeight;
56 return navigationClientHeight !== navigationScrollHeight;
59 export const useLeftSidebarButton = ({ navigationRef }: Props) => {
60 const [isScrollPresent, setIsScrollPresent] = useState(false);
63 const intervalID = window.setInterval(() => {
64 setIsScrollPresent(checkIsScrollPresent({ navigationRef }));
65 }, 350); // we'll optimize with observers later
68 clearInterval(intervalID);
72 return { isScrollPresent };