Skip to content

Commit

Permalink
Merge branch 'issue-64_hide-settings-and-searches' into 'master'
Browse files Browse the repository at this point in the history
Hide settings and searches tab until account setup is complete

See merge request c-hive/poe-sniper-electron!70
  • Loading branch information
gomorizsolt committed Sep 11, 2019
2 parents 8fb15db + 57cd05c commit 2a063d2
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 152 deletions.
2 changes: 0 additions & 2 deletions app/Subscription/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export const refresh = id => {
};

export const startRefreshInterval = id => {
refresh(id);

const oneHourInMilliseconds = 3600000;

refreshInterval = setInterval(() => {
Expand Down
8 changes: 4 additions & 4 deletions app/Subscription/Subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class Subscription {
return fetch(userApiUrl).then(subscriptionData => subscriptionData.json());
};

update(updatedData) {
update = updatedData => {
this.data = {
...this.data,
...updatedData,
};
}
};

active() {
active = () => {
return this.data.paying;
}
};
}

class SingletonSubscription {
Expand Down
10 changes: 5 additions & 5 deletions app/main/initialize-project/initialize-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ const setupWebSocketIpcListeners = () => {

globalStore.set(storeKeys.WS_CONNECTIONS, store.sanitized());

const isLoggedIn = globalStore.get(storeKeys.IS_LOGGED_IN, false);

if (isLoggedIn) {
webSocketActions.updateConnections();
}
webSocketActions.updateConnections();
});

ipcMain.on(ipcEvents.WS_REMOVE, (event, connectionDetails) => {
Expand Down Expand Up @@ -83,6 +79,10 @@ const setupGeneralIpcListeners = () => {
webSocketActions.updateConnections();
}
);

ipcMain.on(ipcEvents.GET_PAYING_STATUS, event => {
event.sender.send(ipcEvents.SEND_PAYING_STATUS, subscription.active());
});
};

const initializeProject = () => {
Expand Down
2 changes: 1 addition & 1 deletion app/main/poe-trade/poe-trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as electronUtils from "../utils/electron-utils/electron-utils";
import ItemFetchError from "../../errors/item-fetch-error";

export const getCookies = () => {
const poeSessionId = globalStore.get(storeKeys.POE_SESSION_ID, "");
const poeSessionId = globalStore.get(storeKeys.POE_SESSION_ID);

return `POESESSID=${poeSessionId}`;
};
Expand Down
20 changes: 15 additions & 5 deletions app/main/web-sockets/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as javaScriptUtils from "../../utils/JavaScriptUtils/JavaScriptUtils";
import * as electronUtils from "../utils/electron-utils/electron-utils";
import getWebSocketUri from "../get-websocket-uri/get-websocket-uri";
import { ipcEvents } from "../../resources/IPCEvents/IPCEvents";
import { globalStore } from "../../GlobalStore/GlobalStore";
import { storeKeys } from "../../resources/StoreKeys/StoreKeys";

const setupMessageListener = id => {
const limiter = notificationsLimiter.getLimiter();
Expand Down Expand Up @@ -134,7 +136,9 @@ export const connect = id => {
isConnected: false,
});

if (subscription.active()) {
const isLoggedIn = globalStore.get(storeKeys.IS_LOGGED_IN, false);

if (isLoggedIn && subscription.active()) {
setTimeout(() => {
connect(id);
}, 500);
Expand Down Expand Up @@ -171,11 +175,17 @@ export const disconnectFromStoredWebSockets = () => {
};

export const updateConnections = () => {
if (subscription.active()) {
connectToStoredWebSockets();
} else {
disconnectFromStoredWebSockets();
const isLoggedIn = globalStore.get(storeKeys.IS_LOGGED_IN, false);
const poeSessionId = globalStore.get(storeKeys.POE_SESSION_ID);

const conditionsAreFulfilled =
isLoggedIn && poeSessionId && subscription.active();

if (conditionsAreFulfilled) {
return connectToStoredWebSockets();
}

return disconnectFromStoredWebSockets();
};

export const reconnect = id => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import React, { useState, Fragment } from "react";
import Box from "@material-ui/core/Box";
import { ipcRenderer } from "electron";
import * as customHooks from "../../../../../utils/CustomHooks/CustomHooks";
import { globalStore } from "../../../../../../GlobalStore/GlobalStore";
import { storeKeys } from "../../../../../../resources/StoreKeys/StoreKeys";
import { ipcEvents } from "../../../../../../resources/IPCEvents/IPCEvents";
import InfoButton from "./InfoButton/InfoButton";
import Input from "../../../../UI/SimpleHtmlElements/Input/Input";
import ButtonWithSuccessIcon from "../../../../UI/ButtonWithSuccessIcon/ButtonWithSuccessIcon";

const sessionIdEditor = () => {
const [poeSessionId, setPoeSessionId] = useState(
globalStore.get(storeKeys.POE_SESSION_ID, "")
globalStore.get(storeKeys.POE_SESSION_ID)
);
const [
successIconIsVisible,
displaySuccessIcon,
hideSuccessIconAfterMsElapsed,
] = customHooks.useDisplay();

function idIsDefined() {
return poeSessionId !== "" && typeof poeSessionId !== "undefined";
}

function onSave() {
globalStore.set(storeKeys.POE_SESSION_ID, poeSessionId);
globalStore.set(
storeKeys.POE_SESSION_ID,
idIsDefined() ? poeSessionId : null
);

displaySuccessIcon();

ipcRenderer.send(ipcEvents.RECONNECT_ALL);

hideSuccessIconAfterMsElapsed(2500);
}

Expand All @@ -31,7 +42,7 @@ const sessionIdEditor = () => {
<Input
type="text"
onChange={e => setPoeSessionId(e.target.value)}
value={poeSessionId}
value={poeSessionId || ""}
label="Session ID"
error={!poeSessionId}
/>
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/Screens/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { uniqueIdGenerator } from "../../../../utils/UniqueIdGenerator/UniqueIdG
import * as regExes from "../../../../resources/RegExes/RegExes";
import * as javaScriptUtils from "../../../../utils/JavaScriptUtils/JavaScriptUtils";
import InvalidInputError from "../../../../errors/invalid-input-error";
import withLoggedOutRestriction from "../../withLoggedOutRedirection/withLoggedOutRedirection";
import withRouteRestriction from "../../withRouteRestriction/withRouteRestriction";

class Input extends Component {
constructor(props) {
Expand Down Expand Up @@ -207,4 +207,4 @@ class Input extends Component {
}
}

export default withLoggedOutRestriction(Input, "/account");
export default withRouteRestriction(Input);
98 changes: 0 additions & 98 deletions app/renderer/components/Screens/Input/Input.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/renderer/components/Screens/Screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Settings from "./Settings/Settings";
const screens = () => (
<Switch>
<Route path="/input" component={Input} />
<Route path="/account" component={Account} />
<Route path="/settings" component={Settings} />
<Route component={Account} />
</Switch>
);

Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/Screens/Settings/Settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import Box from "@material-ui/core/Box";
import withLoggedOutRestriction from "../../withLoggedOutRedirection/withLoggedOutRedirection";
import NotificationsInterval from "./NotificationsInterval/NotificationsInterval";
import TestNotification from "./TestNotification/TestNotification";
import Clipboard from "./Clipboard/Clipboard";
import withRouteRestriction from "../../withRouteRestriction/withRouteRestriction";

const settings = () => (
<Box>
Expand All @@ -13,4 +13,4 @@ const settings = () => (
</Box>
);

export default withLoggedOutRestriction(settings, "/account");
export default withRouteRestriction(settings);
3 changes: 1 addition & 2 deletions app/renderer/components/Screens/Trade/Trade.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import MaterialTable from "material-table";
import * as CustomHooks from "../../../utils/CustomHooks/CustomHooks";
import withLoggedOutRedirection from "../../withLoggedOutRedirection/withLoggedOutRedirection";
import { globalStore } from "../../../../GlobalStore/GlobalStore";
import { storeKeys } from "../../../../resources/StoreKeys/StoreKeys";
import * as tableColumns from "../../../resources/TableColumns/TableColumns";
Expand Down Expand Up @@ -37,4 +36,4 @@ const trade = () => {
);
};

export default withLoggedOutRedirection(trade, "/account");
export default trade;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState, useEffect } from "react";
import { ipcRenderer } from "electron";
import { Redirect } from "react-router-dom";
import { globalStore } from "../../../GlobalStore/GlobalStore";
import { storeKeys } from "../../../resources/StoreKeys/StoreKeys";
import { ipcEvents } from "../../../resources/IPCEvents/IPCEvents";
import Loader from "../UI/Loader/Loader";

const withRouteRestriction = WrappedComponent => {
return ({ ...props }) => {
const isLoggedIn = globalStore.get(storeKeys.IS_LOGGED_IN, false);
const poeSessionId = globalStore.get(storeKeys.POE_SESSION_ID);
const [isPaying, setIsPaying] = useState(false);
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
ipcRenderer.send(ipcEvents.GET_PAYING_STATUS);

ipcRenderer.on(ipcEvents.SEND_PAYING_STATUS, (event, payingStatus) => {
setIsPaying(payingStatus);

setIsLoading(false);
});

return () => ipcRenderer.removeAllListeners();
}, []);

function conditionsAreFulfilled() {
return isLoggedIn && poeSessionId && isPaying;
}

if (isLoading) {
return <Loader />;
}

if (conditionsAreFulfilled()) {
return <WrappedComponent {...props} />;
}

return <Redirect to="/account" />;
};
};

export default withRouteRestriction;
6 changes: 3 additions & 3 deletions app/renderer/utils/CustomHooks/CustomHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ export const useDisable = seconds => {
export const useDisplay = () => {
const [elementIsVisible, setShowElement] = useState(false);

let timeout;
const timeout = useRef(null);

useEffect(() => {
return () => clearTimeout(timeout);
return () => clearTimeout(timeout.current);
}, [timeout]);

const displayElement = () => setShowElement(true);

const hideElementAfterMsElapsed = milliseconds => {
timeout = setTimeout(() => {
timeout.current = setTimeout(() => {
setShowElement(false);
}, milliseconds);
};
Expand Down
Loading

0 comments on commit 2a063d2

Please sign in to comment.