Skip to content

Commit

Permalink
Add options to reset "delete data" flag or remember user choice
Browse files Browse the repository at this point in the history
Defaults to "default off" which will always reset the delete flag

Issue #155
  • Loading branch information
qu1ck committed Feb 4, 2024
1 parent 40611b5 commit a491644
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/components/modals/interfacepanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import { Checkbox, Grid, NativeSelect, NumberInput, Textarea, useMantineTheme }
import type { UseFormReturnType } from "@mantine/form";
import ColorChooser from "components/colorchooser";
import { useGlobalStyleOverrides } from "themehooks";
import type { ColorSetting, StyleOverrides } from "config";
import { DeleteTorrentDataOptions, type ColorSetting, type DeleteTorrentDataOption, type StyleOverrides } from "config";
import { ColorSchemeToggle } from "components/miscbuttons";
const { TAURI, invoke } = await import(/* webpackChunkName: "taurishim" */"taurishim");

export interface InterfaceFormValues {
interface: {
styleOverrides: StyleOverrides,
skipAddDialog: boolean,
deleteTorrentData: DeleteTorrentDataOption,
numLastSaveDirs: number,
defaultTrackers: string[],
},
Expand Down Expand Up @@ -111,6 +112,14 @@ export function InterfaceSettigsPanel<V extends InterfaceFormValues>(props: { fo
<Checkbox label="Skip add torrent dialog"
{...props.form.getInputProps("interface.skipAddDialog", { type: "checkbox" })} />
</Grid.Col>
<Grid.Col span={8}>
Delete torrent data
</Grid.Col>
<Grid.Col span={4}>
<NativeSelect data={DeleteTorrentDataOptions as unknown as string[]}
value={props.form.values.interface.deleteTorrentData}
onChange={(e) => { setFieldValue("interface.deleteTorrentData", e.target.value); }} />
</Grid.Col>
<Grid.Col span={8}>Max number of saved download directories</Grid.Col>
<Grid.Col span={2}>
<NumberInput
Expand Down
22 changes: 20 additions & 2 deletions src/components/modals/remove.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@
import { Button, Checkbox, Divider, Group, Text } from "@mantine/core";
import type { ModalState } from "./common";
import { HkModal, TorrentsNames } from "./common";
import React, { useCallback, useState } from "react";
import React, { useCallback, useContext, useEffect, useState } from "react";
import { useRemoveTorrents } from "queries";
import { notifications } from "@mantine/notifications";
import { useServerSelectedTorrents } from "rpc/torrent";
import { ConfigContext } from "config";

export function RemoveModal(props: ModalState) {
const config = useContext(ConfigContext);
const serverSelected = useServerSelectedTorrents();
const [deleteData, setDeleteData] = useState<boolean>(false);

useEffect(() => {
if (props.opened) {
if (config.values.interface.deleteTorrentData !== "remember selection") {
setDeleteData(config.values.interface.deleteTorrentData === "default on");
} else {
setDeleteData(config.values.interface.deleteTorrentDataSelection);
}
}
}, [config, props.opened]);

const onDeleteDataChanged = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.currentTarget.checked;
setDeleteData(value);
config.values.interface.deleteTorrentDataSelection = value;
}, [config]);

const remove = useRemoveTorrents();

const onDelete = useCallback(() => {
Expand Down Expand Up @@ -57,7 +75,7 @@ export function RemoveModal(props: ModalState) {
<Checkbox
label="Delete torrent data"
checked={deleteData}
onChange={(e) => { setDeleteData(e.currentTarget.checked); }}
onChange={onDeleteDataChanged}
my="xl" />
<Divider my="sm" />
<Group position="center" spacing="md">
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ export type SectionsVisibility<S extends string> = Array<{

export const WindowMinimizeOptions = ["minimize", "hide"] as const;
export const WindowCloseOptions = ["hide", "close", "quit"] as const;
export const DeleteTorrentDataOptions = ["default off", "default on", "remember selection"] as const;
export type WindowMinimizeOption = typeof WindowMinimizeOptions[number];
export type WindowCloseOption = typeof WindowCloseOptions[number];
export type DeleteTorrentDataOption = typeof DeleteTorrentDataOptions[number];

export interface ColorSetting {
color: DefaultMantineColor,
Expand Down Expand Up @@ -149,6 +151,8 @@ interface Settings {
showFilesSearchBox: boolean,
mainSplit: SplitType,
skipAddDialog: boolean,
deleteTorrentData: DeleteTorrentDataOption,
deleteTorrentDataSelection: boolean,
numLastSaveDirs: number,
defaultTrackers: string[],
styleOverrides: StyleOverrides,
Expand Down Expand Up @@ -260,6 +264,8 @@ const DefaultSettings: Settings = {
showFilesSearchBox: false,
mainSplit: "vertical",
skipAddDialog: false,
deleteTorrentData: "default off",
deleteTorrentDataSelection: false,
numLastSaveDirs: 20,
defaultTrackers: [...DefaultTrackerList],
styleOverrides: {
Expand Down

0 comments on commit a491644

Please sign in to comment.