|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useSearchParams } from "react-router-dom";
|
|
|
|
|
import Locale from "./locales";
|
|
|
|
|
|
|
|
|
@ -11,21 +12,22 @@ interface Commands {
|
|
|
|
|
export function useCommand(commands: Commands = {}) {
|
|
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
|
|
|
|
|
|
|
|
if (commands === undefined) return;
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
let shouldUpdate = false;
|
|
|
|
|
searchParams.forEach((param, name) => {
|
|
|
|
|
const commandName = name as keyof Commands;
|
|
|
|
|
if (typeof commands[commandName] === "function") {
|
|
|
|
|
commands[commandName]!(param);
|
|
|
|
|
searchParams.delete(name);
|
|
|
|
|
shouldUpdate = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let shouldUpdate = false;
|
|
|
|
|
searchParams.forEach((param, name) => {
|
|
|
|
|
const commandName = name as keyof Commands;
|
|
|
|
|
if (typeof commands[commandName] === "function") {
|
|
|
|
|
commands[commandName]!(param);
|
|
|
|
|
searchParams.delete(name);
|
|
|
|
|
shouldUpdate = true;
|
|
|
|
|
if (shouldUpdate) {
|
|
|
|
|
setSearchParams(searchParams);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (shouldUpdate) {
|
|
|
|
|
setSearchParams(searchParams);
|
|
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [searchParams, commands]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ChatCommands {
|
|
|
|
|