Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using modern Redux #1710

Merged
merged 11 commits into from
Oct 12, 2023
98 changes: 84 additions & 14 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.21.0",
"@hot-loader/react-dom": "^16.13.0",
"@reduxjs/toolkit": "^1.9.7",
"argparse": "^1.0.10",
"babel-loader": "^8.0.4",
"babel-plugin-lodash": "^3.3.4",
Expand Down Expand Up @@ -108,8 +109,6 @@
"react-tooltip": "^4.2.10",
"react-transition-group": "^1.2.1",
"react-virtualized": "^9.22.3",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"regenerator-runtime": "^0.13.5",
"style-loader": "^0.13.2",
"styled-components": "^4.0.3",
Expand All @@ -125,6 +124,7 @@
"devDependencies": {
"@types/leaflet": "^1.9.3",
"@types/node": "^18.15.11",
"@types/webpack-env": "^1.18.2",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"chai": "^4.1.2",
Expand Down
5 changes: 3 additions & 2 deletions src/components/controls/measurementsOptions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { useSelector } from "react-redux";
import { useAppDispatch } from "../../hooks";
import { isEqual } from "lodash";
import { changeMeasurementsCollection } from "../../actions/measurements";
import {
Expand Down Expand Up @@ -30,7 +31,7 @@ const collectionOptionsSelector = (collections) => {
};

const MeasurementsOptions = () => {
const dispatch = useDispatch();
const dispatch = useAppDispatch();
const collection = useSelector((state) => state.measurements.collectionToDisplay);
const collectionOptions = useSelector((state) => collectionOptionsSelector(state.measurements.collections), isEqual);
const groupBy = useSelector((state) => state.controls.measurementsGroupBy);
Expand Down
35 changes: 0 additions & 35 deletions src/components/controls/panel-toggles.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/components/controls/panel-toggles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import { useSelector } from "react-redux";
import { useAppDispatch } from "../../hooks";
import { useTranslation } from 'react-i18next';

import Toggle from "./toggle";
import { togglePanelDisplay } from "../../actions/panelDisplay";
import { RootState } from "../../store";

export default function PanelToggles() {
const dispatch = useAppDispatch();
const { t } = useTranslation();

const panelsAvailable = useSelector((state: RootState) => state.controls.panelsAvailable);
const panelsToDisplay = useSelector((state: RootState) => state.controls.panelsToDisplay);
const showTreeToo = useSelector((state: RootState) => state.controls.showTreeToo);

const panels = panelsAvailable.slice();
if (showTreeToo && panels.indexOf("map") !== -1) {
panels.splice(panels.indexOf("map"), 1);
}
return <>
{panels.map((n) => (
<Toggle
key={n}
display
on={panelsToDisplay.indexOf(n) !== -1}
callback={() => dispatch(togglePanelDisplay(n))}
label={t("sidebar:Show " + n)}
style={{ paddingBottom: "10px" }}
/>
))}
</>
}
4 changes: 2 additions & 2 deletions src/components/narrativeEditor/examineNarrative.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef, useEffect } from "react";
import { useDispatch } from 'react-redux';
import { useAppDispatch } from "../../hooks";
import { getDatasetNamesFromUrl } from "../../actions/loadData";
import { CLEAN_START } from "../../actions/types";
import { createStateFromQueryOrJSONs } from "../../actions/recomputeReduxState";
Expand Down Expand Up @@ -159,7 +159,7 @@ const NarrativeSummary = ({summary, datasetResponses, showNarrative}) => {
};

const ExamineNarrative = ({narrative, datasetResponses, setDisplayNarrative}) => {
const dispatch = useDispatch();
const dispatch = useAppDispatch();
const el = useRef(null);
useEffect(() => {
/* when a narrative is loaded then we want to focus on <ExamineNarrative> however
Expand Down
4 changes: 2 additions & 2 deletions src/components/narrativeEditor/useDatasetFetch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useEffect, useReducer, useRef} from "react";
import { useDispatch } from 'react-redux';
import { useAppDispatch } from "../../hooks";
import { CACHE_JSONS } from "../../actions/types";
import { FetchError } from "../../util/exceptions";

Expand All @@ -14,7 +14,7 @@ import { FetchError } from "../../util/exceptions";
*/

export function useDatasetFetch(datasets) {
const dispatchRedux = useDispatch();
const dispatchRedux = useAppDispatch;
const [datasetResponses, dispatchDatasetResponses] = useReducer(
(state, action) => {
if (action.reset) return {};
Expand Down
6 changes: 6 additions & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import type { RootState, AppDispatch } from './store'


export const useAppDispatch: () => AppDispatch = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
/* A U S P I C E I M P O R T S */
import configureStore from "./store";
import store from "./store";
import { initialiseGoogleAnalyticsIfRequired } from "./util/googleAnalytics";
import Root from "./root";
/* I N T E R N A T I O N A L I Z A T I O N */
Expand All @@ -26,8 +26,6 @@ import "./css/select.css";
/* FONTS */
import 'typeface-lato';

const store = configureStore();

/* set up non-redux state storage for the animation - use this conservitavely! */
if (!window.NEXTSTRAIN) {window.NEXTSTRAIN = {};}

Expand Down
Loading