Use RatingSystem control in RatingFilter (#3133)

* Use RatingSystem control in RatingFilter
* Improve styling for rating on performer page
This commit is contained in:
WithoutPants
2022-11-17 10:10:40 +11:00
committed by GitHub
parent 3660bf2d1a
commit f0bf780c2e
9 changed files with 92 additions and 121 deletions

View File

@@ -17,6 +17,7 @@ export interface IRatingStarsProps {
onSetRating?: (value?: number) => void;
disabled?: boolean;
precision: RatingStarPrecision;
valueRequired?: boolean;
}
export const RatingStars: React.FC<IRatingStarsProps> = (
@@ -62,7 +63,15 @@ export const RatingStars: React.FC<IRatingStarsProps> = (
) {
const f = newToggleFraction();
if (!f) {
newRating = undefined;
if (props.valueRequired) {
if (fraction) {
newRating = stars + 1;
} else {
newRating = stars;
}
} else {
newRating = undefined;
}
} else if (fraction) {
// we're toggling from an existing fraction so use the stars value
newRating = stars + f;
@@ -143,10 +152,17 @@ export const RatingStars: React.FC<IRatingStarsProps> = (
if (hoverRating) {
if (hoverRating === stars && precision === 1) {
if (props.valueRequired) {
return { rating: r, fraction: 0 };
}
// unsetting
return undefined;
}
if (hoverRating === stars + 1 && fraction && fraction === precision) {
if (props.valueRequired) {
return { rating: r, fraction: 0 };
}
// unsetting
return undefined;
}

View File

@@ -13,6 +13,7 @@ export interface IRatingSystemProps {
value?: number;
onSetRating?: (value?: number) => void;
disabled?: boolean;
valueRequired?: boolean;
}
export const RatingSystem: React.FC<IRatingSystemProps> = (
@@ -32,6 +33,7 @@ export const RatingSystem: React.FC<IRatingSystemProps> = (
precision={
ratingSystemOptions.starPrecision ?? defaultRatingStarPrecision
}
valueRequired={props.valueRequired}
/>
);
}