feat: close #1301 support message actions

This commit is contained in:
Yidadaa
2023-05-09 00:39:00 +08:00
parent 1b19fdfe11
commit 222301307f
9 changed files with 68 additions and 21 deletions

28
app/command.ts Normal file
View File

@@ -0,0 +1,28 @@
import { useSearchParams } from "react-router-dom";
type Command = (param: string) => void;
interface Commands {
fill?: Command;
submit?: Command;
mask?: Command;
}
export function useCommand(commands: Commands = {}) {
const [searchParams, setSearchParams] = useSearchParams();
if (commands === undefined) return;
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);
}
}