* chore(deps): bump react-i18next from 11.16.6 to 12.1.1 Bumps [react-i18next](https://github.com/i18next/react-i18next) from 11.16.6 to 12.1.1. - [Release notes](https://github.com/i18next/react-i18next/releases) - [Changelog](https://github.com/i18next/react-i18next/blob/master/CHANGELOG.md) - [Commits](https://github.com/i18next/react-i18next/compare/v11.16.6...v12.1.1) --- updated-dependencies: - dependency-name: react-i18next dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Update related deps, TS fixes Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom.moor@gmail.com>
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { TFunction } from "i18next";
|
|
import { observer } from "mobx-react";
|
|
import { DoneIcon } from "outline-icons";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import styled, { useTheme } from "styled-components";
|
|
import Document from "~/models/Document";
|
|
import CircularProgressBar from "~/components/CircularProgressBar";
|
|
import usePrevious from "~/hooks/usePrevious";
|
|
import { bounceIn } from "~/styles/animations";
|
|
|
|
type Props = {
|
|
document: Document;
|
|
};
|
|
|
|
function getMessage(t: TFunction, total: number, completed: number): string {
|
|
if (completed === 0) {
|
|
return t(`{{ total }} task`, {
|
|
total,
|
|
count: total,
|
|
});
|
|
} else if (completed === total) {
|
|
return t(`{{ completed }} task done`, {
|
|
completed,
|
|
count: completed,
|
|
});
|
|
} else {
|
|
return t(`{{ completed }} of {{ total }} tasks`, {
|
|
total,
|
|
completed,
|
|
});
|
|
}
|
|
}
|
|
|
|
function DocumentTasks({ document }: Props) {
|
|
const { tasks, tasksPercentage } = document;
|
|
const { t } = useTranslation();
|
|
const theme = useTheme();
|
|
const { completed, total } = tasks;
|
|
const done = completed === total;
|
|
const previousDone = usePrevious(done);
|
|
const message = getMessage(t, total, completed);
|
|
return (
|
|
<>
|
|
{completed === total ? (
|
|
<Done
|
|
color={theme.primary}
|
|
size={20}
|
|
$animated={done && previousDone === false}
|
|
/>
|
|
) : (
|
|
<CircularProgressBar percentage={tasksPercentage} />
|
|
)}
|
|
{message}
|
|
</>
|
|
);
|
|
}
|
|
|
|
const Done = styled(DoneIcon)<{ $animated: boolean }>`
|
|
margin: -1px;
|
|
animation: ${(props) => (props.$animated ? bounceIn : "none")} 600ms;
|
|
transform-origin: center center;
|
|
`;
|
|
|
|
export default observer(DocumentTasks);
|