Skip to content

Commit

Permalink
Merge pull request #108 from tgxn/add-redux-slices
Browse files Browse the repository at this point in the history
Added the reducers and moved the store
  • Loading branch information
tgxn authored Nov 6, 2023
2 parents a2bff8d + b89137d commit fdc350b
Show file tree
Hide file tree
Showing 28 changed files with 121 additions and 126 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"react-redux": "^8.1.1",
"react-router-dom": "^6.18.0",
"redux": "^4.2.1",
"redux-persist": "^6.0.0",
"sass": "^1.69.5",
"sass-loader": "^13.3.2",
"sonner": "^1.1.0",
Expand Down
8 changes: 4 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import Approvals from "./pages/Approvals";
import Reports from "./pages/Reports";
import Login from "./pages/Login";

import AppStore from "./store";
import { selectIsInElectron } from "./reducers/configReducer";
import { selectCurrentUser } from "./reducers/accountReducer";
import { store } from "./redux/store";
import { selectIsInElectron } from "./redux/reducer/configReducer";
import { selectCurrentUser } from "./redux/reducer/accountReducer";

function PageRouter() {
const theme = useTheme();
Expand Down Expand Up @@ -195,7 +195,7 @@ export default function App() {
<QueryClientProvider client={queryClient}>
<ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-left" />

<Provider store={AppStore}>
<Provider store={store}>
<PageRouter />
</Provider>
</QueryClientProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Actions/CommentButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useLemmyHttpAction } from "../../hooks/useLemmyHttp.js";

import { BaseActionButton, ActionConfirmButton, InputElement, ConfirmDialog } from "./BaseElements.jsx";
import { getSiteData } from "../../hooks/getSiteData";
import { selectShowResolved, selectMandatoryModComment } from "../../reducers/configReducer.js";
import { selectShowResolved, selectMandatoryModComment } from "../../redux/reducer/configReducer.js";

export const ResolveCommentReportButton = ({ report, ...props }) => {
const queryClient = useQueryClient();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Actions/GenButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ConfirmDialog,
} from "./BaseElements.jsx";

import { selectMandatoryModComment } from "../../reducers/configReducer";
import { selectMandatoryModComment } from "../../redux/reducer/configReducer";

// banFromCommunity
export const BanUserCommunityButton = ({ person, community, isBanned, ...props }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Actions/PMButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useLemmyHttpAction } from "../../hooks/useLemmyHttp.js";

import { BaseActionButton, ActionConfirmButton, InputElement, ConfirmDialog } from "./BaseElements.jsx";
import { getSiteData } from "../../hooks/getSiteData";
import { selectShowResolved, selectMandatoryModComment } from "../../reducers/configReducer.js";
import { selectShowResolved, selectMandatoryModComment } from "../../redux/reducer/configReducer.js";

// allow resolving / unresolving a post report
// resolvePrivateMessageReport
Expand Down
4 changes: 2 additions & 2 deletions src/components/Actions/PostButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { useLemmyHttpAction } from "../../hooks/useLemmyHttp.js";

import { BaseActionButton, ActionConfirmButton, InputElement, ConfirmDialog } from "./BaseElements.jsx";
import { getSiteData } from "../../hooks/getSiteData";
import { selectShowResolved } from "../../reducers/configReducer.js";
import { selectShowResolved } from "../../redux/reducer/configReducer.js";

import { selectMandatoryModComment } from "../../reducers/configReducer";
import { selectMandatoryModComment } from "../../redux/reducer/configReducer";

// allow resolving / unresolving a post report
export const ResolvePostReportButton = ({ report, ...props }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Actions/RegistrationButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useLemmyHttpAction } from "../../hooks/useLemmyHttp.js";
import { getSiteData } from "../../hooks/getSiteData";

import { BaseActionButton, ActionConfirmButton, InputElement, ConfirmDialog } from "./BaseElements.jsx";
import { selectHideReadApprovals } from "../../reducers/configReducer.js";
import { selectHideReadApprovals } from "../../redux/reducer/configReducer.js";

export const ApproveButton = ({ registration, ...props }) => {
const queryClient = useQueryClient();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Content/PostThumb.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import LaunchIcon from "@mui/icons-material/Launch";
import { SanitizedLink } from "../Display.jsx";
import { Image, Video } from "./Image.jsx";

import { selectBlurNsfw, selectNsfwWords } from "../../reducers/configReducer";
import { selectBlurNsfw, selectNsfwWords } from "../../redux/reducer/configReducer";

function ThumbWrapper({ width = 200, tooltip, modal = null, children }) {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Filters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Checkbox from "@mui/joy/Checkbox";

import Chip from "@mui/joy/Chip";

import { selectFilterCommunity, selectFilterType, selectHideReadApprovals, selectModLogType, selectShowRemoved, selectShowResolved, setConfigItem } from "../reducers/configReducer";
import { selectFilterCommunity, selectFilterType, selectHideReadApprovals, selectModLogType, selectShowRemoved, selectShowResolved, setConfigItem } from "../redux/reducer/configReducer";

import { getSiteData } from "../hooks/getSiteData";
import { getModLogTypeNames } from "../utils";
Expand Down
6 changes: 3 additions & 3 deletions src/components/Header/AccountMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import SupervisedUserCircleIcon from "@mui/icons-material/SupervisedUserCircle";
import AccountBoxIcon from "@mui/icons-material/AccountBox";
import ArrowDropDown from "@mui/icons-material/ArrowDropDown";

import { logoutCurrent, selectUsers } from "../../reducers/accountReducer";
import { logoutCurrent, selectUsers } from "../../redux/reducer/accountReducer";

import { getSiteData } from "../../hooks/getSiteData";

Expand All @@ -31,7 +31,7 @@ import { BasicInfoTooltip } from "../Tooltip.jsx";

import { parseActorId, getUserRole } from "../../utils.js";

import { setAccountIsLoading, setCurrentUser } from "../../reducers/accountReducer";
import { setAccountIsLoading, setCurrentUser } from "../../redux/reducer/accountReducer";

import { RoleIcons } from "../Shared/Icons.jsx";
import { Typography } from "@mui/material";
Expand Down Expand Up @@ -78,7 +78,7 @@ function UserListItem({ user }) {
}

// TODO we need to update the user's details in the saved accounts array too, if this is a saved session
dispatch(setCurrentUser(user.base, user.jwt, getSite));
dispatch(setCurrentUser({base: user.base, jwt: user.jwt, site: getSite}));
} catch (e) {
toast(typeof e == "string" ? e : e.message);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/ConfigModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
selectBlurNsfw,
selectShowAvatars,
selectNsfwWords,
} from "../../reducers/configReducer";
} from "../../redux/reducer/configReducer";

function BooleanSetting({ label, subtext, value, onChange }) {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header/UserMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import VerifiedUserIcon from "@mui/icons-material/VerifiedUser";
import SupervisedUserCircleIcon from "@mui/icons-material/SupervisedUserCircle";
import AccountBoxIcon from "@mui/icons-material/AccountBox";

import { logoutCurrent, selectUsers } from "../../reducers/accountReducer";
import { logoutCurrent, selectUsers } from "../../redux/reducer/accountReducer";

import { useLemmyHttp, refreshAllData } from "../../hooks/useLemmyHttp";
import { getSiteData } from "../../hooks/getSiteData";
Expand All @@ -27,7 +27,7 @@ import { BasicInfoTooltip } from "../Tooltip.jsx";
import { parseActorId } from "../../utils.js";
import AccountMenu from "./AccountMenu.jsx";

import { selectAccountIsLoading } from "../../reducers/accountReducer";
import { selectAccountIsLoading } from "../../redux/reducer/accountReducer";

export default function UserMenu() {
const dispatch = useDispatch();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Shared/ActorMeta.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
selectBlurNsfw,
selectShowAvatars,
selectNsfwWords,
} from "../../reducers/configReducer";
} from "../../redux/reducer/configReducer";

export function PersonMetaLine({ creator, by = false, sx }) {
const { baseUrl, siteData, localPerson, userRole } = getSiteData();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
selectBlurNsfw,
selectShowAvatars,
selectNsfwWords,
} from "../reducers/configReducer";
} from "../redux/reducer/configReducer";

export const UserTooltip = ({ user, ...props }) => {
console.log("user", user);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/getSiteData.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from "react";

import { useSelector } from "react-redux";
import { selectCurrentUser } from "../reducers/accountReducer";
import { selectCurrentUser } from "../redux/reducer/accountReducer";

// accessor for the site data returned at the time of login
export function getSiteData() {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLemmyHttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getSiteData } from "../hooks/getSiteData";

import { LemmyHttp } from "lemmy-js-client";

import { selectCurrentUser, updateCurrentUserData, setAccountIsLoading } from "../reducers/accountReducer";
import { selectCurrentUser, updateCurrentUserData, setAccountIsLoading } from "../redux/reducer/accountReducer";

export function useLemmyHttp(callLemmyMethod, formData = {}) {
const currentUser = useSelector(selectCurrentUser);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLemmyInfinite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getSiteData } from "../hooks/getSiteData";
import { useSelector } from "react-redux";

import { LemmyHttp } from "lemmy-js-client";
import { selectCurrentUser } from "../reducers/accountReducer";
import { selectCurrentUser } from "../redux/reducer/accountReducer";

export default function useLemmyInfinite({
callLemmyMethod,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLemmyModLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LemmyHttp } from "lemmy-js-client";

import useLemmyInfinite from "./useLemmyInfinite";
import { getModLogTypeNames } from "../utils";
import { selectModLogCommunityId, selectModLogType } from "../reducers/configReducer";
import { selectModLogCommunityId, selectModLogType } from "../redux/reducer/configReducer";

// gets paginated / infinite list of reports from lemmy
export default function useLemmyModLog() {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLemmyReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
selectOrderBy,
selectShowRemoved,
selectShowResolved,
} from "../reducers/configReducer";
} from "../redux/reducer/configReducer";

// gets paginated / infinite list of reports from lemmy
export default function useLemmyReports() {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getSiteData } from "../hooks/getSiteData";
import { parseActorId } from "../utils";

import ModLogAccordians from "../components/Activity/ModLogAccordians";
import { selectModLogType } from "../reducers/configReducer";
import { selectModLogType } from "../redux/reducer/configReducer";

export default function Actions() {
const { baseUrl, siteData, localPerson, userRole } = getSiteData();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Approvals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import useLemmyInfinite from "../hooks/useLemmyInfinite";
import ApprovalsList from "../components/ApprovalsList.jsx";

import { getSiteData } from "../hooks/getSiteData";
import { selectHideReadApprovals } from "../reducers/configReducer";
import { selectHideReadApprovals } from "../redux/reducer/configReducer";

export default function Approvals() {
const hideReadApprovals = useSelector(selectHideReadApprovals);
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import {
setCurrentUser,
selectAccountIsLoading,
selectUsers,
} from "../reducers/accountReducer";
} from "../redux/reducer/accountReducer";

import { BasicInfoTooltip } from "../components/Tooltip.jsx";
import { selectIsInElectron } from "../reducers/configReducer";
import { selectIsInElectron } from "../redux/reducer/configReducer";

export default function LoginForm() {
const domainLock = window?.RuntimeConfig?.DomainLock != "" ? window?.RuntimeConfig?.DomainLock : false;
Expand Down Expand Up @@ -99,9 +99,9 @@ export default function LoginForm() {
});

if (saveSession) {
dispatch(addUser(instanceBase, auth.jwt, getSite));
dispatch(addUser({instance: instanceBase, jwt: auth.jwt, site: getSite}));
} else {
dispatch(setCurrentUser(instanceBase, auth.jwt, getSite));
dispatch(setCurrentUser({base: instanceBase, jwt: auth.jwt, site: getSite}));
}
} else {
setLoginError(auth);
Expand Down Expand Up @@ -334,7 +334,7 @@ export default function LoginForm() {
// dispatch(addUser(user.base, auth.jwt, getSite));
// } else {
// dispatch(setCurrentUser(user.base, auth.jwt, getSite));
dispatch(setCurrentUser(user.base, user.jwt, getSite));
dispatch(setCurrentUser({base: instanceBase, jwt: user.jwt, site: getSite}));
// }
} catch (e) {
setLoginError(typeof e == "string" ? e : e.message);
Expand Down
11 changes: 0 additions & 11 deletions src/reducers.js

This file was deleted.

Loading

0 comments on commit fdc350b

Please sign in to comment.