Pause, cancel & resume backup media download

This commit is contained in:
trevor-signal 2024-09-16 15:38:12 -04:00 committed by GitHub
parent 65539b1419
commit 028a3f3ef0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 958 additions and 141 deletions

View file

@ -0,0 +1,53 @@
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
import { ProgressBar } from './ProgressBar';
import type { ComponentMeta } from '../storybook/types';
type Props = React.ComponentProps<typeof ProgressBar>;
export default {
title: 'Components/ProgressBar',
component: ProgressBar,
args: {
fractionComplete: 0,
isRTL: false,
},
} satisfies ComponentMeta<Props>;
export function Zero(args: Props): JSX.Element {
return <ProgressBar {...args} />;
}
export function Thirty(args: Props): JSX.Element {
return <ProgressBar {...args} fractionComplete={0.3} />;
}
export function Done(args: Props): JSX.Element {
return <ProgressBar {...args} fractionComplete={1} />;
}
export function Increasing(args: Props): JSX.Element {
const fractionComplete = useIncreasingFractionComplete();
return <ProgressBar {...args} fractionComplete={fractionComplete} />;
}
export function RTLIncreasing(args: Props): JSX.Element {
const fractionComplete = useIncreasingFractionComplete();
return <ProgressBar {...args} fractionComplete={fractionComplete} isRTL />;
}
function useIncreasingFractionComplete() {
const [fractionComplete, setFractionComplete] = React.useState(0);
React.useEffect(() => {
if (fractionComplete >= 1) {
return;
}
const timeout = setTimeout(() => {
setFractionComplete(cur => Math.min(1, cur + 0.1));
}, 300);
return () => clearTimeout(timeout);
}, [fractionComplete]);
return fractionComplete;
}