refactor: init switching to nextjs router

This commit is contained in:
Fred
2024-05-10 14:57:55 +08:00
parent 00b1a9781d
commit 0c53579996
25 changed files with 473 additions and 123 deletions

View File

@@ -1,5 +1,6 @@
import { useEffect } from "react";
import { useSearchParams } from "react-router-dom";
// import { useSearchParams } from "react-router-dom";
import { useSearchParams } from "next/navigation";
import Locale from "./locales";
type Command = (param: string) => void;
@@ -14,22 +15,23 @@ interface Commands {
export function useCommand(commands: Commands = {}) {
const [searchParams, setSearchParams] = useSearchParams();
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;
}
});
// fixme: update commands
// 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;
// }
// });
if (shouldUpdate) {
setSearchParams(searchParams);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchParams, commands]);
// if (shouldUpdate) {
// setSearchParams(searchParams);
// }
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [searchParams, commands]);
}
interface ChatCommands {