mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
* add rating100 fields to represent rating range 1-100 * deprecate existing (1-5) rating fields * add half- and quarter-star options for rating system * add decimal rating system option Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import React, { useContext } from "react";
|
|
import { FormattedMessage } from "react-intl";
|
|
import {
|
|
convertToRatingFormat,
|
|
defaultRatingSystemOptions,
|
|
RatingStarPrecision,
|
|
RatingSystemType,
|
|
} from "src/utils/rating";
|
|
import { ConfigurationContext } from "src/hooks/Config";
|
|
import { IUIConfig } from "src/core/config";
|
|
|
|
interface IProps {
|
|
rating?: number | null;
|
|
}
|
|
|
|
export const RatingBanner: React.FC<IProps> = ({ rating }) => {
|
|
const { configuration: config } = useContext(ConfigurationContext);
|
|
const ratingSystemOptions =
|
|
(config?.ui as IUIConfig)?.ratingSystemOptions ??
|
|
defaultRatingSystemOptions;
|
|
const isLegacy =
|
|
ratingSystemOptions.type === RatingSystemType.Stars &&
|
|
ratingSystemOptions.starPrecision === RatingStarPrecision.Full;
|
|
|
|
const convertedRating = convertToRatingFormat(
|
|
rating ?? undefined,
|
|
ratingSystemOptions
|
|
);
|
|
|
|
return rating ? (
|
|
<div
|
|
className={
|
|
isLegacy
|
|
? `rating-banner rating-${convertedRating}`
|
|
: `rating-banner rating-100-${Math.trunc(rating / 5)}`
|
|
}
|
|
>
|
|
<FormattedMessage id="rating" />: {convertedRating}
|
|
</div>
|
|
) : (
|
|
<></>
|
|
);
|
|
};
|