mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-16 12:23:12 +00:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { IconButton } from "@mui/joy";
|
|
import { useEffect } from "react";
|
|
import { toast } from "react-hot-toast";
|
|
import { useStorageContext } from "@/context";
|
|
import { useShortcutStore } from "@/stores";
|
|
import Icon from "./Icon";
|
|
|
|
const PullShortcutsButton = () => {
|
|
const context = useStorageContext();
|
|
const shortcutStore = useShortcutStore();
|
|
|
|
useEffect(() => {
|
|
if (context.instanceUrl && context.accessToken) {
|
|
handlePullShortcuts(true);
|
|
}
|
|
}, [context]);
|
|
|
|
const handlePullShortcuts = async (silence = false) => {
|
|
try {
|
|
await shortcutStore.fetchShortcutList(context.instanceUrl, context.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;
|