This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix ratings when get a slow connexion (#455)
- Loading branch information
Showing
3 changed files
with
20 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import isEmpty from 'lodash/isEmpty' | ||
|
||
export const getRatingsAverage = (store) => { | ||
const ratings = store.data.ratings.getAsArray().filter(r => r.feeling !== 'noopinion') | ||
if (isEmpty(ratings)) return null | ||
return ratings.map(r => r.rating).reduce((p, c) => p + c, 0) / ratings.length | ||
export const getRatingsAverage = (ratings) => { | ||
const usersRatings = ratings.filter(r => r.feeling !== 'noopinion') | ||
if (isEmpty(usersRatings)) return null | ||
return usersRatings.map(r => r.rating).reduce((p, c) => p + c, 0) / usersRatings.length | ||
} | ||
|
||
export const getFeelingsCount = feeling => (store) => { | ||
const ratings = store.data.ratings.getAsArray() | ||
export const getFeelingsCount = feeling => (ratings) => { | ||
if (isEmpty(ratings)) return null | ||
return ratings.filter(r => r.feeling === feeling).length | ||
} |