mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 07:39:41 +02:00
feat: User-specific Recipe Ratings (#3345)
Some checks failed
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Docker Nightly Production / Backend Server Tests (push) Has been cancelled
Docker Nightly Production / Frontend and End-to-End Tests (push) Has been cancelled
Docker Nightly Production / Build Tagged Release (push) Has been cancelled
Docker Nightly Production / Notify Discord (push) Has been cancelled
Some checks failed
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Docker Nightly Production / Backend Server Tests (push) Has been cancelled
Docker Nightly Production / Frontend and End-to-End Tests (push) Has been cancelled
Docker Nightly Production / Build Tagged Release (push) Has been cancelled
Docker Nightly Production / Notify Discord (push) Has been cancelled
This commit is contained in:
parent
8ab09cf03b
commit
2a541f081a
50 changed files with 1497 additions and 443 deletions
40
frontend/composables/use-users/user-ratings.ts
Normal file
40
frontend/composables/use-users/user-ratings.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { ref, useContext } from "@nuxtjs/composition-api";
|
||||
import { useUserApi } from "~/composables/api";
|
||||
import { UserRatingSummary } from "~/lib/api/types/user";
|
||||
|
||||
const userRatings = ref<UserRatingSummary[]>([]);
|
||||
const loading = ref(false);
|
||||
const ready = ref(false);
|
||||
|
||||
export const useUserSelfRatings = function () {
|
||||
const { $auth } = useContext();
|
||||
const api = useUserApi();
|
||||
|
||||
async function refreshUserRatings() {
|
||||
if (loading.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
const { data } = await api.users.getSelfRatings();
|
||||
userRatings.value = data?.ratings || [];
|
||||
loading.value = false;
|
||||
ready.value = true;
|
||||
}
|
||||
|
||||
async function setRating(slug: string, rating: number | null, isFavorite: boolean | null) {
|
||||
loading.value = true;
|
||||
const userId = $auth.user?.id || "";
|
||||
await api.users.setRating(userId, slug, rating, isFavorite);
|
||||
loading.value = false;
|
||||
await refreshUserRatings();
|
||||
}
|
||||
|
||||
refreshUserRatings();
|
||||
return {
|
||||
userRatings,
|
||||
refreshUserRatings,
|
||||
setRating,
|
||||
ready,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue