From 09e9edebd553fb34ed0ee0779de0332346831f3a Mon Sep 17 00:00:00 2001 From: Philipp Herz Date: Sun, 12 Nov 2023 21:42:28 +0100 Subject: [PATCH 1/2] Added search params to the Mod Logs and Approvals and reports page --- src/pages/Actions.jsx | 28 ++++++++++++++++++---- src/pages/Approvals.jsx | 21 +++++++++++++++-- src/pages/Reports.jsx | 52 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 7 deletions(-) diff --git a/src/pages/Actions.jsx b/src/pages/Actions.jsx index 895cacc..2757fc5 100644 --- a/src/pages/Actions.jsx +++ b/src/pages/Actions.jsx @@ -1,6 +1,6 @@ import React, { useEffect } from "react"; -import { useSelector } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { useInView } from "react-intersection-observer"; import Box from "@mui/joy/Box"; @@ -19,13 +19,15 @@ import { getSiteData } from "../hooks/getSiteData"; import { parseActorId } from "../utils"; import ModLogAccordians from "../components/Activity/ModLogAccordians"; -import { selectModLogType } from "../redux/reducer/configReducer"; +import { selectModLogType, setConfigItem } from "../redux/reducer/configReducer"; import { useSearchParams } from "react-router-dom"; export default function Actions() { const { baseUrl, siteData, localPerson, userRole } = getSiteData(); const [searchParams, setSearchParams] = useSearchParams(); + const dispatch = useDispatch(); + const locaUserParsedActor = parseActorId(localPerson.actor_id); const modLogType = useSelector(selectModLogType); @@ -40,6 +42,11 @@ export default function Actions() { setLimitCommunityId(searchParams.get("community_id")); } + if (searchParams.get("mod_log_type")) { + dispatch(setConfigItem("modLogType",searchParams.get("mod_log_type"))); + } + + if (searchParams.get("mod_id")) { setLimitModId(searchParams.get("mod_id")); } @@ -47,9 +54,22 @@ export default function Actions() { if (searchParams.get("acted_on_id")) { setActedOnID(searchParams.get("acted_on_id")); } - }, [searchParams]); - + if(searchParams.get("local_instance")) { + setLimitLocalInstance(searchParams.get("local_instance") == "true"); + } + }, []); + + useEffect(() => { + if (modLogType !== null) { + setSearchParams({ mod_log_type: modLogType }); + } + + if (limitLocalInstance !== null) { + setSearchParams({ local_instance: limitCommunityId }); + } + }, [modLogType, limitLocalInstance]); + const { ref, inView, entry } = useInView({ threshold: 0, }); diff --git a/src/pages/Approvals.jsx b/src/pages/Approvals.jsx index f320086..455f49b 100644 --- a/src/pages/Approvals.jsx +++ b/src/pages/Approvals.jsx @@ -1,6 +1,6 @@ import React from "react"; -import { useSelector } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import Box from "@mui/joy/Box"; import Button from "@mui/joy/Button"; @@ -19,7 +19,8 @@ import useLemmyInfinite from "../hooks/useLemmyInfinite"; import ApprovalsList from "../components/ApprovalsList.jsx"; import { getSiteData } from "../hooks/getSiteData"; -import { selectHideReadApprovals } from "../redux/reducer/configReducer"; +import { selectHideReadApprovals, setConfigItem } from "../redux/reducer/configReducer"; +import { useSearchParams } from "react-router-dom"; export default function Approvals() { const hideReadApprovals = useSelector(selectHideReadApprovals); @@ -32,6 +33,8 @@ export default function Approvals() { threshold: 0, }); + const dispatch = useDispatch(); + const { isLoading: registrationsLoading, isFetching: registrationsFetching, @@ -51,6 +54,20 @@ export default function Approvals() { perPage: 10, }); + const [searchParams, setSearchParams] = useSearchParams(); + + React.useEffect(() => { + if(searchParams.has("unread_only")) { + dispatch(setConfigItem("hideReadApprovals", searchParams.get("unread_only") == "true")); + } +}, []); + + + React.useEffect(() => { + setSearchParams({ unread_only: hideReadApprovals }); + }, [hideReadApprovals]); + + const fullData = React.useMemo(() => { if (!registrationsData) return []; diff --git a/src/pages/Reports.jsx b/src/pages/Reports.jsx index 2ce10d7..f2ca7ef 100644 --- a/src/pages/Reports.jsx +++ b/src/pages/Reports.jsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import Box from "@mui/joy/Box"; import Button from "@mui/joy/Button"; @@ -18,6 +18,9 @@ import useLemmyReports from "../hooks/useLemmyReports"; import ReportsList from "../components/ReportsList.jsx"; import { getSiteData } from "../hooks/getSiteData"; +import { selectFilterCommunity, selectFilterType, selectShowResolved, setConfigItem } from "../redux/reducer/configReducer.js"; +import { useSelector } from "react-redux"; +import { useSearchParams } from "react-router-dom"; export default function Reports() { // const { @@ -53,6 +56,53 @@ export default function Reports() { const isLoading = loadingReports; const isError = isReportsError; + const filterCommunity = useSelector(selectFilterCommunity); + const filterType = useSelector(selectFilterType); + const showResolved = useSelector(selectShowResolved); + + const [searchParams, setSearchParams] = useSearchParams(); + + useEffect(() => { + if (searchParams.filter_community) { + dispatch(setConfigItem("filterCommunity", searchParams.filter_community)); + } + if (searchParams.mod_log_type) { + dispatch(setConfigItem("filterType", searchParams.filter_type)); + } + if (searchParams.show_resolved) { + dispatch(setConfigItem("showResolved", true)); + } + }, []) + + const [query, setQuery] = useState({}); + + useEffect(() => { + setSearchParams(query); + }, [query]) + + useEffect(() => { + if (filterCommunity) { + + setQuery({ ...query, filter_community: filterCommunity }); + } + }, [filterCommunity]) + + useEffect(() => { + if (filterType) { + setQuery({ ...query, filter_type: filterCommunity }); + } + }, [filterType]) + + useEffect(() => { + if (showResolved) { + setQuery({ ...query, show_resolved: showResolved }); + } else { + const { show_resolved, ...rest } = query; + setQuery({ ...rest }); + } + }, [showResolved]) + + if (userRole == "user") { return ( Date: Sun, 12 Nov 2023 21:50:56 +0100 Subject: [PATCH 2/2] Fixed some logic --- src/pages/Actions.jsx | 7 +++++-- src/pages/Approvals.jsx | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pages/Actions.jsx b/src/pages/Actions.jsx index 2757fc5..f9c36d5 100644 --- a/src/pages/Actions.jsx +++ b/src/pages/Actions.jsx @@ -65,8 +65,11 @@ export default function Actions() { setSearchParams({ mod_log_type: modLogType }); } - if (limitLocalInstance !== null) { - setSearchParams({ local_instance: limitCommunityId }); + if (limitLocalInstance !== null && limitLocalInstance !== true) { + setSearchParams({ local_instance: limitLocalInstance }); + } else { + searchParams.delete("local_instance"); + setSearchParams(searchParams); } }, [modLogType, limitLocalInstance]); diff --git a/src/pages/Approvals.jsx b/src/pages/Approvals.jsx index 455f49b..81537a6 100644 --- a/src/pages/Approvals.jsx +++ b/src/pages/Approvals.jsx @@ -55,7 +55,7 @@ export default function Approvals() { }); const [searchParams, setSearchParams] = useSearchParams(); - + React.useEffect(() => { if(searchParams.has("unread_only")) { dispatch(setConfigItem("hideReadApprovals", searchParams.get("unread_only") == "true")); @@ -64,7 +64,12 @@ export default function Approvals() { React.useEffect(() => { + if(hideReadApprovals){ setSearchParams({ unread_only: hideReadApprovals }); + } else { + searchParams.delete("unread_only"); + setSearchParams(searchParams); + } }, [hideReadApprovals]);