Skip to content

Commit

Permalink
Fix toggling details panel resetting filters
Browse files Browse the repository at this point in the history
Issue #35
  • Loading branch information
qu1ck committed Jul 6, 2023
1 parent af9cdaf commit 8680c28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/components/filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import React, { useCallback, useContext, useEffect, useMemo, useState } from "react";
import React, { useCallback, useContext, useEffect, useMemo, useReducer, useState } from "react";
import type { Torrent } from "../rpc/torrent";
import { Status } from "../rpc/transmission";
import * as Icon from "react-bootstrap-icons";
import * as StatusIcons from "./statusicons";
import type { FilterSectionName, SectionsVisibility } from "../config";
import { ConfigContext, ServerConfigContext } from "../config";
import { Divider, Flex } from "@mantine/core";
import { eventHasModKey, useForceRender } from "trutil";
Expand Down Expand Up @@ -304,16 +305,17 @@ export function Filters(props: FiltersProps) {
};
}, [props.allLabels, props.allTrackers]);

const [sections, setSections] = useState(config.values.interface.filterSections);
const [sections, setSections] = useReducer(
(_: SectionsVisibility<FilterSectionName>, sections: SectionsVisibility<FilterSectionName>) => {
props.setCurrentFilters({ verb: "set", filter: { id: "", filter: DefaultFilter } });
return sections;
}, config.values.interface.filterSections);
const [sectionsMap, setSectionsMap] = useState(getSectionsMap(sections));

const { setCurrentFilters } = props;

useEffect(() => {
config.values.interface.filterSections = sections;
setSectionsMap(getSectionsMap(sections));
setCurrentFilters({ verb: "set", filter: { id: "", filter: DefaultFilter } });
}, [config, sections, setCurrentFilters]);
}, [config, sections]);

const [info, setInfo, handler] = useContextMenu();

Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const Sashes = ["vertical", "horizontal"] as const;
type SashName = typeof Sashes[number];

const FilterSections = ["Status", "Directories", "Labels", "Trackers"] as const;
type FilterSectionName = typeof FilterSections[number];
export type FilterSectionName = typeof FilterSections[number];

const StatusbarSections = [
"Connection", "Download speed ", "Upload speed", "Free space", "Total", "Selected",
Expand Down

0 comments on commit 8680c28

Please sign in to comment.