"use client"; import { useEffect, useId, useRef } from "react"; // THE VISITOR'S OWN COPY, PICKED (lane missing-source, slice 2): one plain // button that opens the browser's file picker, and the one-sentence promise // beside it. The chosen File goes to `onPick` and nowhere else — the provider // plays it from an object URL. No context here, so PlayerProvider can render // it without a cycle. // // Nothing in this file may reach the network or storage; a unit test reads // this source and fails on any API that could (LocalFilePicker.test.ts). export const LOCAL_FILE_PRIVACY = "Your file stays in this browser: nothing is uploaded."; export const LOCAL_FILE_BUTTON = "Play your own copy"; export function LocalFilePicker({ onPick, takeFocus, tone = "dark", }: { onPick: (file: File) => void; // Asked once on mount: true when this control replaces a copy the visitor // just stopped, and so takes the focus back. takeFocus?: () => boolean; tone?: "dark"; }) { const inputRef = useRef(null); const buttonRef = useRef(null); const noteId = useId(); useEffect(() => { if (takeFocus?.()) buttonRef.current?.focus(); // On mount only: a later render is not a return from "Stop". // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( { const file = e.currentTarget.files?.[0]; // Cleared so the same file can be picked again after "Stop". e.currentTarget.value = ""; if (file) onPick(file); }} /> {LOCAL_FILE_PRIVACY} ); }