Skip to content

Commit

Permalink
feat: keep custom transports in localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Jul 5, 2021
1 parent b3673e0 commit 26e45af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
15 changes: 12 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@types/jest": "^24.0.13",
"@types/qs": "^6.5.3",
"@types/react-dom": "^16.8.4",
"@types/use-persisted-state": "^0.3.0",
"jest": "24.9.0",
"monaco-editor-webpack-plugin": "^1.7.0",
"react-scripts": "^3.3.0",
Expand Down Expand Up @@ -68,6 +69,7 @@
"react-split-pane": "^0.1.87",
"semantic-release": "^15.13.21",
"use-dark-mode": "^2.3.1",
"use-debounce": "^3.3.0"
"use-debounce": "^3.3.0",
"use-persisted-state": "^0.3.3"
}
}
9 changes: 6 additions & 3 deletions src/containers/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ListItemText,
Container,
} from "@material-ui/core";
import createPersistedState from "use-persisted-state";
import Brightness3Icon from "@material-ui/icons/Brightness3";
import WbSunnyIcon from "@material-ui/icons/WbSunny";
import { JSONRPCError } from "@open-rpc/client-js/build/Error";
Expand All @@ -40,6 +41,8 @@ import useTransport, { ITransport, IWebTransport, TTransport } from "../hooks/us
import JSONRPCLogger, { JSONRPCLog } from "@open-rpc/logs-react";
import OptionsEditor from "./OptionsEditor";

const useCustomTransportList = createPersistedState("inspector-custom-transports");

const defaultTransports: ITransport[] = [
{
type: "http",
Expand Down Expand Up @@ -167,7 +170,7 @@ const Inspector: React.FC<IProps> = (props) => {
params: [],
id: 0,
});
const [transportList, setTransportList] = useState(() => {
const [transportList, setTransportList] = useCustomTransportList(() => {
if (props.customTransport) {
return [...defaultTransports, props.customTransport];
}
Expand Down Expand Up @@ -222,8 +225,8 @@ const Inspector: React.FC<IProps> = (props) => {

useEffect(() => {
if (props.transport) {
const t = defaultTransports
.find((tp: ITransport) => tp.type === props.transport);
const t = transportList
.find((tp: ITransport) => tp.name?.toLowerCase() === props.transport?.toLowerCase());
if (t) {
setSelectedTransport(t);
}
Expand Down

0 comments on commit 26e45af

Please sign in to comment.