Better insight into settings updates

This commit is contained in:
Gregory Schier
2024-12-16 16:27:13 -08:00
parent 5ff5d6fb1d
commit cb6e3d4ac8
18 changed files with 145 additions and 88 deletions

View File

@@ -3,6 +3,7 @@ import type { HTMLAttributes, ReactNode } from 'react';
import { forwardRef, useImperativeHandle, useRef } from 'react';
import type { HotkeyAction } from '../../hooks/useHotKey';
import { useFormattedHotkey, useHotKey } from '../../hooks/useHotKey';
import { trackEvent } from '../../lib/analytics';
import { Icon } from './Icon';
export type ButtonProps = Omit<HTMLAttributes<HTMLButtonElement>, 'color' | 'onChange'> & {
@@ -28,6 +29,7 @@ export type ButtonProps = Omit<HTMLAttributes<HTMLButtonElement>, 'color' | 'onC
leftSlot?: ReactNode;
rightSlot?: ReactNode;
hotkeyAction?: HotkeyAction;
event?: string | { id: string; [attr: string]: number | string };
};
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
@@ -48,6 +50,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
hotkeyAction,
title,
onClick,
event,
...props
}: ButtonProps,
ref,
@@ -107,7 +110,12 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
type={type}
className={classes}
disabled={disabled || isLoading}
onClick={onClick}
onClick={(e) => {
onClick?.(e);
if (event != null) {
trackEvent('button', 'click', typeof event === 'string' ? { id: event } : event);
}
}}
onDoubleClick={(e) => {
// Kind of a hack? This prevents double-clicks from going through buttons. For example, when
// double-clicking the workspace header to toggle window maximization