1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-02 20:15:24 +02:00

refactor(frontend): ♻️ split user profile/management (#670)

* refactor(frontend): ♻️ major rewrite/improvement of use-profile pages

* refactor(frontend): ♻️ split webhooks into their own page

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden 2021-09-04 20:24:32 -08:00 committed by GitHub
parent 3d87ffc3a5
commit e179dcdb10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 723 additions and 796 deletions

View file

@ -7,6 +7,56 @@ import { Recipe } from "~/types/api-types/recipe";
export const allRecipes = ref<Recipe[] | null>([]);
export const recentRecipes = ref<Recipe[] | null>([]);
const rand = (n: number) => Math.floor(Math.random() * n);
function swap(t: Array<any>, i: number, j: number) {
const q = t[i];
t[i] = t[j];
t[j] = q;
return t;
}
export const useSorter = () => {
function sortAToZ(list: Array<Recipe>) {
list.sort((a, b) => {
const textA = a.name.toUpperCase();
const textB = b.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
}
function sortByCreated(list: Array<Recipe>) {
list.sort((a, b) => (a.dateAdded > b.dateAdded ? -1 : 1));
}
function sortByUpdated(list: Array<Recipe>) {
list.sort((a, b) => (a.dateUpdated > b.dateUpdated ? -1 : 1));
}
function sortByRating(list: Array<Recipe>) {
list.sort((a, b) => (a.rating > b.rating ? -1 : 1));
}
function randomRecipe(list: Array<Recipe>): Recipe {
return list[Math.floor(Math.random() * list.length)];
}
function shuffle(list: Array<Recipe>) {
let last = list.length;
let n;
while (last > 0) {
n = rand(last);
swap(list, n, --last);
}
}
return {
sortAToZ,
sortByCreated,
sortByUpdated,
sortByRating,
randomRecipe,
shuffle,
};
};
export const useRecipes = (all = false, fetchRecipes = true) => {
const api = useApiSingleton();