diff --git a/frontend/src/components/UI/CardSection.vue b/frontend/src/components/UI/CardSection.vue
index c9e712739..da98e3b6b 100644
--- a/frontend/src/components/UI/CardSection.vue
+++ b/frontend/src/components/UI/CardSection.vue
@@ -7,26 +7,50 @@
{{ title }}
- Random
+
+ mdi-dice-multiple
+
+ {{ $t("general.random") }}
-
+
-
+
+
+ mdi-sort
+
{{ $t("general.sort") }}
+
+ mdi-order-alphabetical-ascending
+
{{ $t("general.sort-alphabetically") }}
+
+ mdi-star
+
{{ $t("general.rating") }}
+
+
+ mdi-new-box
+
+ {{ $t("general.created") }}
+
+
+ mdi-update
+
{{ $t("general.updated") }}
-
- {{ $t("general.created") }}
+
+
+ mdi-shuffle-variant
+
+ {{ $t("general.shuffle") }}
@@ -114,6 +138,7 @@ export default {
},
data() {
return {
+ sortLoading: false,
cardLimit: 30,
loading: false,
EVENTS: {
@@ -121,6 +146,7 @@ export default {
rating: "rating",
created: "created",
updated: "updated",
+ shuffle: "shuffle",
},
};
},
@@ -165,6 +191,7 @@ export default {
this.$router.push(`/recipe/${recipe.slug}`);
},
sortRecipes(sortType) {
+ this.sortLoading = true;
let sortTarget = [...this.recipes];
switch (sortType) {
case this.EVENTS.az:
@@ -179,11 +206,16 @@ export default {
case this.EVENTS.updated:
utils.recipe.sortByUpdated(sortTarget);
break;
+ case this.EVENTS.shuffle:
+ utils.recipe.shuffle(sortTarget);
+ break;
default:
console.log("Unknown Event", sortType);
return;
}
+
this.$emit(SORT_EVENT, sortTarget);
+ this.sortLoading = false;
},
},
};
diff --git a/frontend/src/locales/messages/en-US.json b/frontend/src/locales/messages/en-US.json
index 0122916c1..d64ebf629 100644
--- a/frontend/src/locales/messages/en-US.json
+++ b/frontend/src/locales/messages/en-US.json
@@ -74,11 +74,12 @@
"save": "Save",
"settings": "Settings",
"sort": "Sort",
- "sort-alphabetically": "A-Z",
+ "sort-alphabetically": "Alphabetical",
"status": "Status",
"submit": "Submit",
"success-count": "Success: {count}",
"sunday": "Sunday",
+ "shuffle": "Shuffle",
"templates": "Templates:",
"themes": "Themes",
"thursday": "Thursday",
diff --git a/frontend/src/utils/recipe.js b/frontend/src/utils/recipe.js
index 3b3a120d1..a04cdf5e9 100644
--- a/frontend/src/utils/recipe.js
+++ b/frontend/src/utils/recipe.js
@@ -28,4 +28,22 @@ export const recipe = {
randomRecipe(list) {
return list[Math.floor(Math.random() * list.length)];
},
+ shuffle(list) {
+ let last = list.length;
+ let n;
+ while (last > 0) {
+ n = rand(last);
+ swap(list, n, --last);
+ }
+ },
};
+
+const rand = n =>
+ Math.floor(Math.random() * n)
+
+function swap(t, i, j) {
+ let q = t[i];
+ t[i] = t[j];
+ t[j] = q;
+ return t;
+}