import { useTranslation } from "react-i18next"; import { DialogContent } from "@mui/material"; import { useAppDispatch, useAppSelector } from "../../../redux/hooks.ts"; import { ChangeEvent, useCallback, useEffect, useState } from "react"; import DraggableDialog from "../../Dialogs/DraggableDialog.tsx"; import { closePinFileDialog } from "../../../redux/globalStateSlice.ts"; import { pinToSidebar } from "../../../redux/thunks/settings.ts"; import { FilledTextField } from "../../Common/StyledComponents.tsx"; const PinToSidebar = () => { const { t } = useTranslation(); const dispatch = useAppDispatch(); const [name, setName] = useState(""); const [loading, setLoading] = useState(false); const open = useAppSelector((state) => state.globalState.pinFileDialogOpen); const uri = useAppSelector((state) => state.globalState.pinFileUri); const onClose = useCallback(() => { if (!loading) { dispatch(closePinFileDialog()); } }, [dispatch, loading]); const onAccept = useCallback( async (e?: React.FormEvent) => { if (e) { e.preventDefault(); } if (!uri) { return; } setLoading(true); try { await dispatch(pinToSidebar(uri, name)); } catch (e) { } finally { setLoading(false); dispatch(closePinFileDialog()); } }, [name, dispatch, uri, setLoading], ); useEffect(() => { if (uri && open) { setName(""); } }, [uri]); const onNameChange = useCallback( (e: ChangeEvent) => { setName(e.target.value); }, [dispatch, setName], ); return ( ); }; export default PinToSidebar;