mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +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);
|
||||
|
||||
useEffect(() => {
|
||||
if (opened && ctx.data.length === 1) {
|
||||
setRating(ctx.data[0].userRating ?? 0);
|
||||
if (opened && ctx.data.length > 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 {
|
||||
setRating(0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue