mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 18:33:33 +00:00
handle initial rating for multiple items in context menu
This commit is contained in:
parent
dc03a432fe
commit
ab8c3ad0ec
1 changed files with 10 additions and 2 deletions
|
|
@ -123,8 +123,16 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
||||||
const [rating, setRating] = useState<number>(0);
|
const [rating, setRating] = useState<number>(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (opened && ctx.data.length === 1) {
|
if (opened && ctx.data.length > 0) {
|
||||||
setRating(ctx.data[0].userRating ?? 0);
|
if (ctx.data.length === 1) {
|
||||||
|
setRating(ctx.data[0].userRating ?? 0);
|
||||||
|
} else {
|
||||||
|
const firstRating = ctx.data[0].userRating ?? 0;
|
||||||
|
const allSameRating = ctx.data.every(
|
||||||
|
(item) => (item.userRating ?? 0) === firstRating,
|
||||||
|
);
|
||||||
|
setRating(allSameRating ? firstRating : 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setRating(0);
|
setRating(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue