From 4fbffda45d262c2ff4f71d0802c3201d023c5231 Mon Sep 17 00:00:00 2001
From: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Date: Fri, 12 Apr 2024 18:59:01 +0000
Subject: [PATCH 1/3] simplify user vs group rating toggle
---
.../components/Domain/Recipe/RecipeRating.vue | 75 +++++++------------
1 file changed, 29 insertions(+), 46 deletions(-)
diff --git a/frontend/components/Domain/Recipe/RecipeRating.vue b/frontend/components/Domain/Recipe/RecipeRating.vue
index 45abdb9534f..344ffed73ff 100644
--- a/frontend/components/Domain/Recipe/RecipeRating.vue
+++ b/frontend/components/Domain/Recipe/RecipeRating.vue
@@ -1,12 +1,12 @@
+
+
+
@@ -45,61 +58,30 @@ export default defineComponent({
type: Boolean,
default: false,
},
- preferGroupRating: {
- type: Boolean,
- default: false,
- },
},
setup(props, context) {
const { $auth } = useContext();
const { isOwnGroup } = useLoggedInState();
const { userRatings, setRating, ready: ratingsLoaded } = useUserSelfRatings();
- const hideGroupRating = ref(false);
-
- type Rating = {
- ratingValue: number | undefined;
- hasUserRating: boolean | undefined
- };
- // prefer user rating over group rating
- const rating = computed(() => {
- if (!ratingsLoaded.value) {
- return { ratingValue: undefined, hasUserRating: undefined };
- }
- if (!($auth.user?.id) || props.preferGroupRating) {
- return { ratingValue: props.value, hasUserRating: false };
- }
-
- const userRating = userRatings.value.find((r) => r.recipeId === props.recipeId);
- return {
- ratingValue: userRating?.rating || (hideGroupRating.value ? 0 : props.value),
- hasUserRating: !!userRating?.rating
- };
+ const userRating = computed(() => {
+ return userRatings.value.find((r) => r.recipeId === props.recipeId)?.rating;
});
// if a user unsets their rating, we don't want to fall back to the group rating since it's out of sync
+ const hideGroupRating = ref(!!userRating.value);
watch(
- () => rating.value.hasUserRating,
+ () => userRating.value,
() => {
- if (rating.value.hasUserRating && !props.preferGroupRating) {
+ if (userRating.value) {
hideGroupRating.value = true;
}
},
)
- const attrs = computed(() => {
- return isOwnGroup.value ? {
- // Logged-in user
- color: rating.value.hasUserRating ? "secondary" : "grey darken-1",
- hoverColor: "secondary",
- backgroundColor: "secondary lighten-3",
- } : {
- // Anonymous user
- color: "secondary",
- hoverColor: "secondary",
- backgroundColor: "secondary lighten-3",
- };
- })
+ const groupRating = computed(() => {
+ return hideGroupRating.value ? 0 : props.value;
+ });
function updateRating(val: number | null) {
if (!isOwnGroup.value) {
@@ -113,9 +95,10 @@ export default defineComponent({
}
return {
- attrs,
isOwnGroup,
- rating,
+ ratingsLoaded,
+ groupRating,
+ userRating,
updateRating,
};
},
From 65cc92de56e31287bde20d87694d06d8745ce00c Mon Sep 17 00:00:00 2001
From: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Date: Fri, 12 Apr 2024 19:12:58 +0000
Subject: [PATCH 2/3] fixed sort by rating edgecases
---
mealie/repos/repository_recipes.py | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/mealie/repos/repository_recipes.py b/mealie/repos/repository_recipes.py
index 8569adcdb97..770f15c48ec 100644
--- a/mealie/repos/repository_recipes.py
+++ b/mealie/repos/repository_recipes.py
@@ -18,9 +18,19 @@
from mealie.db.models.users.user_to_recipe import UserToRecipe
from mealie.schema.cookbook.cookbook import ReadCookBook
from mealie.schema.recipe import Recipe
-from mealie.schema.recipe.recipe import RecipeCategory, RecipePagination, RecipeSummary, RecipeTag, RecipeTool
+from mealie.schema.recipe.recipe import (
+ RecipeCategory,
+ RecipePagination,
+ RecipeSummary,
+ RecipeTag,
+ RecipeTool,
+)
from mealie.schema.recipe.recipe_category import CategoryBase, TagBase
-from mealie.schema.response.pagination import OrderByNullPosition, OrderDirection, PaginationQuery
+from mealie.schema.response.pagination import (
+ OrderByNullPosition,
+ OrderDirection,
+ PaginationQuery,
+)
from ..db.models._model_base import SqlAlchemyBase
from ..schema._mealie.mealie_model import extract_uuids
@@ -173,11 +183,11 @@ def add_order_attr_to_query(
UserToRecipe.rating is not None,
UserToRecipe.rating > 0,
),
- sa.select(UserToRecipe.rating)
+ sa.select(sa.func.max(UserToRecipe.rating))
.where(UserToRecipe.recipe_id == self.model.id, UserToRecipe.user_id == self.user_id)
.scalar_subquery(),
),
- else_=self.model.rating,
+ else_=sa.case((self.model.rating == 0, None), else_=self.model.rating),
).label(effective_rating_column_name)
)
@@ -189,7 +199,7 @@ def add_order_attr_to_query(
if order_by_null is OrderByNullPosition.first:
order_attr = sa.nulls_first(order_attr)
- elif order_by_null is OrderByNullPosition.last:
+ else:
order_attr = sa.nulls_last(order_attr)
return query.order_by(order_attr)
From b5ddd1b896814688f6a5e79fa1bea898a84d4531 Mon Sep 17 00:00:00 2001
From: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Date: Fri, 19 Apr 2024 14:23:02 +0000
Subject: [PATCH 3/3] removed unused assignment
---
frontend/components/Domain/Recipe/RecipeRating.vue | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/frontend/components/Domain/Recipe/RecipeRating.vue b/frontend/components/Domain/Recipe/RecipeRating.vue
index 344ffed73ff..e8cd6c04169 100644
--- a/frontend/components/Domain/Recipe/RecipeRating.vue
+++ b/frontend/components/Domain/Recipe/RecipeRating.vue
@@ -33,7 +33,7 @@