From f3ddceecfce14c0f6370edb9c0a52216d8437e50 Mon Sep 17 00:00:00 2001 From: talksik Date: Wed, 25 Mar 2026 16:03:14 -0700 Subject: [PATCH] fix: persist auto-play setting --- js/src/components/ui/switch.tsx | 31 +++++++++++++++++++++++++++++++ js/src/features/layout.tsx | 31 ++++++++++++++++++++----------- js/src/stores/autoplay-store.ts | 22 +++++++++++++++++++++- 3 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 js/src/components/ui/switch.tsx diff --git a/js/src/components/ui/switch.tsx b/js/src/components/ui/switch.tsx new file mode 100644 index 0000000..877dbc8 --- /dev/null +++ b/js/src/components/ui/switch.tsx @@ -0,0 +1,31 @@ +import * as React from "react" +import { Switch as SwitchPrimitive } from "radix-ui" + +import { cn } from "@/lib/utils" + +function Switch({ + className, + size = "default", + ...props +}: React.ComponentProps & { + size?: "sm" | "default" +}) { + return ( + + + + ) +} + +export { Switch } diff --git a/js/src/features/layout.tsx b/js/src/features/layout.tsx index 12f99f8..b8903b6 100644 --- a/js/src/features/layout.tsx +++ b/js/src/features/layout.tsx @@ -2,7 +2,7 @@ import { WindowControls } from "@/components/window-controls"; import { Button } from "@/components/ui/button"; import { useNavigate, useParams } from "react-router-dom"; import { Home, Settings, Users, Volume2, VolumeOff } from "lucide-react"; -import { Toggle } from "@/components/ui/toggle"; +import { Switch } from "@/components/ui/switch"; import { useAutoplayStore } from "@/stores/autoplay-store"; import { Breadcrumb, @@ -17,7 +17,8 @@ import { useNetworks } from "@/hooks/use-networks"; import { particlePath } from "@/lib/particle-path"; import { useParticle } from "@/hooks/use-particle"; import type { Particle } from "@/api/types"; -import { PropsWithChildren } from "react"; +import { PropsWithChildren, useCallback } from "react"; +import { toast } from "sonner"; function getParticleDisplayName(particle: Particle): string { switch (particle.type) { @@ -59,16 +60,24 @@ function AutoplayToggle() { const muted = useAutoplayStore((s) => s.muted); const toggleMuted = useAutoplayStore((s) => s.toggleMuted); + const handleToggle = useCallback(() => { + toggleMuted(); + if (muted) { + toast.success("Auto-play enabled"); + } else { + toast.info("Auto-play disabled"); + } + }, [toggleMuted, muted]); + return ( - - {muted ? : } - +
+ {muted ? : } + +
); } diff --git a/js/src/stores/autoplay-store.ts b/js/src/stores/autoplay-store.ts index b974e5f..5d4e34d 100644 --- a/js/src/stores/autoplay-store.ts +++ b/js/src/stores/autoplay-store.ts @@ -3,6 +3,24 @@ import type { Particle } from "@/api/types"; type MediaParticle = Extract; +const STORAGE_KEY = "llink:autoplay-muted"; + +function loadMuted(): boolean { + try { + return localStorage.getItem(STORAGE_KEY) === "true"; + } catch { + return false; + } +} + +function saveMuted(muted: boolean) { + try { + localStorage.setItem(STORAGE_KEY, String(muted)); + } catch { + // Storage unavailable + } +} + interface AutoplayState { /** The media particle currently being autoplayed, null when idle */ activeParticle: MediaParticle | null; @@ -21,7 +39,7 @@ interface AutoplayState { export const useAutoplayStore = create((set, get) => ({ activeParticle: null, streamId: null, - muted: false, + muted: loadMuted(), play: (particle, streamId) => { if (get().muted) return; set({ activeParticle: particle, streamId }); @@ -32,8 +50,10 @@ export const useAutoplayStore = create((set, get) => ({ // If muting, also stop any current playback if (!wasMuted) { set({ muted: true, activeParticle: null, streamId: null }); + saveMuted(true); } else { set({ muted: false }); + saveMuted(false); } }, }));