mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-18 21:19:44 +00:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { IconButton } from "@mui/joy";
|
|
import { useStorage } from "@plasmohq/storage/hook";
|
|
import { useEffect } from "react";
|
|
import { toast } from "react-hot-toast";
|
|
import useShortcutStore from "@/store/shortcut";
|
|
import Icon from "./Icon";
|
|
|
|
const PullShortcutsButton = () => {
|
|
const [instanceUrl] = useStorage("domain");
|
|
const [accessToken] = useStorage("access_token");
|
|
const shortcutStore = useShortcutStore();
|
|
|
|
useEffect(() => {
|
|
if (instanceUrl && accessToken) {
|
|
handlePullShortcuts(true);
|
|
}
|
|
}, [instanceUrl, accessToken]);
|
|
|
|
const handlePullShortcuts = async (silence = false) => {
|
|
try {
|
|
await shortcutStore.fetchShortcutList(instanceUrl, accessToken);
|
|
if (!silence) {
|
|
toast.success("Shortcuts pulled");
|
|
}
|
|
} catch (error) {
|
|
toast.error("Failed to pull shortcuts, error: " + error.message);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<IconButton color="neutral" variant="plain" size="sm" onClick={() => handlePullShortcuts()}>
|
|
<Icon.RefreshCcw className="w-4 h-auto" />
|
|
</IconButton>
|
|
);
|
|
};
|
|
|
|
export default PullShortcutsButton;
|