Add manual translate as default (#33)

* Added translate and switch auto buttons

* Tests updated

* Added hotkey & improved buttons visually
This commit is contained in:
David
2021-07-12 17:06:27 +02:00
committed by GitHub
parent f537dff588
commit 5870e4b096
13 changed files with 214 additions and 82 deletions

View File

@@ -0,0 +1,38 @@
import { useState, useEffect, FC } from "react";
import { IconButton } from "@chakra-ui/react";
import { FaBolt } from "react-icons/fa";
type Props = {
onAuto: () => void,
[key: string]: any
};
const initLocalStorage = () => {
const initial = typeof window !== "undefined" && localStorage.getItem("isauto");
return initial ? initial === "true" : false;
};
const AutoTranslateButton: FC<Props> = ({ onAuto, ...props }) => {
const [isAuto, setIsAuto] = useState(initLocalStorage);
useEffect(() => {
localStorage.setItem("isauto", isAuto.toString());
}, [isAuto]);
useEffect(() => {
isAuto && onAuto();
}, [isAuto, onAuto]);
return (
<IconButton
aria-label="Switch auto"
icon={<FaBolt />}
colorScheme="lingva"
variant={isAuto ? "solid" : "outline"}
onClick={() => setIsAuto(current => !current)}
{...props}
/>
);
};
export default AutoTranslateButton;