Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorful progress bars #82

Closed
wants to merge 2 commits into from

Conversation

melyux
Copy link
Contributor

@melyux melyux commented Sep 20, 2023

First time writing in this lang. Part of #40

CC: @Pentaphon

@Pentaphon
Copy link

This is exciting! Thanks!

Copy link
Member

@qu1ck qu1ck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! There are few things that need to be fixed but looks good for a first pass.

First, configure your IDE to run eslint, it caught a bunch of fixes.
You can also run it manually with npx eslint ./src

The remaining comments are inline.


interface ProgressBarProps {
now: number,
max?: number,
label?: string,
animate?: boolean,
status?: number,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status logic should not be in ProgressBar component because it is generic. It should have an enum variant prop that gives it correct color, determine the variant in parent component that knows what status means, let progressbar handle the color based on variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of confused on this one. Do you mean the ProgressBar component should have an enum for the possible colors, and everything that calls ProgressBar should manually convert e.g. the torrent status into a ProgressBarColor? Which would mean repeating the code between torrenttable.tsx and details.tsx?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to repeat the code, extract it into a helper function, you can put it in torrent.ts.

const label = props.label ?? `${percent}%`;
const className = `progressbar ${props.animate === true ? "animate" : ""} ${props.className ?? ""}`;
const label = props.label || `${percent}%`;
const animate = (props.animate && props.status !== Status.queuedToVerify &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Animate prop should also be taken as is. Determine whether progress bar should be animated in the parent.

props.status == Status.magnetizing || props.status == Status.verifying;
let color = "blue";

const config = useContext(ConfigContext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the config checks outside as well.

Basically this should be a dumb generic reusable component that just draws what it's told.

@@ -136,7 +136,7 @@ function ByteSizeField(props: TableFieldProps) {
function PercentBarField(props: TableFieldProps) {
const now = props.entry.percent ?? 0;

return <ProgressBar now={now} className="white-outline" />;
return <ProgressBar now={now} status={Status.downloading} className="white-outline" />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this blue.
Or, if you want to get colorful here too then make skipped files grey, downloading ones blue and finished ones green to be consistent with torrent table.

@@ -80,7 +81,8 @@ function PercentField(props: TableFieldProps) {
return <ProgressBar
now={now}
className="white-outline"
animate={active} />;
animate={active}
status={Status.downloading} />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, either keep this unchanged or keep consistent logic.

status = Status.error;
} else if (props.torrent.status === Status.downloading && props.torrent.pieceCount === 0) {
now = 100;
label = "🧲";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No emojis and no custom labels here, the icon in name field is enough indication.

if ((props.torrent.error !== undefined && props.torrent.error > 0) || props.torrent.cachedError !== "") {
status = Status.error;
} else if (props.torrent.status === Status.downloading && props.torrent.pieceCount === 0) {
now = 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is leftover from testing or you intend to always show full progress bar. I'm inclined to not show it, even if it makes the color of the progress bar rarely visible because it usually goes from 0 to downloading in a single update.

Copy link
Contributor Author

@melyux melyux Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with the Magnetizing one is that I think you said the Magnetization progress is not grabbed at the full table level, only at the per-torrent level. So the Magnetization process will never be shown, and so the colors will never be shown. I felt it's better to have the bar be full all the time to at least show that this torrent is being Magnetized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, showing full animated bar with no percentage text will be fine.

src/config.ts Show resolved Hide resolved
Comment on lines +36 to +54
.progressbar.dark-blue>:first-child {
background: #0054ae;
}

.progressbar.green>:first-child {
background: #36B24D;
}

.progressbar.dark-green>:first-child {
background: #1d8931;
}

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

.progressbar.dark-red>:first-child {
background: #C92B2A;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The colors are fine but they are not from the default palette and stand out.
This and the default blue should be moved from css file into inline css in jsx and use the MantineTheme colors.
If you are not sure how to do that I can move current styles there and you can build on top of it.

Comment on lines +32 to +33
magnetizing: -1,
error: -2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be changed at all. It is meant to directly map to transmission API.

Once you move the status out of ProgressBar you will likely find that you don't need these fake statuses here.

@Pentaphon
Copy link

Any update on this?

@melyux
Copy link
Contributor Author

melyux commented Oct 23, 2023

Will work on the PR suggestions this week

@Pentaphon
Copy link

@melyux any progress on this?

We recently got an issue that could be solved by your PR where users may benefit from having your color-changing progress bars instead of animated progressbars that take up CPU/GPU on low-spec devices so I think your work has inadvertently solved another issue that certain users have. #170

@qu1ck
Copy link
Member

qu1ck commented Apr 7, 2024

This is now implemented in a similar way in 05303b6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants