Files
sexy/lib/buttplug/store.ts
T
valknarandClaude Sonnet 5 5484d3cefe
CI / Static checks (push) Successful in 1m7s
CI / Build and push image (push) Successful in 1m2s
Fix device/replay/session UX issues, add pagination, bump to 0.3.0
- Fix device rename input collapsing on mobile (fixed width vs w-full
  inside an auto-layout table column).
- Add cascade-delete confirmation for sessions with a saved recording.
- Fix header connection LED: derive state from scanning/device-count/
  recording instead of the Buttplug client's raw connected flag; drop
  the label text and hide the indicator entirely when idle.
- Add a per-device disconnect button (stop + remove from store, the
  closest equivalent Buttplug's protocol allows per device).
- Fix replay ending early: duration now comes from the recording's
  actual durationMs, not the last event's timestamp.
- Replay robustness: show which devices are being replayed to, reset
  actuators to zero on start/play/pause, fully disconnect devices and
  the whole client on stop/unmount, surface command failures via toast.
- Stop flagging the header LED red during replay - recording is only
  for live sessions.
- Add page-number pagination to recordings/sessions/devices lists.
- Wordmark SEXY -> Sexy; add proper per-page <title>s including
  dynamic titles for recording/session detail and replay pages.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-25 21:26:18 +02:00

59 lines
2.4 KiB
TypeScript

import { create } from "zustand";
import type { ConnectedDeviceInfo } from "./types";
export const actuatorKey = (deviceIndex: number, featureIndex: number): string =>
`${deviceIndex}:${featureIndex}`;
interface ButtplugStoreState {
connected: boolean;
scanning: boolean;
/** Whether a play session is actively being recorded (see ButtplugConsole's session lifecycle). */
recording: boolean;
devices: Record<number, ConnectedDeviceInfo>;
/** Last-known slider value per `${deviceIndex}:${featureIndex}`, for UI display only. */
actuatorValues: Record<string, number>;
/** Last-known battery reading (0-1) per device index; absent until first read completes. */
batteryLevels: Record<number, number | null>;
error: string | null;
setConnected: (connected: boolean) => void;
setScanning: (scanning: boolean) => void;
setRecording: (recording: boolean) => void;
upsertDevice: (device: ConnectedDeviceInfo) => void;
removeDevice: (index: number) => void;
setActuatorValue: (deviceIndex: number, featureIndex: number, value: number) => void;
setBatteryLevel: (deviceIndex: number, level: number | null) => void;
setError: (message: string | null) => void;
reset: () => void;
}
export const useButtplugStore = create<ButtplugStoreState>((set) => ({
connected: false,
scanning: false,
recording: false,
devices: {},
actuatorValues: {},
batteryLevels: {},
error: null,
setConnected: (connected) => set({ connected }),
setScanning: (scanning) => set({ scanning }),
setRecording: (recording) => set({ recording }),
upsertDevice: (device) => set((s) => ({ devices: { ...s.devices, [device.index]: device } })),
removeDevice: (index) =>
set((s) => {
const devices = { ...s.devices };
delete devices[index];
const batteryLevels = { ...s.batteryLevels };
delete batteryLevels[index];
return { devices, batteryLevels };
}),
setActuatorValue: (deviceIndex, featureIndex, value) =>
set((s) => ({
actuatorValues: { ...s.actuatorValues, [actuatorKey(deviceIndex, featureIndex)]: value },
})),
setBatteryLevel: (deviceIndex, level) =>
set((s) => ({ batteryLevels: { ...s.batteryLevels, [deviceIndex]: level } })),
setError: (message) => set({ error: message }),
reset: () =>
set({ connected: false, scanning: false, recording: false, devices: {}, actuatorValues: {}, batteryLevels: {} }),
}));