Skip to content

Commit

Permalink
Added server state storage to browser, fix for broken download paths
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-mony committed Nov 19, 2020
1 parent 0ff4c9c commit 5a01732
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion frontend/Context/Servers/ServerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import serverReducer from "./serverReducer";
import servers from "../../data/qresp_servers";
import httpServers from "../../data/http_servers";

import { SET_SELECTED, SET_SELECTED_HTTP } from "../types";
import { SET_SELECTED, SET_SELECTED_HTTP, SET_SERVER_STATE } from "../types";

import WebStore from "../../Utils/Persist";

const ServerState = (props) => {
const initialState = {
Expand All @@ -17,6 +19,20 @@ const ServerState = (props) => {

const [state, dispatch] = useReducer(serverReducer, initialState);

useEffect(() => {
const data = WebStore.get("srvr");
if (data !== null) {
setServerState(data);
}
}, []);

useEffect(() => {
WebStore.set("srvr", state);
}, [state]);

const setServerState = (state) =>
dispatch({ type: SET_SERVER_STATE, payload: state });

const setSelected = (selected) => {
dispatch({ type: SET_SELECTED, payload: selected });
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/Context/Servers/serverReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { SET_SELECTED, SET_SELECTED_HTTP } from "../types";
import { SET_SELECTED, SET_SELECTED_HTTP, SET_SERVER_STATE } from "../types";

export default (state, action) => {
switch (action.type) {
case SET_SERVER_STATE:
return action.payload;
case SET_SELECTED:
return { ...state, selected: action.payload };
case SET_SELECTED_HTTP:
Expand Down

0 comments on commit 5a01732

Please sign in to comment.