Skip to content

Commit

Permalink
removed unutilized imports and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuthopsee committed Oct 19, 2023
1 parent 35a87a9 commit 3c24082
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 88 deletions.
1 change: 0 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ function App() {

return (
<ThemeProvider theme={theme}>
{console.log("App.js rendered")}
<ToastContextProvider>
<CssBaseline />
<AppBar {...appBarStyles} elevation={0}>
Expand Down
19 changes: 3 additions & 16 deletions src/Contexts/CustomPresetsContextProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { useContext, createContext } from 'react';
import { useNavigate } from 'react-router-dom';
import useLocalStorage from '../hooks/useLocalStorage';
import { StrategyContext } from './StrategyContextProvider';

export const CustomPresetsContext = createContext();

const CustomPresetsContextProvider = ({ children }) => {
const navigate = useNavigate();
const [customPresets, setCustomPresets] = useLocalStorage("customPresets", []);
const {
selectedPreset,
selectPreset,
setSelectedPreset,
legs,
updateLegs
legs,
} = useContext(StrategyContext);

const saveNewCustomPreset = (name) => {
Expand All @@ -30,7 +28,7 @@ const CustomPresetsContextProvider = ({ children }) => {
const updatedPreset = { name: selectedPreset.name, legs: legs }
setCustomPresets(
customPresets.map((preset) => (preset.name === selectedPreset.name) ? updatedPreset : preset)
)
);
};

const deleteCustomPreset = (index) => {
Expand All @@ -48,23 +46,12 @@ const CustomPresetsContextProvider = ({ children }) => {
setCustomPresets(customPresets.filter((preset, i) => index !== i))
};

const selectCustomPreset = (presetName, customPresetIndex) => {
setSelectedPreset(
{
name: presetName,
custom: true
}
);
updateLegs(customPresets[customPresetIndex].legs);
};

const value = {
customPresets: customPresets,
setCustomPresets: setCustomPresets,
deleteCustomPreset: deleteCustomPreset,
saveCustomPreset: saveCustomPreset,
saveNewCustomPreset: saveNewCustomPreset,
selectCustomPreset: selectCustomPreset
};

return (
Expand Down
12 changes: 1 addition & 11 deletions src/Contexts/StrategyContextProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ const StrategyContextProvider = ({ children }) => {
name: defaultPresetName,
custom: false
}, setLegs);

const selectPreset = (presetName, custom=false) => {
setSelectedPreset(
{
name: presetName,
custom: custom
}
);
setLegs(PRESETS[presetName]);
};

const updateLegs = (updatedLegs) => {
if (updatedLegs.length <= 10) {
Expand All @@ -33,7 +23,7 @@ const StrategyContextProvider = ({ children }) => {
};

return (
<StrategyContext.Provider value={{ legs, updateLegs, selectedPreset, setSelectedPreset, selectPreset}}>
<StrategyContext.Provider value={{ legs, updateLegs, selectedPreset }}>
{children}
</StrategyContext.Provider>
);
Expand Down
8 changes: 2 additions & 6 deletions src/components/Presets/BullCallSpreadSVG.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import { StrategyContext } from '../../Contexts/StrategyContextProvider';

const BullCallSpreadSVG = () => {
const navigate = useNavigate();
const { selectedPreset, selectPreset } = useContext(StrategyContext);
const { selectedPreset } = useContext(StrategyContext);

const isSelected = () => {
if (selectedPreset.name === "Bull Call Spread" && !selectedPreset.custom) {
return true;
} else {
return false;
};
return (selectedPreset.name === "Bull Call Spread" && !selectedPreset.custom);
};

return (
Expand Down
8 changes: 2 additions & 6 deletions src/components/Presets/BullPutSpreadSVG.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import { StrategyContext } from '../../Contexts/StrategyContextProvider';

const BullPutSpreadSVG = () => {
const navigate = useNavigate();
const { selectedPreset, selectPreset } = useContext(StrategyContext);
const { selectedPreset } = useContext(StrategyContext);
const isSelected = () => {
if (selectedPreset.name === "Bull Put Spread" && !selectPreset.custom) {
return true;
} else {
return false;
};
return (selectedPreset.name === "Bull Put Spread" && !selectedPreset.custom);
};

return (
Expand Down
8 changes: 2 additions & 6 deletions src/components/Presets/CustomSVG.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ import CancelIcon from '@mui/icons-material/Close';
const CustomSVG = ({ name, index }) => {
const navigate = useNavigate();
const { selectedPreset } = useContext(StrategyContext);
const { deleteCustomPreset, selectCustomPreset } = useContext(CustomPresetsContext);
const { deleteCustomPreset } = useContext(CustomPresetsContext);
const { toggleToast } = useContext(ToastContext);

const isSelected = () => {
if (selectedPreset.name === name && selectedPreset.custom) {
return true;
} else {
return false;
};
return (selectedPreset.name === name && selectedPreset.custom);
};

const handleDeleteClick = (e) => {
Expand Down
8 changes: 2 additions & 6 deletions src/components/Presets/ShortStraddleSVG.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import { StrategyContext } from '../../Contexts/StrategyContextProvider';

const ShortStraddleSVG = () => {
const navigate = useNavigate();
const { selectedPreset, selectPreset } = useContext(StrategyContext);
const { selectedPreset } = useContext(StrategyContext);
const isSelected = () => {
if (selectedPreset.name === "Short Straddle" && !selectedPreset.custom) {
return true;
} else {
return false;
};
return (selectedPreset.name === "Short Straddle" && !selectedPreset.custom)
};

return (
Expand Down
8 changes: 2 additions & 6 deletions src/components/Presets/ShortStrangleSVG.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import { StrategyContext } from '../../Contexts/StrategyContextProvider';

const ShortStrangleSVG = () => {
const navigate = useNavigate();
const { selectedPreset, selectPreset } = useContext(StrategyContext);
const { selectedPreset } = useContext(StrategyContext);
const isSelected = () => {
if (selectedPreset.name === "Short Strangle" && !selectedPreset.custom) {
return true;
} else {
return false;
};
return (selectedPreset.name === "Short Strangle" && !selectedPreset.custom);
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePathBasedLegs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect } from "react";
import { useLocation } from "react-router-dom";
import { PRESETS } from "../const/presets";
import { splitWords, getHash, getPathName } from "./utils";
import { splitWords, getPathName } from "./utils";

const getLegs = (defaultPresetName, pathName) => {
if (!pathName) return PRESETS[defaultPresetName];
Expand Down
18 changes: 2 additions & 16 deletions src/hooks/usePathBasedPresetName.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect, useRef } from "react";
import { useLocation } from "react-router-dom";
import { getPathName } from "./utils";
import { PRESETS } from "../const/presets";
import { splitWords, joinWords, getHash } from "./utils";
import { splitWords } from "./utils";

const getSelectedPreset = (defaultPresetName, pathName) => {
if (!pathName) return { name: defaultPresetName, custom: false };
Expand Down Expand Up @@ -37,26 +37,12 @@ const getCustomPresetLegs = (presetName) => {
return null;
};

const usePathBasedPresetName = (initialState, setLegs) => {
const usePathBasedPresetName = (initialState) => {
const location = useLocation();
const pathName = getPathName(location);

const firstRender = useRef(true);
const [selectedPreset, setSelectedPreset] = useState(() => getSelectedPreset(initialState.name, pathName));

const handlePopState = () => {
const preset = getSelectedPreset(selectedPreset.name);
if (preset.name !== selectedPreset.name) {
setSelectedPreset(preset);
if (!preset.custom) {
setLegs(PRESETS[preset.name]);
} else {
const customPresetLegs = getCustomPresetLegs(preset.name);
setLegs(customPresetLegs);
};
};
};

useEffect(() => {
if (pathName && pathName !== selectedPreset.name) {
setSelectedPreset(getSelectedPreset(initialState.name, pathName));
Expand Down
13 changes: 0 additions & 13 deletions src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ export const splitWords = (hyphenSeparatedString) => {
return lowercaseWords.join(' ');
};

export const getHash = () => {
let inputText = window.location.hash;
if (inputText === "") return "";
inputText = inputText.slice(2)
const indexOfSlash = inputText.indexOf('/');

if (indexOfSlash !== -1) {
return inputText.slice(0, indexOfSlash);
} else {
return inputText;
};
};

export const getPathName = (location) => {
let pathName = location.pathname.slice(1);
const indexOfSlash = pathName.indexOf('/');
Expand Down

0 comments on commit 3c24082

Please sign in to comment.