Skip to content

Commit

Permalink
Implement progress bar style options: not animated and colorful
Browse files Browse the repository at this point in the history
Issue #170
  • Loading branch information
qu1ck committed Apr 7, 2024
1 parent 3990b38 commit 05303b6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/components/modals/interfacepanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { Checkbox, Grid, MultiSelect, NativeSelect, NumberInput, Textarea, useMa
import type { UseFormReturnType } from "@mantine/form";
import ColorChooser from "components/colorchooser";
import { useGlobalStyleOverrides } from "themehooks";
import { DeleteTorrentDataOptions, type ColorSetting, type DeleteTorrentDataOption, type StyleOverrides } from "config";
import { DeleteTorrentDataOptions, ProgressbarStyleOptions } from "config";
import type { ProgressbarStyleOption, ColorSetting, DeleteTorrentDataOption, StyleOverrides } from "config";
import { ColorSchemeToggle } from "components/miscbuttons";
import { Label } from "./common";
const { TAURI, invoke } = await import(/* webpackChunkName: "taurishim" */"taurishim");
Expand All @@ -33,6 +34,7 @@ export interface InterfaceFormValues {
styleOverrides: StyleOverrides,
skipAddDialog: boolean,
deleteTorrentData: DeleteTorrentDataOption,
progressbarStyle: ProgressbarStyleOption,
numLastSaveDirs: number,
preconfiguredLabels: string[],
defaultTrackers: string[],
Expand Down Expand Up @@ -120,26 +122,31 @@ export function InterfaceSettigsPanel<V extends InterfaceFormValues>(props: { fo
<Grid.Col span={1}>
<ColorChooser value={style[theme.colorScheme].backgroundColor ?? defaultBg} onChange={setBgColor} />
</Grid.Col>
<Grid.Col span={4}>
<Grid.Col span={3}>
Delete torrent data
</Grid.Col>
<Grid.Col span={4}>
<Grid.Col span={3}>
<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={4}>
<Grid.Col span={6}>
<Checkbox label="Skip add torrent dialog"
{...props.form.getInputProps("interface.skipAddDialog", { type: "checkbox" })} />
</Grid.Col>
<Grid.Col span={6}>Max number of saved download directories</Grid.Col>
<Grid.Col span={4}>Max number of saved download directories</Grid.Col>
<Grid.Col span={2}>
<NumberInput
min={1}
max={100}
{...props.form.getInputProps("interface.numLastSaveDirs")} />
</Grid.Col>
<Grid.Col span={4}></Grid.Col>
<Grid.Col span={3}>Progressbars</Grid.Col>
<Grid.Col span={3}>
<NativeSelect data={ProgressbarStyleOptions as unknown as string[]}
value={props.form.values.interface.progressbarStyle}
onChange={(e) => { setFieldValue("interface.progressbarStyle", e.target.value); }} />
</Grid.Col>
<Grid.Col>
<MultiSelect
data={props.form.values.interface.preconfiguredLabels}
Expand Down
8 changes: 7 additions & 1 deletion src/components/progressbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@
import "../css/progressbar.css";
import React from "react";

export type ProgressBarVariant = "default" | "green" | "dark-green" | "red" | "grey";

interface ProgressBarProps {
now: number,
max?: number,
label?: string,
animate?: boolean,
variant?: ProgressBarVariant,
className?: string,
}

export function ProgressBar(props: ProgressBarProps) {
const max = props.max ?? 100;
const percent = Math.floor(1000 * props.now / max) / 10;
const label = props.label ?? `${percent}%`;
const className = `progressbar ${props.animate === true ? "animate" : ""} ${props.className ?? ""}`;
const className = "progressbar " +
`${props.animate === true ? "animate" : ""} ` +
`${props.variant !== undefined && props.variant !== "default" ? props.variant : ""} ` +
`${props.className ?? ""}`;
return (
<div className={className}>
<div>{label}</div>
Expand Down
9 changes: 8 additions & 1 deletion src/components/tables/filetreetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { isDirEntry } from "../../cachedfiletree";
import { ConfigContext, ServerConfigContext } from "../../config";
import { PriorityColors, PriorityStrings } from "../../rpc/transmission";
import { bytesToHumanReadableStr, fileSystemSafeName, pathMapFromServer } from "../../trutil";
import type { ProgressBarVariant } from "../progressbar";
import { ProgressBar } from "../progressbar";
import * as Icon from "react-bootstrap-icons";
import type { TrguiTableRef } from "./common";
Expand Down Expand Up @@ -141,9 +142,15 @@ function ByteSizeField(props: TableFieldProps) {
}

function PercentBarField(props: TableFieldProps) {
const config = useContext(ConfigContext);
const now = props.entry.percent ?? 0;
let variant: ProgressBarVariant = "default";
if (config.values.interface.progressbarStyle === "colorful") {
if (props.entry.want === false) variant = "grey";
else if (now === 100) variant = "dark-green";
}

return <ProgressBar now={now} className="white-outline" />;
return <ProgressBar now={now} className="white-outline" variant={variant} />;
}

function PriorityField(props: TableFieldProps) {
Expand Down
7 changes: 5 additions & 2 deletions src/components/tables/peerstable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
*/

import type { AccessorFn, CellContext, ColumnDef } from "@tanstack/react-table";
import React, { useMemo, useCallback } from "react";
import React, { useMemo, useCallback, useContext } from "react";
import type { Torrent, PeerStats } from "rpc/torrent";
import { bytesToHumanReadableStr } from "trutil";
import { TrguiTable, useStandardSelect } from "./common";
import { ProgressBar } from "components/progressbar";
import { Flex } from "@mantine/core";
import { ConfigContext } from "config";
const { TAURI } = await import(/* webpackChunkName: "taurishim" */"taurishim");
if (TAURI) await import(/* webpackChunkName: "flag-icons" */"flagsshim");

Expand Down Expand Up @@ -74,13 +75,15 @@ function ByteRateField(props: TableFieldProps) {
}

function PercentField(props: TableFieldProps) {
const config = useContext(ConfigContext);
const now = props.entry[props.fieldName] * 100;
const active = props.entry.rateToClient > 0 || props.entry.rateToPeer > 0;

return <ProgressBar
now={now}
className="white-outline"
animate={active} />;
animate={config.values.interface.progressbarStyle === "animated" && active}
variant={config.values.interface.progressbarStyle === "colorful" && active ? "green" : "default"} />;
}

const Columns = AllFields.map((field): ColumnDef<PeerStats> => {
Expand Down
16 changes: 15 additions & 1 deletion src/components/tables/torrenttable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { TorrentAllFieldsType, TorrentFieldsType } from "rpc/transmission";
import { PriorityColors, PriorityStrings, Status, StatusStrings, TorrentMinimumFields } from "rpc/transmission";
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
import { bytesToHumanReadableStr, fileSystemSafeName, modKeyString, pathMapFromServer, secondsToHumanReadableStr, timestampToDateString } from "trutil";
import type { ProgressBarVariant } from "../progressbar";
import { ProgressBar } from "../progressbar";
import type { AccessorFn, CellContext } from "@tanstack/table-core";
import type { TableSelectReducer } from "./common";
Expand Down Expand Up @@ -324,13 +325,26 @@ function ByteRateField(props: TableFieldProps) {
}

function PercentBarField(props: TableFieldProps) {
const config = useContext(ConfigContext);
const now = props.torrent[props.fieldName] * 100;
const active = props.torrent.rateDownload > 0 || props.torrent.rateUpload > 0;
let variant: ProgressBarVariant = "default";
if (config.values.interface.progressbarStyle === "colorful") {
if ((props.torrent.error !== undefined && props.torrent.error > 0) ||
props.torrent.cachedError !== "") variant = "red";
else {
if (active) variant = "green";
else if (props.torrent.status === Status.stopped &&
props.torrent.sizeWhenDone > 0 &&
props.torrent.leftUntilDone === 0) variant = "dark-green";
}
}

return <ProgressBar
now={now}
className="white-outline"
animate={active} />;
animate={config.values.interface.progressbarStyle === "animated" && active}
variant={variant} />;
}

const Columns = AllFields.map((f): ColumnDef<Torrent> => {
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ 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 const ProgressbarStyleOptions = ["plain", "animated", "colorful"] as const;
export type WindowMinimizeOption = typeof WindowMinimizeOptions[number];
export type WindowCloseOption = typeof WindowCloseOptions[number];
export type DeleteTorrentDataOption = typeof DeleteTorrentDataOptions[number];
export type ProgressbarStyleOption = typeof ProgressbarStyleOptions[number];

export interface ColorSetting {
color: DefaultMantineColor,
Expand Down Expand Up @@ -158,6 +160,7 @@ interface Settings {
preconfiguredLabels: string[],
defaultTrackers: string[],
styleOverrides: StyleOverrides,
progressbarStyle: ProgressbarStyleOption,
},
}

Expand Down Expand Up @@ -276,6 +279,7 @@ const DefaultSettings: Settings = {
dark: {},
light: {},
},
progressbarStyle: "animated",
},
};

Expand Down
16 changes: 16 additions & 0 deletions src/css/progressbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
color: white;
}

.progressbar.red>:first-child {
background: #fa5252;
}

.progressbar.green>:first-child {
background: #37b24d;
}

.progressbar.dark-green>:first-child {
background: #0f6d20;
}

.progressbar.grey>:first-child {
background: #677274;
}

.progressbar>:last-child {
position: absolute;
display: flex;
Expand Down

0 comments on commit 05303b6

Please sign in to comment.